Skip to content

Client list_all_* helpers follow nextCursor with no page cap #1456

Description

@mateolafalce

Peer<RoleClient>::list_all_tools, list_all_prompts, list_all_resources, list_all_resource_templates, and list_all_skills (crates/rmcp/src/service/client.rs) loop until next_cursor is None. Nothing else stops them.

loop {
    let result = self
        .list_tools(Some(PaginatedRequestParams { meta: None, cursor }))
        .await?;
    tools.extend(result.tools);
    cursor = result.next_cursor;
    if cursor.is_none() {
        break;
    }
}

The same loop is copied for the other four methods. These are the helpers the examples and the Python/JS interop tests call to load a server.

Why it matters

The 2026-07-28 pagination rules say a client treats a missing nextCursor as the end of the results, and that it must not decide anything else from the cursor value. An empty string is explicitly a valid cursor. A server that keeps the field present — "", the same token again, or a fresh token every page — makes list_all_* run until the process runs out of memory. Each iteration appends another page first, so the Vec grows without bound.

That is a realistic peer, not only a hostile one. The C# SDK hit non-terminating tools/list walks in csharp-sdk#988 and csharp-sdk#1072. The TypeScript client used to stop when a cursor repeated, which silently dropped pages, and typescript-sdk#2736 removed that check. It still fails the walk with ListPaginationExceeded after listMaxPages.

A positive ttlMs makes the Rust walk worse. list_tools / list_prompts / list_resources / list_resource_templates cache a page under a key that is only the cursor (list_response_cache_key). ttlMs: 0 is not stored (ClientCacheConfig::default_ttl is zero, and cache_response_with_generation skips a zero TTL), but the spec's own example uses ttlMs: 300000. Once a repeated cursor is cached, later iterations never reach the server: they append the cached page again in a tight loop. list_all_skills is not cached, so that one stays a network loop.

What not to do

Do not treat "" or a repeated cursor as the end. The spec forbids that, and the TypeScript SDK already shipped a bug by stopping on a repeated opaque cursor.

Suggestion

Bound the walk, the same way MRTR is already bounded.

call_tool_with_mrtr_max_rounds stops after DEFAULT_MRTR_MAX_ROUNDS and returns ServiceError::InputRequiredRoundsExceeded. A list_all_* walk needs the same shape: a finite default, an override, and a ServiceError variant that names the cap. Check the cap on cache hits too, so a cached repeated cursor cannot spin. Keep requesting while next_cursor is Some, including Some("").

skills/list is not in the core pagination section, but list_all_skills has the same loop and should share the cap.

Activity

  1. added
    bug
    P0
    T-service
    T-security
    ready for work
    on Nov 14, 2026
  2. github-actions commented on Nov 14, 2026

    @github-actions
    Contributor

    @jokemanfire is on triage rotation this week and is the reviewer for this one.

    Codex labeled this bug / P0 (T-service, T-security). Please confirm or correct those labels.

    Automated triage. Labels are a first pass and the assigned maintainer has the final say.

  3. marcus-beauregard commented on Nov 20, 2026

    @marcus-beauregard

    Opened #1479 with a cap on the walk: DEFAULT_LIST_MAX_PAGES = 64 in model.rs, counted in the shared list_all_pages loop so cached responses count too, and a new ServiceError::ListPaginationExceeded instead of growing the merged list. Each helper keeps its signature and gains a *_with_max_pages override.

    Four unit tests cover the looping cursor, the default, Some("") as a valid cursor, and an explicit shorter cap — all driven through the response cache on a disconnected peer, so no server needed.

    It is open as a draft because this account is currently refused markPullRequestReadyForReview by the API; the diff and description are complete and it is ready for review as-is.

  4. added 2 commits that reference this issue on Nov 21, 2026
    8504a41
    8ff82dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0T-securityT-servicebugready for work

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions