Repository navigation
fix(handler): keep RequestContext meta on extract - #1583
orangeCatDeveloper wants to merge 1 commit into
Conversation
The RequestMetaObject extractor moved the meta out of the RequestContext, so a RequestContext parameter listed after it saw empty meta: no progress token, and no client info or capabilities on sessionless requests.
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. |
jokemanfire
left a comment
There was a problem hiding this comment.
Verified at 7cca723c (base 3725772), not from the description.
Red → green, using this PR's own test
I split the change so only the test moves: at base 3725772 with common.rs untouched (mem::swap still in place) and tool.rs taken from this branch, the new test fails with
left: "Some(ProgressToken(Number(7))) None"
right: "Some(ProgressToken(Number(7))) Some(ProgressToken(Number(7)))"
At head the same test passes (cargo test -p rmcp --all-features test_meta_extractor_leaves_request_context_meta_intact → 1 passed, 967 filtered).
So the diagnosis in #1580 is correct: the extractor mutates the context instead of reading it.
Gates at head
cargo clippy -p rmcp --all-features --all-targets -- -D warnings→ clean (54s).cargo fmt --check -p rmcp→ clean on stable. Note the repo's rustfmt config usesimports_granularity/group_imports, which stable cannot enforce, so nightly fmt is still unverified on my side.- No checks are reported on the branch, so CI has not run on this head either.
Consistency
The new body matches the other five FromContextPart impls in crates/rmcp/src/handler/server/common.rs (RequestContext, CancellationToken, Extensions, Extension, Peer, RequestId), and grep finds no remaining destructive read of RequestContext::meta (meta.take() / mem::take) in the tree. Keeping as_request_context_mut is right; removing it would be a breaking trait change.
One request before I approve
The test pins only the progress token, while the issue also claims that sessionless requests lose client info and capabilities. Those live in the same RequestMetaObject, so the clone covers them, but nothing in the suite would notice if a later refactor special-cased the token. Please either build the test meta with RequestMetaObject::with_client_context(protocol_version, client_info, client_capabilities) and assert client_info/client_capabilities survive after extraction, or trim that half of the issue text. A one-line assertion on ctx.meta.client_info() is enough.
Not requesting changes on anything else; the fix itself is correct.
Fixes #1580
A tool or prompt handler that takes
RequestMetaObjectbeforeRequestContextsees emptyctx.meta: no progress token, and no client info or capabilities on sessionless requests.Motivation and Context
The
RequestMetaObjectextractormem::swaps the meta out of theRequestContext, so every extractor that runs after it reads a default meta. The fix clones it, as the otherRequestContext-derived extractors (RequestContext,Peer,Extensions,RequestId,CancellationToken) already do. It is shared by the tool and prompt routers, so both are fixed.How Has This Been Tested?
A tool
probe(meta: RequestMetaObject, ctx: RequestContext<RoleServer>)called from an rmcp client over a duplex transport, printing both progress tokens:test_meta_extractor_leaves_request_context_meta_intactdrives the same parameter order throughToolRouter; it fails on main.Breaking Changes
None.
as_request_context_mutis no longer called but stays, since it is a public trait method.Types of changes
Checklist