Null fields in JsonSchema without @Nullable annotation break serialization with Jackson
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start at the JsonSchema model exposed through tool.inputSchema and reproduce serialization with ObjectMapper using the fields named in the report. Determine whether the affected fields should receive defaults or be marked nullable, then verify that a client-provided JsonSchema can be serialized without the reported exception.
Written by the indexing model from the issue text.
Description
Bug description
When connecting as a client to an MCP server written with fastmcp 2.12.3, some tool input schemas received from the server are deserialized in Java with a number of JsonSchema fields set to null: required, additionalProperties, defs, and definitions.
This breaks Jackson serialization for the resulting JsonSchema:
McpSyncClient client = ...;
Tool tool = client.listTools().tools().get(0);
tool.inputSchema().required() // -> null
tool.inputSchema().additionalProperties() // -> null
tool.inputSchema().defs() // -> null
tool.inputSchema().definitions() // -> null
(new ObjectMapper()).valueToTree(tool.inputSchema)
Results in:
java.lang.IllegalArgumentException: Non-nullable field additionalProperties was null, annotate with @Nullable if this is expected (through reference chain: io.modelcontextprotocol.spec.McpSchema$JsonSchema["additionalProperties"])
As a workaround, you can reconstruct the JsonSchema with some sensible defaults before serializing:
new JsonSchema(inputSchema.type, inputSchema.properties, List.of(), true, Map.of(), Map.of())
which resolves the issue.
Environment
- Observed on a Mac, library version
0.13.1, Java 21
Steps to reproduce
See above.
Expected behavior
Jackson should be able to serialize JsonSchema objects provided by the client.
Either:
JsonSchemashould have default values for these fields instead of defaulting tonull, OR- These fields should be annotated with
@Nullable
Minimal Complete Reproducible example
It's difficult without also providing an example of the server, but let me know if anything is unclear or if I can provide any additional details.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 1.1k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/java-sdk
-
area/transport bug P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
modelcontextprotocol/java-sdk#1136 ·
-
area/client bug P2
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelcontextprotocol/java-sdk#1124 · 1 comment ·
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities Openbug P2 ready for work
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
modelcontextprotocol/java-sdk#1086 · 1 comment ·
-
enhancement good first issue P3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
modelcontextprotocol/java-sdk#1067 ·
-
bug P2 ready for work
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
modelcontextprotocol/java-sdk#898 · 1 comment ·
All issues in modelcontextprotocol/java-sdk
Similar issues
-
bug untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
opensearch-project/ml-commons#5094 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
emitter:client:csharp feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 Openbug frontend maui-pilot
Difficulty 2/5 1-3 hours Newbie friendliness 72/100