modelcontextprotocol / modelcontextprotocol/java-sdk

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

Offen
#664 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P3
Vorherrschende Sprache
Java
Sterne
3.7k
Forks
1.1k
Ø Merge
1 T. 15 Std.
Gemergte PRs (30 T.)
9

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne beim über tool.inputSchema bereitgestellten JsonSchema-Modell und reproduziere die Serialisierung mit ObjectMapper unter Verwendung der im Bericht genannten Felder. Ermittle, ob die betroffenen Felder Standardwerte erhalten oder als nullable gekennzeichnet werden sollten, und überprüfe anschließend, ob ein vom Client bereitgestelltes JsonSchema ohne die gemeldete Ausnahme serialisiert werden kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
api
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.