Fix JsonSchema null collection fields causing serialization failures - #853
Open
rameshreddy-adutla wants to merge 1 commit into
Open
rameshreddy-adutla wants to merge 1 commit into
rameshreddy-adutla wants to merge 1 commit into
Conversation
Servers that omit required, properties, $defs or definitions produce null collections, which break re-serialisation and cause NPEs when iterated. Default them to empty immutable collections and omit empty values on output. Fixes modelcontextprotocol#664.
rameshreddy-adutla
force-pushed
the
fix/664-jsonschema-nullable-defaults
branch
from
September 28, 2026 12:37
7aa3465 to
2846e53
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #664
When an MCP server (e.g. Python/fastmcp) omits optional schema fields like
required,$defs, anddefinitions, Jackson deserializes them asnull. This causes:IllegalArgumentExceptionwhen re-serializing with a standardObjectMapperNullPointerExceptionwhen iterating over these collectionsChanges
McpSchema.JsonSchema(mcp-core)required,properties,defs,definitions) to empty immutable collections (List.of(),Map.of())@JsonInclude(NON_EMPTY)on collection fields: Ensures empty defaults are omitted during serialization, preserving wire format compatibilityTests (
mcp-test)testJsonSchemaWithMissingOptionalFields: Verifies deserialization of a minimal schema (norequired/$defs/definitions) produces non-null collections and round-trips correctlytestJsonSchemaConstructorDefaultsForNullCollections: Verifies direct constructor with null args produces empty collectionsBefore
After