-
Notifications
You must be signed in to change notification settings - Fork 733
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.