{"record":{"id":"ccda17d0912c9df9","repo":"PrefectHQ/fastmcp","slug":"self-name-reached-auto-pagination-limit-max-ccda17","errorCode":null,"errorMessage":"[{self.name}] Reached auto-pagination limit ({max_pages} pages) for list_resource_templates. Use list_resource_templates_mcp() with cursor for manual pagination, or increase max_pages.","messagePattern":"\\[(.+?)\\] Reached auto-pagination limit \\((.+?) pages\\) for list_resource_templates\\. Use list_resource_templates_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":206,"sourceCode":"        cursor: str | None = None\n        seen_cursors: set[str] = set()\n\n        for _ in range(max_pages):\n            result = await self.list_resource_templates_mcp(cursor=cursor)\n            all_templates.extend(result.resource_templates)\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_resource_templates;\"\n                    \" 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_resource_templates.\"\n                \" Use list_resource_templates_mcp() with cursor for manual pagination,\"\n                \" or increase max_pages.\"\n            )\n\n        return all_templates\n\n    async def read_resource_mcp(\n        self: Client, uri: AnyUrl | str, meta: dict[str, Any] | None = None\n    ) -> mcp_types.ReadResourceResult:\n        \"\"\"Send a resources/read request and return the complete MCP protocol result.\n\n        Args:\n            uri (AnyUrl | str): The URI of the resource to read. Can be a string or an AnyUrl object.\n            meta (dict[str, Any] | None, optional): Request metadata (e.g., for SEP-1686 tasks). Defaults to None.\n\n        Returns:","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/mixins/resources.py#L188-L224","documentation":"FastMCP's client `list_resource_templates()` auto-paginates through URI templates, following `nextCursor` for up to `max_pages` iterations (default 250). If pagination does not terminate in time, the for-else branch raises `RuntimeError`. Same safety guard as the other list methods, applied to resource templates.","triggerScenarios":"Calling `client.list_resource_templates()` against a server with more than 250 pages of templates, or one whose `nextCursor` never resolves to None.","commonSituations":"A server generating templates dynamically per-entity (thousands of templates); gateway/proxy setups with tiny page sizes; buggy servers that keep emitting cursors.","solutions":["Use `client.list_resource_templates_mcp(cursor=...)` and loop manually until `result.next_cursor is None`.","Increase the budget: `client.list_resource_templates(max_pages=...)`.","Check the server's cursor behavior — a repeated cursor means a server-side pagination bug to fix or work around.","Consolidate templates server-side so fewer pages are needed."],"exampleFix":"// before\ntemplates = await client.list_resource_templates()  # RuntimeError after 250 pages\n// after\nresult = await client.list_resource_templates_mcp()\ntemplates = result.resource_templates\nwhile result.next_cursor is not None:\n    result = await client.list_resource_templates_mcp(cursor=result.next_cursor)\n    templates.extend(result.resource_templates)","handlingStrategy":"try-catch","validationCode":"# Probe pagination health before the auto-paginating call\nfirst = await client.list_resource_templates_mcp()\nif first.next_cursor is not None and len(first.resource_templates) < 10:\n    print(\"Server pages are small; prefer manual pagination or larger max_pages\")","typeGuard":null,"tryCatchPattern":"try:\n    templates = await client.list_resource_templates()\nexcept RuntimeError as e:\n    if \"auto-pagination limit\" not in str(e):\n        raise\n    page = await client.list_resource_templates_mcp()\n    templates = page.resource_templates\n    cursor = page.next_cursor\n    while cursor is not None:\n        page = await client.list_resource_templates_mcp(cursor=cursor)\n        templates.extend(page.resource_templates)\n        cursor = page.next_cursor","preventionTips":["Use list_resource_templates_mcp() with an explicit loop for template-heavy servers","Pass an explicit max_pages sized to the expected page count","Log cursors during development to spot non-terminating chains","Consolidate templates server-side so pagination stays shallow"],"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"}