Skip to content

Add @JsonIgnoreProperties(ignoreUnknown = true) to capability sub-records#852

Open
rameshreddy-adutla wants to merge 1 commit intomodelcontextprotocol:mainfrom
rameshreddy-adutla:fix/766-json-ignore-unknown-capabilities
Open

Add @JsonIgnoreProperties(ignoreUnknown = true) to capability sub-records#852
rameshreddy-adutla wants to merge 1 commit intomodelcontextprotocol:mainfrom
rameshreddy-adutla:fix/766-json-ignore-unknown-capabilities

Conversation

@rameshreddy-adutla
Copy link

Summary

Add @JsonIgnoreProperties(ignoreUnknown = true) to all capability sub-records that are missing the annotation, ensuring forward compatibility when the MCP spec adds new fields.

Problem

The top-level ClientCapabilities and ServerCapabilities records have @JsonIgnoreProperties(ignoreUnknown = true), but their nested sub-records do not. Since the ObjectMapper defaults to FAIL_ON_UNKNOWN_PROPERTIES = true, any unknown field on a capability sub-object causes a deserialization failure.

This already caused a real breakage when the elicitation capability gained form and url fields (#724, fixed in #731). The systemic issue remains — the next spec addition to any capability sub-object will break older SDK versions.

The MCP spec schema explicitly does not close capability objects (additionalProperties: false is never set). Several sub-capabilities (sampling, elicitation, completions, logging) explicitly set additionalProperties: true.

Fix

Add @JsonIgnoreProperties(ignoreUnknown = true) to:

Record Location
ClientCapabilities.Sampling Line ~407
ClientCapabilities.Elicitation Line ~434
ClientCapabilities.Elicitation.Form Line ~440
ClientCapabilities.Elicitation.Url Line ~447
ServerCapabilities.CompletionCapabilities Line ~549
ServerCapabilities.LoggingCapabilities Line ~556
ServerCapabilities.PromptCapabilities Line ~566
ServerCapabilities.ResourceCapabilities Line ~577
ServerCapabilities.ToolCapabilities Line ~588

Testing

Added 9 targeted tests in McpSchemaTests that verify each sub-record correctly ignores unknown fields during deserialization. All existing tests continue to pass.

Fixes #766
Related: #734

…ords

The top-level ClientCapabilities and ServerCapabilities records have
@JsonIgnoreProperties(ignoreUnknown = true) but their nested sub-records
do not. Since ObjectMapper defaults to FAIL_ON_UNKNOWN_PROPERTIES = true,
unknown fields on sub-objects cause deserialization failures.

This already caused a real breakage when elicitation gained form/url
fields (modelcontextprotocol#724). The MCP spec explicitly does not close capability objects
(additionalProperties is never set to false), so SDKs must tolerate
unknown fields for forward compatibility.

Add the annotation to:
- ClientCapabilities.Sampling
- ClientCapabilities.Elicitation, Elicitation.Form, Elicitation.Url
- ServerCapabilities.CompletionCapabilities
- ServerCapabilities.LoggingCapabilities
- ServerCapabilities.PromptCapabilities
- ServerCapabilities.ResourceCapabilities
- ServerCapabilities.ToolCapabilities

Fixes modelcontextprotocol#766

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing @JsonIgnoreProperties(ignoreUnknown = true) on capability sub-records

1 participant