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.
This commit is contained in:
Hermes Agent 2026-07-09 17:25:12 -07:00 committed by Teknium
parent 6030ca8cea
commit a8ec41533c

View file

@ -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(