Repository navigation
fix(mcp): follow tools/list pagination when caching server tools - #1770
Merged
lizhengfeng101 merged 2 commits intoOct 20, 2026
Merged
Conversation
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
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.
Description
tools/listis a paginated MCP method: each result carries one page plus an optionalnextCursor.internal/mcpread the catalog with a singlesession.ListTools(ctx, nil)call in bothNewClient(stdio) andNewRemoteClient(Streamable HTTP), so on a server that pages its tools only the first page was cached. Every tool past that page was silently invisible toClient.Tools(),RegisterAll,CollectToolDefsand therefore to the review agent: no warning was printed, and the tool could not be reached even by listing it inallowed_tools(that path reports "allowed tool not found in server's tool list").Both constructors now go through a
listAllToolshelper built on the SDK's paginatingmcp.ClientSession.Toolsiterator, so the cached catalog is complete. A server that returns everything in one page behaves exactly as before.Reproduced against a server created with
mcp.ServerOptions{PageSize: 1}and three tools:Type of Change
How Has This Been Tested?
make testpasses locally (see note on the race leg below)New tests:
TestListAllTools_FollowsPaginationconnects an in-memory transport to a server that pages one tool at a time. It first asserts via a plainListToolscall that the fixture really paginates (one tool plus a non-empty cursor), then assertslistAllToolsreturns all three tools in order.TestNewClient_Stdio_PaginatedToolsruns the same fixture as a real stdio subprocess and assertsNewClientcaches all three tools.Both tests fail against the previous single-call behavior (
listAllTools names = [paged_tool_1]) and pass with this change.Other checks run locally:
go test -count=1 ./internal/mcp,go vet ./internal/mcp,go build ./...,go run scripts/verify-english-only.go,gofmt -s -l.Note: the
-raceleg ofmake testcould not run here because this machine has no C compiler for cgo ("gcc not found"). The package passes without-race; the CI race build covers it.Checklist
go fmt,go vet)AI/LLM disclosure: implemented with AI assistance (WorkBuddy coding agent). I reviewed the change and the tests, and will answer questions about the behavior from my own understanding.
Related Issues
No existing issue: this was found while auditing the MCP client against the spec's pagination requirement. Happy to open a tracking issue if you would rather review the bug report first.