From a8ec41533cad60dc772da7df60d23f864ebc1612 Mon Sep 17 00:00:00 2001 From: Hermes Agent <127238744+teknium1@users.noreply.github.com> Date: Thu, 9 Jul 2026 17:25:12 -0700 Subject: [PATCH] fix(mcp): treat non-string nextCursor as end of pagination Per the MCP spec the cursor is an opaque string; anything else (including MagicMock auto-attributes in tests) means no more pages. Fixes test_mcp_tool_session_expired mock-session runaway. --- tools/mcp_tool.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/mcp_tool.py b/tools/mcp_tool.py index 55585bf2e612..2d87c7616820 100644 --- a/tools/mcp_tool.py +++ b/tools/mcp_tool.py @@ -609,7 +609,9 @@ async def _paginate_full_list(list_method, items_attr: str, server_name: str): result = await (list_method(cursor=cursor) if cursor else list_method()) items.extend(getattr(result, items_attr, None) or []) cursor = getattr(result, "nextCursor", None) - if not cursor: + # Per the MCP spec the cursor is an opaque string; anything else + # (including mock objects in tests) means "no more pages". + if not isinstance(cursor, str) or not cursor: break else: logger.warning(