MCP bridge discovery does not enforce its configured 50-page limit
Observed behavior
The bridge's MAX_TOOL_LIST_PAGES = 50 does not bound discovery with the locked @modelcontextprotocol/client 2.4.0. The first client.listTools(undefined) already walks all pages inside the SDK and removes nextCursor, so the engine's outer loop runs only once.
I reproduced this using the real SDK and a local stateless HTTP fixture, one distinct tool per page:
{"totalPages":51,"listRequests":51,"tools":51}
{"totalPages":65,"listRequests":64,"error":"tools/list: exceeded listMaxPages (64); server pagination did not terminate"}
Thus a terminating 51-page catalog exceeds the engine's stated ceiling, and a terminating 65-page catalog fails discovery rather than returning the first 50 pages as the engine's loop suggests. The SDK has its own default 64-page cap; this is not an unbounded request loop.
Where
McpClientEngine.listTools calls client.listTools(cursor ? { cursor } : undefined) inside its 50-iteration loop.
The installed SDK's listTools takes the per-page path only when params.cursor !== undefined; otherwise _listAllPages handles pagination. Its listMaxPages option defaults to 64.
Reproduction
Environment: Windows, Node 24.17.0, AnythingMCP v0.55.5 (main 25376a85), client SDK 2.4.0. I used the local build with the pending session-cleanup fix from #1766; the discovery loop and client construction are unchanged from main.
- From the repository root, run
npm run build -w packages/backendwith the local Prisma-generation environment configured. - Start a loopback-only MCP fixture that answers initialize with protocol
2025-06-18andcapabilities: { tools: {} }, returns one distinct tool and a freshnextCursoron everytools/listpage, and finishes after 51 pages. No session ID is needed. Return HTTP 202 for notifications and 405 for GET. - In a local test process (
NODE_ENV=testto permit the loopback fixture), call the builtnew McpClientEngine({}).listTools({ baseUrl: fixtureUrl, authType: 'NONE' })and counttools/listrequests. It sends 51 and returns 51 tools. - Repeat with 65 pages. It sends 64 requests and throws the SDK pagination error shown above. No external services, real credentials or database were used for either call.
Expected / proposed scope
Choose and enforce one page-budget policy at the SDK/request level: either a bounded aggregate call with an explicit listMaxPages, or explicit single-page requests if returning a capped partial catalog remains intended. Remove the ineffective outer loop when using aggregation.
A regression should exercise the real SDK across the cap; mocking client.listTools to return individual pages misses this behavior. Both Cloud and self-hosted use this backend discovery path.
I have not started an implementation; the choice between rejecting an oversized catalog and returning partial discovery should be explicit first.
Thanks for the clear report and the reproduction with the real SDK. You are right: since client 2.4 our loop runs once and the SDK default of 64 applies. #1800 passes our limit to the SDK as listMaxPages and explains the cap error in plain words. A server with more than 50 pages now gets that clear error instead of a partial list.