fix: follow tools/list pagination so all MCP tools are callable - #566
Open
Divya (divya0795) wants to merge 1 commit into
Open
fix: follow tools/list pagination so all MCP tools are callable#566Divya (divya0795) wants to merge 1 commit into
Divya (divya0795) wants to merge 1 commit into
Conversation
…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 detectedLatest commit: 2a257dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #565.
The MCP spec paginates
tools/listwith a top-levelnextCursor: a client must re-issue the request with that cursor until the field is absent. Both JSON-RPC clients insrc/connectors/mcp-client.tsissued 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.
callMcpConnectorToolhard-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 withMCP tool <name> was not returned by tools/list— and the error points the user atopenwiki_list_mcp_tools, which was itself truncated to page 1, so the advice could never resolve it.Changes
collectPaginatedTools, a shared helper that followsnextCursoruntil it is absent and concatenates the pages. It reuses the existingextractToolValues, so a malformed page still contributes nothing rather than throwing.StdioJsonRpcClient.listToolsandHttpJsonRpcClient.listToolsat the helper — both transports were affected, and both expose an identical privaterequest(method, params), so neither needed its own loop.Behavior and safety
The first request is unchanged (
tools/listwith{}), and a server that returns nonextCursorstill results in exactly one round-trip — no extra traffic for the non-paginating case.listToolsstill resolves to{ tools }, soextractToolsand both call sites are untouched. Tool validation and the read-only policy checks inmcp-runtime.tsare 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 exportedlistMcpToolsagainst a stubbed MCP server:{ cursor: "cursor-2" };tools/listrequest (regression guard against extra traffic);Confirmed these are real regression tests: with the source change reverted, three of the four fail; all four pass with it.
Validation:
pnpm run formatpnpm run lintpnpm run typecheckpnpm test— 872/873 pass. The one failure istest/openwiki-ignore.test.ts > restricts shell execute while ignore rules are active, which fails identically on an unmodifiedmainon this machine (it shells out topwd, so it is Windows-specific and unrelated to this change).