Null fields in JsonSchema without @Nullable annotation break serialization with Jackson
まだ誰も着手していません。
評価
調査の方向性
tool.inputSchema を通じて公開されている JsonSchema モデルから始め、レポートで指定されているフィールドを使って ObjectMapper によるシリアライズを再現します。影響を受けるフィールドにデフォルト値を設定すべきか、nullable としてマークすべきかを判断し、その後、クライアントが提供した JsonSchema を報告された例外なしでシリアライズできることを確認します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 9
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/java-sdk のほかの issue
-
area/transport bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
modelcontextprotocol/java-sdk#1136 ·
-
area/client bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/java-sdk#1124 · コメント 1 件 ·
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities オープンbug P2 ready for work
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
modelcontextprotocol/java-sdk#1086 · コメント 1 件 ·
-
enhancement good first issue P3
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/java-sdk#1067 ·
-
bug P2 ready for work
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/java-sdk#898 · コメント 1 件 ·
modelcontextprotocol/java-sdk の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
elastic/gradle-plugins#157 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
cryptomator/hub#497 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
johanhaleby/occurrent#1120 ·