{"record":{"id":"8d26109d422f8a77","repo":"PrefectHQ/fastmcp","slug":"self-name-reached-auto-pagination-limit-max-8d2610","errorCode":null,"errorMessage":"[{self.name}] Reached auto-pagination limit ({max_pages} pages) for list_resources. Use list_resources_mcp() with cursor for manual pagination, or increase max_pages.","messagePattern":"\\[(.+?)\\] Reached auto-pagination limit \\((.+?) pages\\) for list_resources\\. Use list_resources_mcp\\(\\) with cursor for manual pagination, or increase max_pages\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/mixins/resources.py","lineNumber":110,"sourceCode":"        all_resources: list[mcp_types.Resource] = []\n        cursor: str | None = None\n        seen_cursors: set[str] = set()\n\n        for _ in range(max_pages):\n            result = await self.list_resources_mcp(cursor=cursor)\n            all_resources.extend(result.resources)\n            if not result.next_cursor:\n                break\n            if result.next_cursor in seen_cursors:\n                logger.warning(\n                    f\"[{self.name}] Server returned duplicate pagination cursor\"\n                    f\" {result.next_cursor!r} for list_resources; stopping pagination\"\n                )\n                break\n            seen_cursors.add(result.next_cursor)\n            cursor = result.next_cursor\n        else:\n            raise RuntimeError(\n                f\"[{self.name}] Reached auto-pagination limit\"\n                f\" ({max_pages} pages) for list_resources.\"\n                \" Use list_resources_mcp() with cursor for manual pagination,\"\n                \" or increase max_pages.\"\n            )\n\n        return all_resources\n\n    async def list_resource_templates_mcp(\n        self: Client,\n        *,\n        cursor: str | None = None,\n        cache_mode: CacheMode = \"use\",\n    ) -> mcp_types.ListResourceTemplatesResult:\n        \"\"\"Send a resources/listResourceTemplates request and return the complete MCP protocol result.\n\n        Args:\n            cursor: Optional pagination cursor from a previous request's nextCursor.","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/mixins/resources.py#L92-L128","documentation":"FastMCP's client `list_resources()` auto-paginates through the server's resource list, following `nextCursor` for up to `max_pages` iterations (default 250). If the cursor chain does not terminate within that budget, the for-else branch raises `RuntimeError`. This guards against infinite loops caused by very large catalogs or servers that never clear `nextCursor`.","triggerScenarios":"Calling `client.list_resources()` against a server exposing more than 250 pages of resources, or a server whose `nextCursor` never becomes None (repeated/regenerated cursors).","commonSituations":"Pointing a client at a gateway that aggregates thousands of resources with small page sizes; a third-party MCP server with a broken pagination implementation; running against a mock/test server that always returns a cursor.","solutions":["Switch to `client.list_resources_mcp(cursor=...)` and page manually until `result.next_cursor is None`.","Pass a larger `max_pages` to `client.list_resources(max_pages=...)`.","Inspect `list_resources_mcp()` output to check whether the server repeats the same cursor (server bug) — stop on repeated cursors in your own loop.","Reduce the resource count or page size on the server side."],"exampleFix":"// before\nresources = await client.list_resources()  # RuntimeError after 250 pages\n// after\nresult = await client.list_resources_mcp()\nresources = result.resources\nwhile result.next_cursor is not None:\n    result = await client.list_resources_mcp(cursor=result.next_cursor)\n    resources.extend(result.resources)","handlingStrategy":"try-catch","validationCode":"# Probe pagination health before the auto-paginating call\nfirst = await client.list_resources_mcp()\nif first.next_cursor is not None and len(first.resources) < 10:\n    print(\"Server pages are small; prefer manual pagination or larger max_pages\")","typeGuard":null,"tryCatchPattern":"try:\n    resources = await client.list_resources()\nexcept RuntimeError as e:\n    if \"auto-pagination limit\" not in str(e):\n        raise\n    page = await client.list_resources_mcp()\n    resources = page.resources\n    cursor = page.next_cursor\n    while cursor is not None:\n        page = await client.list_resources_mcp(cursor=cursor)\n        resources.extend(page.resources)\n        cursor = page.next_cursor","preventionTips":["Use list_resources_mcp() with an explicit loop for very large resource catalogs","Pass an explicit max_pages matched to the expected number of pages","Detect repeating cursors in your own loop and bail out early","Verify server pagination terminates correctly before relying on auto-pagination"],"tags":["pagination","client","mcp","runtime-error"],"backgroundTag":"pagination-limit-exceeded","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}