modelcontextprotocol / modelcontextprotocol/java-sdk

Null fields in JsonSchema without @Nullable annotation break serialization with Jackson

Open
#664 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

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:

  • JsonSchema should have default values for these fields instead of defaulting to null, 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

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.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.