Repository navigation
fix(client): cap list_all_* pagination like the MRTR round cap - #1457
jokemanfire wants to merge 2 commits into
Conversation
`list_all_tools`, `list_all_prompts`, `list_all_resources`,
`list_all_resource_templates` and `list_all_skills` followed `nextCursor`
until it was absent. The spec forbids reading anything into a cursor value and
explicitly allows `""`, so a server that keeps returning a cursor (or a cached
repeated cursor under a positive `ttlMs`) made the walk grow without bound
until the process ran out of memory.
Bound the walk:
- `DEFAULT_LIST_ALL_MAX_PAGES` (100, matching the TypeScript SDK's
`listMaxPages`), plus `*_with_max_pages` overrides next to the defaults, the
same shape as `call_tool_with_mrtr_max_rounds`.
- `ServiceError::ListPaginationExceeded { max_pages }` names the cap.
- The page check lives in one shared `collect_all_pages` helper, so the five
walks cannot drift and a cache hit is bounded the same way as a network call.
`None` still ends the walk; `Some("")` and a repeated cursor keep going until
the cap, as the spec requires.
Fixes modelcontextprotocol#1456
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@michaelneale is on triage rotation this week and is the reviewer for this one. Labels come from the PR labeler. Please review the change. Automated triage. Labels are a first pass and the assigned maintainer has the final say. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change that bounds Rust SDK list pagination.
No open issues 🎉
What changed in this PR
Bounds the Rust SDK client’s list_all_* pagination to prevent endless page accumulation while preserving opaque cursor handling.
Changes:
- Adds a shared pagination helper with a 100-page default and per-call overrides for all five list helpers.
- Introduces
ListPaginationExceededto report when the configured cap is reached. - Adds tests for normal termination, endless and empty cursors, and completion exactly at the limit.
| File | Description |
|---|---|
crates/rmcp/src/service/client.rs |
Shares bounded pagination across list helpers, adds overrides, and tests boundary behavior. |
crates/rmcp/src/service.rs |
Adds the pagination-limit error variant. |
crates/rmcp/src/model.rs |
Defines the default 100-page cap. |
Review effort: Balanced
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f140cba85
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let mut tools = Vec::new(); | ||
| let mut cursor = None; | ||
| loop { | ||
| self.list_all_tools_with_max_pages(DEFAULT_LIST_ALL_MAX_PAGES) |
There was a problem hiding this comment.
Document the default page limit on list-all helpers
When a valid peer exposes more than 100 pages, this formerly unbounded method now returns ListPaginationExceeded, but its rustdoc still promises to run “until all tools are listed” and README.md:1739-1747 still says every page is fetched; the analogous four methods have the same mismatch. Please state the 100-page default and point callers to *_with_max_pages, otherwise existing users have no documented indication that they must opt in to retrieving larger catalogs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a786272. The rustdoc of all five list_all_* helpers now states the 100-page DEFAULT_LIST_ALL_MAX_PAGES default, names the error (ServiceError::ListPaginationExceeded) and points at *_with_max_pages; README.md (Pagination section) said the helpers "walk every page", so it now spells out the cap and shows list_all_prompts_with_max_pages(500) as the opt-in. The four "like ..." variants were already pointing at the tools override, which now carries the cap text.
The rustdoc of the five `list_all_*` helpers still promised to follow `nextCursor` "until all tools are listed", and the README said the helpers walk every page. Both are wrong since the cap landed: a server that keeps returning a cursor now ends in `ServiceError::ListPaginationExceeded` after 100 pages. State the default cap, name the `*_with_max_pages` escape hatch, and show it in the README snippet. Refs: modelcontextprotocol#1456 Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
Fixes #1456
Problem
list_all_tools/list_all_prompts/list_all_resources/list_all_resource_templates/list_all_skillslooped untilnext_cursorwas
None. The spec forbids interpreting the cursor value —""is a validcursor — so a peer that keeps returning one (a fresh token per page, the same
token again, or a repeated cursor served from the page cache under a positive
ttlMs) made the walk append pages until the process ran out of memory.Change
DEFAULT_LIST_ALL_MAX_PAGES = 100(same default as the TypeScript SDK'slistMaxPages) plus*_with_max_pagesoverrides, mirroring the existingcall_tool_with_mrtr_max_roundsshape.ServiceError::ListPaginationExceeded { max_pages }names the cap.collect_all_pageshelper does the walk for all five methods, sothe cap applies to cache hits as well and the loops cannot drift apart.
Nonestill ends the walk, and afinal page that arrives exactly on the limit is accepted.
Evidence
New unit tests (
service::client::list_page_cap_tests):empty_string_cursor_is_not_the_endis the one that pins the spec rule: a""cursor must not be treated as the end, only the cap stops the walk.Notes
max_pages = 0fails immediately withListPaginationExceeded { max_pages: 0 };documented on the override methods.
helper, and the loop has no transport-specific behaviour left.