Skip to content

Commit 862022a

Browse files
committed
refactor(mcp): remove redundant type field from Content implementations
- The type field and associated methods were redundant in Content implementations (TextContent, ImageContent, EmbeddedResource) as the type information is already handled by Jackson's polymorphic type handling via @JsonSubTypes annotation. - Added comprehensive unit tests for McpSchema to validate serialization/deserialization behavior of all schema components. Resolves #26 Resolve spring-projects/spring-ai#2350 Signed-off-by: Christian Tzolov <[email protected]>
1 parent b2c62d5 commit 862022a

File tree

2 files changed

+461
-29
lines changed

2 files changed

+461
-29
lines changed

Diff for: mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java

+3-29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12+
import com.fasterxml.jackson.annotation.JsonIgnore;
1213
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
1314
import com.fasterxml.jackson.annotation.JsonInclude;
1415
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -964,61 +965,34 @@ public record CompleteCompletion(// @formatter:off
964965
@JsonSubTypes.Type(value = EmbeddedResource.class, name = "resource") })
965966
public sealed interface Content permits TextContent, ImageContent, EmbeddedResource {
966967

967-
String type();
968+
// String type();
968969

969970
}
970971

971972
@JsonInclude(JsonInclude.Include.NON_ABSENT)
972973
public record TextContent( // @formatter:off
973974
@JsonProperty("audience") List<Role> audience,
974975
@JsonProperty("priority") Double priority,
975-
@JsonProperty("type") String type,
976976
@JsonProperty("text") String text) implements Content { // @formatter:on
977977

978-
public TextContent {
979-
type = "text";
980-
}
981-
982-
public String type() {
983-
return type;
984-
}
985-
986978
public TextContent(String content) {
987-
this(null, null, "text", content);
979+
this(null, null, content);
988980
}
989981
}
990982

991983
@JsonInclude(JsonInclude.Include.NON_ABSENT)
992984
public record ImageContent( // @formatter:off
993985
@JsonProperty("audience") List<Role> audience,
994986
@JsonProperty("priority") Double priority,
995-
@JsonProperty("type") String type,
996987
@JsonProperty("data") String data,
997988
@JsonProperty("mimeType") String mimeType) implements Content { // @formatter:on
998-
999-
public ImageContent {
1000-
type = "image";
1001-
}
1002-
1003-
public String type() {
1004-
return type;
1005-
}
1006989
}
1007990

1008991
@JsonInclude(JsonInclude.Include.NON_ABSENT)
1009992
public record EmbeddedResource( // @formatter:off
1010993
@JsonProperty("audience") List<Role> audience,
1011994
@JsonProperty("priority") Double priority,
1012-
@JsonProperty("type") String type,
1013995
@JsonProperty("resource") ResourceContents resource) implements Content { // @formatter:on
1014-
1015-
public EmbeddedResource {
1016-
type = "resource";
1017-
}
1018-
1019-
public String type() {
1020-
return type;
1021-
}
1022996
}
1023997

1024998
// ---------------------------

0 commit comments

Comments
 (0)