Repository navigation
Conversation
…ClientCapabilities The schema leaves both capability sets open, so fields such as `events` were dropped when a gateway parsed and re-sent them. Fixes modelcontextprotocol#1447.
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. |
|
@michaelneale 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. |
jokemanfire
left a comment
There was a problem hiding this comment.
Verified at 1786355 rather than from the description.
What I ran
cargo test -p rmcp --lib --all-features model::capabilities: 15 passed (3 new tests included), 0 failed.cargo test -p rmcp --test test_message_schema --features "server client schemars": 3 passed — the committed schemas match the regenerated ones, and no_current.jsonwas rewritten, so theadditionalProperties: truedeltas are the whole schema change.cargo clippy -p rmcp --all-targets --all-features -- -D warnings: clean.cargo fmt --check: clean on stable 1.96 (the nightly-only import options inrustfmt.tomlare skipped here, so the nightlyfmtjob is still the authoritative one).
Code read
extra: JsonObjectwith#[serde(flatten)]on both structs; the builder macro'sbuild()setsJsonObject::default(), and the macro is instantiated only for these two types (capabilities.rs:394,capabilities.rs:489), so no other builder target is affected by that added line.- An empty
extrareally does serialize to nothing:built_capabilities_serialize_without_extra_fieldscovers it, and#[serde(flatten)]drops an empty map, soServerCapabilities::default()still emits{}. - Adding a public field is source-compatible here because both structs are
#[non_exhaustive]; downstream callers build through the builders, andcaps.extra.insert(..)works for anyone who wants to add a field explicitly.
One suggestion, non-blocking
The tests round-trip ServerCapabilities/ClientCapabilities directly. The report is about a gateway forwarding initialize / server/discover, so a nested case would lock the actual shape, e.g. serialize ServerResult::InitializeResult (and the client side) with capabilities.events and assert the key survives. Same serde path, but it fails if a future wrapper ever re-serializes capabilities through a narrower type.
I did not hit any behavioural regression in the flatten/builder/builder-toggle tests. Not approving yet since this is the only question I have.
SIDDARTHAREDDY8
left a comment
There was a problem hiding this comment.
I checked the change against capabilities.rs at the PR head, the schema snapshots, and test_message_schema.rs. The approach is sound: #[serde(flatten)] pub extra: JsonObject round-trips unknown fields on both structs, the new tests cover the round trip on both sides plus the builder serializing with no extra fields, and since both structs are #[non_exhaustive] the new field cannot break downstream struct literals (the builder sets extra to default).
Two checks worth confirming:
- I verified the schema edits land on the right objects —
additionalProperties: truewas added to theClientCapabilitiesobject in both schema files and to theServerCapabilitiesobject in the server schema. Buttest_message_schema.rsregenerates both schemas from the types with schemars and asserts exact JSON equality with the committed files, so please confirm that test passes on this branch: a hand edit that differs at all from what schemars emits for a flattened map would fail it. - Small question on coverage: the PR body motivates this with a gateway parsing and re-sending capabilities (e.g.
events). The new tests cover an unknown field surviving one deserialize/serialize round trip at the unit level — is there an existing test exercising a full parse-and-resend through the transport (e.g. intest_deserialization.rs), or is the unit-level round trip the intended coverage? If the latter, the unit tests look sufficient as-is.
|
thanks for checking
|
jokemanfire
left a comment
There was a problem hiding this comment.
Both answers are acceptable, so my only open question is cleared.
On (2): I checked the narrowing path myself rather than take the argument — git grep over crates/rmcp/src at 1786355 shows InitializeResult.capabilities is a plain ServerCapabilities (model.rs:1286), the only constructions are ServerCapabilities::default() in the Default impls and the builder macro, and no forwarding code rebuilds capabilities field-by-field. So the unit-level round trip exercises the same serde path a gateway would, and a nested case would add coverage of InitializeResult, not of the flatten attribute. Optional, agreed.
The flatten-on-empty-map behaviour and the additionalProperties: true schema deltas are the two things that could have regressed existing callers, and both are pinned by tests that pass at this SHA. Approving; if a maintainer would still like the InitializeResult wrapper case, it can land as a follow-up.
For the record, my runs at 1786355: cargo test -p rmcp --lib --all-features model::capabilities 15 passed; cargo test -p rmcp --test test_message_schema --features "server client schemars" 3 passed; cargo clippy -p rmcp --all-targets --all-features -- -D warnings clean (Linux, stable 1.96).
fixes #1447
ServerCapabilitiesandClientCapabilitiesdropped any field rmcp doesn't model, so a gateway that parses and re-sends capabilities lost things likeevents. the schema says both sets are open ("this is not a closed set: any server can define its own, additional capabilities").both structs now have
#[serde(flatten)] pub extra: JsonObject, so unknown fields survive a round trip. both are#[non_exhaustive]so the new field isn't a breaking change. the builder fills it with an empty map, so built capabilities serialize the same as before. the JSON schema snapshots gain"additionalProperties": trueon the two types.tests:
server_capabilities_keep_unknown_fields,client_capabilities_keep_unknown_fields,built_capabilities_serialize_without_extra_fields. fullcargo test -p rmcp --all-featurespasses, fmt + clippy clean.AI use: found and written with Claude Code. Tests were run locally.