Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit 26460e6

Browse files
committed
feat(mcp): add JsonIgnoreProperties to schema records for resilient deserialization
1 parent 2199e34 commit 26460e6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mcp/src/main/java/org/springframework/ai/mcp/spec/McpSchema.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public record InitializeRequest( // @formatter:off
222222
} // @formatter:on
223223

224224
@JsonInclude(JsonInclude.Include.NON_ABSENT)
225+
@JsonIgnoreProperties(ignoreUnknown = true)
225226
public record InitializeResult( // @formatter:off
226227
@JsonProperty("protocolVersion") String protocolVersion,
227228
@JsonProperty("capabilities") ServerCapabilities capabilities,
@@ -472,12 +473,14 @@ public record ResourceTemplate( // @formatter:off
472473
} // @formatter:on
473474

474475
@JsonInclude(JsonInclude.Include.NON_ABSENT)
476+
@JsonIgnoreProperties(ignoreUnknown = true)
475477
public record ListResourcesResult( // @formatter:off
476478
@JsonProperty("resources") List<Resource> resources,
477479
@JsonProperty("nextCursor") String nextCursor) {
478480
} // @formatter:on
479481

480482
@JsonInclude(JsonInclude.Include.NON_ABSENT)
483+
@JsonIgnoreProperties(ignoreUnknown = true)
481484
public record ListResourceTemplatesResult( // @formatter:off
482485
@JsonProperty("resourceTemplates") List<ResourceTemplate> resourceTemplates,
483486
@JsonProperty("nextCursor") String nextCursor) {
@@ -489,6 +492,7 @@ public record ReadResourceRequest( // @formatter:off
489492
} // @formatter:on
490493

491494
@JsonInclude(JsonInclude.Include.NON_ABSENT)
495+
@JsonIgnoreProperties(ignoreUnknown = true)
492496
public record ReadResourceResult( // @formatter:off
493497
@JsonProperty("contents") List<ResourceContents> contents){
494498
} // @formatter:on
@@ -619,6 +623,7 @@ public record PromptMessage( // @formatter:off
619623
* are more prompts available.
620624
*/
621625
@JsonInclude(JsonInclude.Include.NON_ABSENT)
626+
@JsonIgnoreProperties(ignoreUnknown = true)
622627
public record ListPromptsResult( // @formatter:off
623628
@JsonProperty("prompts") List<Prompt> prompts,
624629
@JsonProperty("nextCursor") String nextCursor) {
@@ -643,6 +648,7 @@ public record GetPromptRequest(// @formatter:off
643648
* @param messages A list of messages to display as part of the prompt.
644649
*/
645650
@JsonInclude(JsonInclude.Include.NON_ABSENT)
651+
@JsonIgnoreProperties(ignoreUnknown = true)
646652
public record GetPromptResult( // @formatter:off
647653
@JsonProperty("description") String description,
648654
@JsonProperty("messages") List<PromptMessage> messages) {
@@ -659,6 +665,7 @@ public record GetPromptResult( // @formatter:off
659665
* are more tools available.
660666
*/
661667
@JsonInclude(JsonInclude.Include.NON_ABSENT)
668+
@JsonIgnoreProperties(ignoreUnknown = true)
662669
public record ListToolsResult( // @formatter:off
663670
@JsonProperty("tools") List<Tool> tools,
664671
@JsonProperty("nextCursor") String nextCursor) {
@@ -716,6 +723,7 @@ public static JsonSchema parseSchema(String schema) {
716723
* input schema.
717724
*/
718725
@JsonInclude(JsonInclude.Include.NON_ABSENT)
726+
@JsonIgnoreProperties(ignoreUnknown = true)
719727
public record CallToolRequest(// @formatter:off
720728
@JsonProperty("name") String name,
721729
@JsonProperty("arguments") Map<String, Object> arguments) implements Request {
@@ -730,6 +738,7 @@ public record CallToolRequest(// @formatter:off
730738
* If false or absent, indicates successful execution.
731739
*/
732740
@JsonInclude(JsonInclude.Include.NON_ABSENT)
741+
@JsonIgnoreProperties(ignoreUnknown = true)
733742
public record CallToolResult( // @formatter:off
734743
@JsonProperty("content") List<Content> content,
735744
@JsonProperty("isError") Boolean isError) {
@@ -776,6 +785,7 @@ public enum ContextInclusionStrategy {
776785
}// @formatter:on
777786

778787
@JsonInclude(JsonInclude.Include.NON_ABSENT)
788+
@JsonIgnoreProperties(ignoreUnknown = true)
779789
public record CreateMessageResult(// @formatter:off
780790
@JsonProperty("role") Role role,
781791
@JsonProperty("content") Content content,
@@ -837,6 +847,7 @@ public record PaginatedRequest(@JsonProperty("cursor") String cursor) {
837847
}
838848

839849
@JsonInclude(JsonInclude.Include.NON_ABSENT)
850+
@JsonIgnoreProperties(ignoreUnknown = true)
840851
public record PaginatedResult(@JsonProperty("nextCursor") String nextCursor) {
841852
}
842853

@@ -1044,6 +1055,7 @@ public record Root( // @formatter:off
10441055
* that the server can operate on.
10451056
*/
10461057
@JsonInclude(JsonInclude.Include.NON_ABSENT)
1058+
@JsonIgnoreProperties(ignoreUnknown = true)
10471059
public record ListRootsResult( // @formatter:off
10481060
@JsonProperty("roots") List<Root> roots) {
10491061
} // @formatter:on

0 commit comments

Comments
 (0)