Skip to content

fix(mcp): follow tools/list pagination when caching server tools - #1770

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
ydflow:fix/mcp-tool-list-pagination
Oct 20, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
ydflow:fix/mcp-tool-list-pagination

Conversation

@ydflow

@ydflow ydflow commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Description

tools/list is a paginated MCP method: each result carries one page plus an optional nextCursor. internal/mcp read the catalog with a single session.ListTools(ctx, nil) call in both NewClient (stdio) and NewRemoteClient (Streamable HTTP), so on a server that pages its tools only the first page was cached. Every tool past that page was silently invisible to Client.Tools(), RegisterAll, CollectToolDefs and therefore to the review agent: no warning was printed, and the tool could not be reached even by listing it in allowed_tools (that path reports "allowed tool not found in server's tool list").

Both constructors now go through a listAllTools helper built on the SDK's paginating mcp.ClientSession.Tools iterator, 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:

session.ListTools(ctx, nil)  -> 1 tool,  nextCursor non-empty
listAllTools(ctx, session)   -> 3 tools: paged_tool_1 paged_tool_2 paged_tool_3

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally (see note on the race leg below)
  • Manual testing (described below)

New tests:

  • TestListAllTools_FollowsPagination connects an in-memory transport to a server that pages one tool at a time. It first asserts via a plain ListTools call that the fixture really paginates (one tool plus a non-empty cursor), then asserts listAllTools returns all three tools in order.
  • TestNewClient_Stdio_PaginatedTools runs the same fixture as a real stdio subprocess and asserts NewClient caches 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 -race leg of make test could 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

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable) — no user-facing behavior or docs text changes; more tools simply become available
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

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.

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 410ddb8 into alibaba:main Oct 20, 2026
12 checks passed
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.

3 participants