Skip to content

fix(client): cap list_all_* pagination like the MRTR round cap - #1457

Open
jokemanfire wants to merge 2 commits into
modelcontextprotocol:mainfrom
jokemanfire:fix/1456-list-page-cap
Open

jokemanfire wants to merge 2 commits into
modelcontextprotocol:mainfrom
jokemanfire:fix/1456-list-page-cap

Conversation

@jokemanfire

Copy link
Copy Markdown
Member

Fixes #1456

Problem

list_all_tools / list_all_prompts / list_all_resources /
list_all_resource_templates / list_all_skills looped until next_cursor
was None. The spec forbids interpreting the cursor value — "" is a valid
cursor — 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's
    listMaxPages) plus *_with_max_pages overrides, mirroring the existing
    call_tool_with_mrtr_max_rounds shape.
  • ServiceError::ListPaginationExceeded { max_pages } names the cap.
  • One shared collect_all_pages helper does the walk for all five methods, so
    the cap applies to cache hits as well and the loops cannot drift apart.
  • Semantics unchanged for well-behaved peers: None still ends the walk, and a
    final page that arrives exactly on the limit is accepted.

Evidence

New unit tests (service::client::list_page_cap_tests):

none_cursor_ends_the_walk ... ok
endless_cursor_is_capped ... ok
empty_string_cursor_is_not_the_end ... ok
final_page_may_arrive_at_the_limit ... ok

empty_string_cursor_is_not_the_end is the one that pins the spec rule: a
"" cursor must not be treated as the end, only the cap stops the walk.

cargo test -p rmcp --lib --features "client server" -> 306 passed
cargo clippy -p rmcp --lib --features "client server" -- -D warnings -> clean
cargo fmt --check -> clean

Notes

  • API addition only; the existing helpers keep their signatures and now delegate.
  • max_pages = 0 fails immediately with ListPaginationExceeded { max_pages: 0 };
    documented on the override methods.
  • I did not add a transport-level test: the cap is exercised through the shared
    helper, and the loop has no transport-specific behaviour left.

`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>
@jokemanfire
jokemanfire requested a review from a team as a code owner November 15, 2026 04:49
Copilot AI balanced review requested due to automatic review settings November 15, 2026 04:49
@github-actions github-actions Bot added T-core Core library changes T-service Service layer changes labels Nov 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T13:19:14.837148Z a786272 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

@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.

Copilot AI 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.

🟢 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 ListPaginationExceeded to 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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-documentation Documentation improvements T-service Service layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client list_all_* helpers follow nextCursor with no page cap

2 participants