Null fields in JsonSchema without @Nullable annotation break serialization with Jackson
还没有人认领这个 Issue。
评估
调研方向
从通过 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 小时
- 30 天内合并 PR
- 9
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 ·