modelcontextprotocol / modelcontextprotocol/java-sdk
Null fields in JsonSchema without @Nullable annotation break serialization with Jackson
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 9
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
tool.inputSchema を通じて公開されている JsonSchema モデルから始め、レポートで指定されているフィールドを使って ObjectMapper によるシリアライズを再現します。影響を受けるフィールドにデフォルト値を設定すべきか、nullable としてマークすべきかを判断し、その後、クライアントが提供した JsonSchema を報告された例外なしでシリアライズできることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- api
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100