Skip to content

fix: follow tools/list pagination so all MCP tools are callable - #566

Open
Divya (divya0795) wants to merge 1 commit into
langchain-ai:mainfrom
divya0795:fix/openwiki-002-mcp-tools-list-pagination
Open

fix: follow tools/list pagination so all MCP tools are callable#566
Divya (divya0795) wants to merge 1 commit into
langchain-ai:mainfrom
divya0795:fix/openwiki-002-mcp-tools-list-pagination

Conversation

@divya0795

Copy link
Copy Markdown
Contributor

Summary

Fixes #565.

The MCP spec paginates tools/list with a top-level nextCursor: a client must re-issue the request with that cursor until the field is absent. Both JSON-RPC clients in src/connectors/mcp-client.ts issued a single request with empty params and read only the first page, so every tool past page 1 was silently dropped from discovery.

That is not only a discovery gap. callMcpConnectorTool hard-rejects any tool name missing from the discovered set (src/connectors/mcp-runtime.ts:88-92), so on a paginating server valid read-only tools became permanently uncallable with MCP tool <name> was not returned by tools/list — and the error points the user at openwiki_list_mcp_tools, which was itself truncated to page 1, so the advice could never resolve it.

Changes

  • Added collectPaginatedTools, a shared helper that follows nextCursor until it is absent and concatenates the pages. It reuses the existing extractToolValues, so a malformed page still contributes nothing rather than throwing.
  • Pointed both StdioJsonRpcClient.listTools and HttpJsonRpcClient.listTools at the helper — both transports were affected, and both expose an identical private request(method, params), so neither needed its own loop.
  • Bounded the loop twice over so a misbehaving server cannot hang discovery: it stops when a cursor repeats, and at a 100-page cap.
  • Added a patch changeset.

Behavior and safety

The first request is unchanged (tools/list with {}), and a server that returns no nextCursor still results in exactly one round-trip — no extra traffic for the non-paginating case. listTools still resolves to { tools }, so extractTools and both call sites are untouched. Tool validation and the read-only policy checks in mcp-runtime.ts are unchanged; this only widens what discovery sees to what the server actually offers.

How I tested it

Added four cases to test/mcp-client.test.ts, driving the real HTTP client end-to-end through the exported listMcpTools against a stubbed MCP server:

  • a two-page server ⇒ both tools discovered, and the second request carries { cursor: "cursor-2" };
  • a single-page server ⇒ exactly one tools/list request (regression guard against extra traffic);
  • a server that repeats the same cursor ⇒ terminates instead of looping;
  • a server that always returns a fresh cursor ⇒ terminates at the page cap.

Confirmed these are real regression tests: with the source change reverted, three of the four fail; all four pass with it.

Validation:

  • pnpm run format
  • pnpm run lint
  • pnpm run typecheck
  • pnpm test — 872/873 pass. The one failure is test/openwiki-ignore.test.ts > restricts shell execute while ignore rules are active, which fails identically on an unmodified main on this machine (it shells out to pwd, so it is Windows-specific and unrelated to this change).

…llable

The MCP spec paginates tools/list with a top-level nextCursor, but both the
stdio and HTTP JSON-RPC clients issued a single request with empty params and
read only the first page. Every tool past page 1 was silently dropped from
discovery, and callMcpConnectorTool then rejected those tools as "not returned
by tools/list" even though they were valid and read-only.

Both clients now delegate to a shared collectPaginatedTools helper that follows
nextCursor until it is absent. The loop is bounded twice over so a misbehaving
server cannot hang discovery: it stops on a repeated cursor, and on a page cap.
@changeset-bot

changeset-bot Bot commented Aug 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2a257dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openwiki Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP tools/list ignores nextCursor, so tools past page 1 are undiscoverable and uncallable

1 participant