Skip to content

fix(model): keep unknown capability fields on ServerCapabilities and ClientCapabilities - #1468

Open
no-hup wants to merge 1 commit into
modelcontextprotocol:mainfrom
no-hup:fix/server-capabilities-extra-fields
Open

no-hup wants to merge 1 commit into
modelcontextprotocol:mainfrom
no-hup:fix/server-capabilities-extra-fields

Conversation

@no-hup

@no-hup no-hup commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

fixes #1447

ServerCapabilities and ClientCapabilities dropped any field rmcp doesn't model, so a gateway that parses and re-sends capabilities lost things like events. 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": true on the two types.

tests: server_capabilities_keep_unknown_fields, client_capabilities_keep_unknown_fields, built_capabilities_serialize_without_extra_fields. full cargo test -p rmcp --all-features passes, fmt + clippy clean.

AI use: found and written with Claude Code. Tests were run locally.

…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.
@no-hup
no-hup requested a review from a team as a code owner November 17, 2026 06:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T06:40:23.944098Z 1786355 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added T-test Testing related changes T-config Configuration file changes T-core Core library changes T-model Model/data structure changes labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@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 jokemanfire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json was rewritten, so the additionalProperties: true deltas 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 in rustfmt.toml are skipped here, so the nightly fmt job is still the authoritative one).

Code read

  • extra: JsonObject with #[serde(flatten)] on both structs; the builder macro's build() sets JsonObject::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 extra really does serialize to nothing: built_capabilities_serialize_without_extra_fields covers it, and #[serde(flatten)] drops an empty map, so ServerCapabilities::default() still emits {}.
  • Adding a public field is source-compatible here because both structs are #[non_exhaustive]; downstream callers build through the builders, and caps.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 SIDDARTHAREDDY8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. I verified the schema edits land on the right objects — additionalProperties: true was added to the ClientCapabilities object in both schema files and to the ServerCapabilities object in the server schema. But test_message_schema.rs regenerates 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.
  2. 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. in test_deserialization.rs), or is the unit-level round trip the intended coverage? If the latter, the unit tests look sufficient as-is.

@no-hup

no-hup commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

thanks for checking

  1. yep, test_message_schema passes on this branch (all 3), so the committed schemas match what schemars emits
  2. unit level round trip is the intended coverage. there isnt a capabilities parse-and-resend test in test_deserialization.rs, and the gateway case is really just deserialize then serialize the same struct, which is what the new tests do. happy to add one there if you want it though

@jokemanfire jokemanfire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

This branch has not been deployed

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

Labels

T-config Configuration file changes T-core Core library changes T-model Model/data structure changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ServerCapabilities drops unknown fields such as events

3 participants