Skip to content

tools/list and prompts/list accept a cursor the server never issued #1482

In review

Description

@KhomDev

What

The list_tools and list_prompts implementations generated by #[tool_handler] and #[prompt_handler] always return a single page with next_cursor: None and never read the request's cursor. A request that carries a cursor the server never issued is answered with a normal first page instead of an error.

The pagination spec (2025-11-25, "Error Handling") says:

Invalid cursors SHOULD result in an error with code -32602 (Invalid params).

Since these generated handlers never issue a cursor, any cursor they receive is invalid.

Repro

A server that uses only the generated handlers, and a client in the same process over tokio::io::duplex:

#[tool_handler(router = self.tool_router)]
#[prompt_handler(router = self.prompt_router)]
impl ServerHandler for ListingServer {}

// client side
let params = PaginatedRequestParams::default().with_cursor(Some("not-issued-by-this-server".into()));
let result = client.list_tools(Some(params)).await;

On main (459cb4f) this returns:

Ok(ListToolsResult { next_cursor: None, tools: [], .. })

and the same for list_prompts. Expected: Err(McpError { code: -32602, .. }).

I ran this as an integration test on CI: both cursor cases fail on main (test result: FAILED. 1 passed; 2 failed), and a no-cursor control passes.

Possible fixes

  1. In the generated list_tools / list_prompts, return ErrorData::invalid_params when request.cursor is Some, since these handlers only ever serve one page. I have this change with the test above on a branch (about 10 lines per macro) and can open a PR.
  2. Keep the lenient behaviour (the spec also says servers SHOULD "handle invalid cursors gracefully") and document that the generated handlers ignore cursors.

resources/list and the default list_* methods in the ServerHandler trait also ignore cursors; I kept this report to the two macros. Which direction would you prefer?

This issue was drafted with Claude Code; I reproduced the behaviour and reviewed the text myself.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    P1
    T-macros
    T-handler
    ready for work
    on Nov 20, 2026
  2. github-actions commented on Nov 20, 2026

    @github-actions
    Contributor

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

    Codex labeled this bug / P1 (T-macros, T-handler). Please confirm or correct those labels.

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

  3. jokemanfire commented on Nov 22, 2026

    @jokemanfire
    Member

    I confirmed the code path on 9043cdfa (current main plus the nightly PRs). Both generated handlers accept the request and then ignore it:

    • crates/rmcp-macros/src/tool_handler.rs:66-84 — async fn list_tools(&self, _request: Option<PaginatedRequestParams>, …) returns #router.list_all() with next_cursor: None.
    • crates/rmcp-macros/src/prompt_handler.rs:60-78 — the same shape for list_prompts.

    So the server never issues a cursor and every cursor it receives is invalid. The pagination section says invalid cursors SHOULD be -32602, so option 1 (reject) is the right direction; returning page one makes a broken client look healthy:

    if request.cursor.is_some() {
        return Err(rmcp::ErrorData::invalid_params(
            "this server does not paginate; the cursor was not issued by it",
            None,
        ));
    }

    Rename _request to request in the generated signature; the Option stays because that is the trait signature.

    Two things to put in the PR text:

    1. It is a behaviour change for a client that sends cursor: "". An empty string is a legal opaque cursor and the client helpers here keep walking on one, but this server never returns one, so rejecting it is consistent. Nothing in the repo sends an empty cursor to a generated handler today; I checked.
    2. resources/list and the ServerHandler trait defaults (handler/server.rs:618-628 answers ListToolsResult::default()) ignore the cursor the same way. Changing the trait defaults would alter behaviour for every server that does not override list_*, which is a bigger decision than the two macros. I would keep this issue to the macros and open a separate one for the defaults if we want them strict.

    If you open the PR with the macro change, a test for tools/list, prompts/list, and the no-cursor control, I will review it.

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

Metadata

Metadata

Assignees

Labels

P1T-handlerT-macrosbugready for work

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions