modelcontextprotocol / modelcontextprotocol/java-sdk

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

Đang mở
#664 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug P3
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.1k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ mô hình JsonSchema được cung cấp qua tool.inputSchema và tái hiện quá trình tuần tự hóa bằng ObjectMapper, sử dụng các trường được nêu trong báo cáo. Xác định xem các trường bị ảnh hưởng nên nhận giá trị mặc định hay được đánh dấu là nullable, sau đó xác minh rằng một JsonSchema do client cung cấp có thể được tuần tự hóa mà không gặp ngoại lệ đã báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.