fix(mcp): follow tools/list pagination instead of silently truncating#5833
Conversation
The SDK's listTools() returns a single page; a server that paginates via nextCursor was silently truncated to page one. Follow the cursor bounded by four independent budgets (50 pages / 1000 tools / 5 MB / 60s aggregate wall-clock) plus a repeated-cursor guard — a page cap alone can't stop a server returning a fresh cursor with no new tools. Partial results from earlier pages are kept when a later page fails; only a page-one failure throws. Matches the LibreChat capped-cursor-loop pattern; caps live in MCP_CLIENT_CONSTANTS.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Pagination is bounded by new Partial success: if page 1+ succeeds and a later page errors, collected tools are returned (including Reviewed by Cursor Bugbot for commit 57abaec. Configure here. |
Greptile SummaryThis PR adds complete, bounded pagination for MCP tool discovery. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "fix(mcp): count UTF-8 bytes, keep empty ..." | Re-trigger Greptile |
…curately Review fixes on the tools/list pagination loop: - Buffer.byteLength(..., 'utf8') instead of .length so non-ASCII schemas can't overshoot the 5 MB budget by counting UTF-16 code units. - Track pagesFetched (not tools.length) for the partial-success decision, so a valid-but-empty first page followed by a failing page returns [] instead of throwing and marking the server unhealthy. - Explicit reachedEnd/page-cap distinction so a natural finish on exactly MAX_PAGES isn't mislogged as truncated.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 57abaec. Configure here.
Summary
listTools()returns a single page. A server that paginates its tool list vianextCursorwas silently truncated to page one — its later tools just never appeared, with no error.MCP_CLIENT_CONSTANTS.nextCursor= end of results, opaque cursors).Deliberately scoped to pagination only. Legacy HTTP+SSE transport fallback is a separate, larger change (restructures the connect path + a real header-auth-on-SSE-GET footgun + needs a real legacy-SSE server to validate against) — recommended as its own PR, not bundled here.
Type of Change
Testing
nextCursor, repeated-cursor loop guard stops early, later-page failure returns partial results. All 19 client tests green; tsc + biome clean.Checklist