modelcontextprotocol / modelcontextprotocol/java-sdk

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

未關閉
#664 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

bug P3
主要語言
Java
星號
3.7k
分支
1.1k
平均合併
1 天 15 小時
30 天內合併 PR
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:

  • 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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從透過 tool.inputSchema 暴露的 JsonSchema 模型開始,使用報告中列出的欄位,透過 ObjectMapper 重現序列化過程。確定受影響的欄位是否應接收預設值或標記為 nullable,然後驗證用戶端提供的 JsonSchema 是否可以在不出現所回報例外的情況下完成序列化。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
api
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。