anythingmcp icon indicating copy to clipboard operation
anythingmcp copied to clipboard

MCP bridge discovery does not enforce its configured 50-page limit

Open Coding-Professional opened this issue 2 weeks ago • 1 comments

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.

  1. From the repository root, run npm run build -w packages/backend with the local Prisma-generation environment configured.
  2. Start a loopback-only MCP fixture that answers initialize with protocol 2025-06-18 and capabilities: { tools: {} }, returns one distinct tool and a fresh nextCursor on every tools/list page, and finishes after 51 pages. No session ID is needed. Return HTTP 202 for notifications and 405 for GET.
  3. In a local test process (NODE_ENV=test to permit the loopback fixture), call the built new McpClientEngine({}).listTools({ baseUrl: fixtureUrl, authType: 'NONE' }) and count tools/list requests. It sends 51 and returns 51 tools.
  4. 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.

Coding-Professional avatar Nov 18 '26 13:11 Coding-Professional

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.

helpcodeai avatar Nov 19 '26 08:11 helpcodeai