Repository navigation
Description
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
- In the generated
list_tools/list_prompts, returnErrorData::invalid_paramswhenrequest.cursorisSome, 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. - 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
github-actions commentedon Nov 20, 2026
@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.
jokemanfire commentedon Nov 22, 2026
I confirmed the code path on
9043cdfa(currentmainplus 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()withnext_cursor: None.crates/rmcp-macros/src/prompt_handler.rs:60-78— the same shape forlist_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:Rename
_requesttorequestin the generated signature; theOptionstays because that is the trait signature.Two things to put in the PR text:
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.resources/listand theServerHandlertrait defaults (handler/server.rs:618-628answersListToolsResult::default()) ignore the cursor the same way. Changing the trait defaults would alter behaviour for every server that does not overridelist_*, 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.