Repository navigation
fix(rmcp): reject null CallToolRequestParams fields and ignore pre-init cancellations - #1532
Conversation
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. |
|
@connor4312 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7624d726fc
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| #[serde( | ||
| default, | ||
| skip_serializing_if = "Option::is_none", | ||
| deserialize_with = "deserialize_non_null_option" |
There was a problem hiding this comment.
Remove null from the generated tool-call schema
With schemars enabled, JsonSchema still derives these properties from Option<T>: the checked-in client_json_rpc_message_schema_current.json permits null for arguments, inputResponses, and requestState. Consumers validating CallToolRequestParams against that schema can construct explicit-null tools/call requests that this deserializer now rejects with -32602; add non-null schema overrides and update the generated schema snapshots alongside the runtime change.
Useful? React with 👍 / 👎.
|
Updated |
jokemanfire
left a comment
There was a problem hiding this comment.
Verified at ad47b5f1 (base d0dab0e3 = current origin/main). I re-ran the gate and reproduced both bugs at the base commit instead of trusting the PR text.
What I ran (all in a clean worktree at the head SHA, CARGO_TARGET_DIR shared with the cached build)
cargo fmt --all -- --check→ clean.cargo clippy -p rmcp --lib --features "client,server,macros,schemars" -- -D warnings -A clippy::result_large_err→ clean (1m18s).cargo test -p rmcp --test test_tool_macros --test test_server_initialization --test test_deserialization --test test_message_schema --features "client,server,macros,schemars"→ 25 / 3 / 23 / 18 passed, 0 failed.- Red-before: the two new tests copied onto
d0dab0e3fail as expected —pre_init_cancelled_notification_is_ignored_and_server_continues:panicked at tests/test_server_initialization.rs:702:48: called Option::unwrap() on a None value(the server never came up).test_tools_call_rejects_explicit_null_arguments_with_invalid_params:panicked at tests/test_tool_macros.rs:766:18(it got a successful tool response instead of-32602).
Independent probe (my own throwaway test, not part of the branch)
Served a Router::new(NoToolsHandler) over a duplex transport and drove it with raw JSON-RPC:
{"name":"hi","arguments":null}→-32602 invalid parameters for tools/call(guard active)."params": null,"arguments": 5, missingname→ same-32602.- A valid
tools/callfor a nonexistent tool still goes down the normal path (-32602 "tool not found"), i.e. the guard does not swallow well-formed requests.
One thing worth fixing: the condition in router.rs is always true
crates/rmcp/src/handler/server/router.rs:149-151 gates on self.get_info().capabilities.tools.is_some(), but this type's own get_info() (same file, :162-168) unconditionally does tools.get_or_insert_with(Default::default()). My probe confirms it: for a wrapped handler whose ServerInfo has capabilities.tools = None, Router::get_info() still reports Some(ToolsCapability { list_changed: Some(true) }). So on the Router path the guard is unconditional, and a Router wrapping a handler that deliberately answers tools/call through on_custom_request would now get -32602 instead of the handler's answer. If the intent is "only when tools are really advertised", use the inner service's info (ServerHandler::get_info(&self.service).capabilities.tools.is_some()); if unconditional is intended, drop the clause so the invariant is explicit.
Coverage gap: the new test drives a #[tool_handler] type, which exercises the ServerHandler::handle_request arm (handler/server.rs:254-265) only. Nothing in the suite exercises the new Router arm, even though Router::handle_request is a separate entry point that runs before delegation. A test shaped like the probe above (serve a Router, send arguments: null, expect -32602) would lock it down.
Minor:
deserialize_non_null_option(model.rs:4177) isdeserialize_present_value(model.rs:4167) generalized; the latter could be expressed asdeserialize_non_null_option::<Value>to avoid two near-identical helpers with opposite doc wording.- Behaviour change worth a line in the release notes:
"arguments": null/"inputResponses": null/"requestState": nullwere accepted before and now return-32602. Spec-correct, but clients that serializeNoneasnullwill start failing. - Codex's P2 about the generated schema allowing
nullis addressed at head:JsonObject/InputResponses/Stringoverrides make the schema non-nullable while the fields stay optional, andtest_message_schema+ both snapshots agree (I diffed them).
Overall this is the right shape and the verification claims hold up. I'm not approving yet — mainly because of the always-true capability check on the Router path and the missing test for it; a reply on those two is all I need.
|
Correction to my review above: I wrote that the PR base equals current Worth a rebase before merge so CI exercises both new main commits alongside this change. |
|
@jokemanfire Thanks for the thorough review and probe! Addressed everything in rebased head
|
ad47b5f to
02f6930
Compare
…per, and rebase onto main
02f6930 to
2253ab8
Compare
|
Rebased onto |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2253ab8604
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if request.method == CallToolRequestMethod::VALUE | ||
| && self.get_info().capabilities.tools.is_some() |
There was a problem hiding this comment.
Validate malformed calls before generic Service dispatch
For a server that implements the public Service<RoleServer> directly rather than using the ServerHandler blanket implementation or Router, tools/call with arguments: null falls back to ClientRequest::CustomRequest; this guard and the router’s parallel branch are never reached. A direct handler that dispatches custom requests as tool calls can still execute the malformed request. Move this validation to shared server dispatch if null rejection is meant to cover every serve path.
Useful? React with 👍 / 👎.
|
@chatgpt-codex-connector[bot] Good catch - moved malformed |
SIDDARTHAREDDY8
left a comment
There was a problem hiding this comment.
I read the diff against base 95e7465 and the new tests. The deserialize_present_option change itself looks right: structured_content: Option<Value> keeps its old Some(Value::Null) behavior since Value accepts null, and the schema snapshots now correctly show the three CallToolRequestParams fields as non-nullable.
A few things I noticed:
-
The pre-init cancellation fix looks test-only in this diff. The body says the pre-init loop in
serve_server_with_ct_innerwas updated to ignoreCancelledNotification, but theserver.rsdiff only addsvalidate_peer_request. The arm that drops all pre-init notifications (logging "dropping a client notification received before the first request") is already on base. So part 2 here is the regression test, not a behavior change. Is that intended, or did a loop change get lost in the rebase onto main? Either way the new test is a useful lock-in for the behavior. -
The capability check described in the body is not in the code. The body says the
-32602applies when the method istools/calland tools capability is enabled, butRoleServer::validate_peer_requestdoes not check the capability, and it runs in the shared serve loop beforehandle_request. So on a server without tools enabled, a malformedtools/callnow gets-32602while a well-formed one would presumably still get-32601from the handler. Is that split intended, or should the guard check the capability first? -
The
-32602carries no detail about what was wrong. By the time the request has fallen through toCustomRequest, the serde error is gone, so a client sending"arguments": nullgets "invalid parameters for tools/call" with no hint which field failed. Would it be worth re-running theCallToolRequestParamsdeserialization insidevalidate_peer_requestand putting the serde error in the error data? That would make the new error code much more actionable for client authors. -
Small test gap: the wire-level tests in
test_tool_macros.rsonly exercise"arguments": null;inputResponses: nullandrequestState: nullare covered only by the serde unit test inserde_impl.rs. Extending one of the three paths (handler, Router, direct service) to the other two fields would close the loop. -
The
client_json_rpc_message_schema_current.jsonsnapshot also gains"additionalProperties": trueonClientCapabilities, which does not look related to the tools/call change. Is that intended, or regenerated snapshot drift?
|
Thanks for the detailed review @SIDDARTHAREDDY8 and @jokemanfire! Pushed
Verified locally:
|
…est all null fields over wire
Closes #1525
Summary
Fixes both server-side issues reported in #1525:
Reject explicit
nullforCallToolRequestParamsoptional object/string fields (-32602Invalid params):deserialize_non_null_optiononCallToolRequestParams::{arguments, input_responses, request_state}incrates/rmcp/src/model.rsso omitted fields remainNonewhile explicitnullvalues are rejected.ClientRequestis#[serde(untagged)]withCustomRequestas its catch-all variant, a malformedtools/callpayload falls through toCustomRequestinstead of reachingCallToolRequest; updatedServerHandler::handle_requestandRouter::handle_requestto returnErrorCode::INVALID_PARAMS(-32602) whenmethod == "tools/call"and tools capability is enabled (instead of falling back to-32601Method not found).Ignore
notifications/cancelledarriving before initialization finishes:serve_server_with_ct_inner(crates/rmcp/src/service/server.rs) to ignoreClientNotification::CancelledNotification(_)(for example cancelling a completedserver/discoverprobe or unknown request id) instead of aborting startup withServerInitializeError::ExpectedInitializeRequest.Verification
cargo fmt --all -- --checkcargo clippy -p rmcp --lib --features "client,server,macros,schemars" -- -D warnings -A clippy::result_large_errcargo test -p rmcp --lib --features "server,macros,schemars"(305 passed)cargo test -p rmcp --test test_server_initialization --test test_tool_macros --test test_custom_request --test test_tool_routers --test test_deserialization --features "client,server,macros,schemars"(including new regression testspre_init_cancelled_notification_is_ignored_and_server_continues,test_tools_call_rejects_explicit_null_arguments_with_invalid_params, andcall_tool_params_rejects_explicit_null_fields)