Repository navigation
fix(mcp): follow tool catalog pagination cursors - #936
rudycelekli wants to merge 2 commits into
Conversation
Yanami-2K
left a comment
There was a problem hiding this comment.
跟随 nextCursor 分页是必要的修复,两页目录的测试也成立。但描述里说的 "fail on a repeated cursor so a malformed catalog cannot loop forever" 只做到了一半:
internal/mcpclient/client.goListToolsContext的for循环:seen只拦截重复游标。服务端每次都返回一个新游标(实现有 bug 或恶意网关)时,循环不会结束,tools会一直增长。ListTools()走的是context.Background(),没有截止时间兜底。建议加一个页数上限(比如maxToolPages = 100),超过时返回明确错误,例如mcp tools/list exceeded %d pages。seen[next]这个新增的错误分支没有测试。请在pagination_test.go里加一个用例:服务端一直返回同一个游标,断言返回 "repeated its pagination cursor" 错误、且请求次数有限;第 1 条加上页数上限后,也补一个持续返回新游标的用例。
另外,client.go 的 diff 在 listToolsPage 结尾处被截断,我没看到最后的 return 语句。#935 也修改了 ListToolsContext 里构造请求的那段代码(加了 setSessionHeaders),两边一定会有文本冲突,合入顺序上需要协调。
34571dc to
b6c5934
Compare
|
Addressed both pagination gaps. I also rebased this PR and coordinated it with the rebased #935. Actual merges succeed automatically in both orders and produce identical Git trees; the negotiated headers land inside |
What changed
Follow
nextCursorwhen listing an MCP tool catalog. Stop on a repeated cursor, and cap the catalog at 100 pages so a server returning endlessly fresh cursors cannot grow memory and issue requests forever. A terminal 100th page remains valid; limit/cursor errors return no partial catalog.Validation
mcp tools/list exceeded 100 pages.internal/mcpclientpackage tests, package vet, gofmt andgit diff --checkpass.Related changes
Rebased onto main
6f606cf. The rebased session-header fix in #935 and this PR merge automatically in both orders, with identical resulting Git trees. Combined package tests/vet pass. An isolated additional strict-server check verified the negotiated headers on both catalog pages, ID-free initialization notification, opaque cursor round-trip and cancellation during page two. No manual production conflict resolution was needed.Full platform/frontend build, browser acceptance and the complete platform Go checks were not run for this revision; maintainer-triggered platform CI remains required. Tests use only synthetic loopback HTTP endpoints. Codex assisted with implementation and validation.