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 摘要。