Skip to content

Commit 9e858f1

Browse files
committed
add AudioContent to McpSchema
Signed-off-by: jitokim <[email protected]>
1 parent 41c6bd9 commit 9e858f1

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,9 @@ public record CompleteCompletion(
12541254
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
12551255
@JsonSubTypes({ @JsonSubTypes.Type(value = TextContent.class, name = "text"),
12561256
@JsonSubTypes.Type(value = ImageContent.class, name = "image"),
1257+
@JsonSubTypes.Type(value = AudioContent.class, name = "audio"),
12571258
@JsonSubTypes.Type(value = EmbeddedResource.class, name = "resource") })
1258-
public sealed interface Content permits TextContent, ImageContent, EmbeddedResource {
1259+
public sealed interface Content permits TextContent, ImageContent, AudioContent, EmbeddedResource {
12591260

12601261
default String type() {
12611262
if (this instanceof TextContent) {
@@ -1264,6 +1265,9 @@ default String type() {
12641265
else if (this instanceof ImageContent) {
12651266
return "image";
12661267
}
1268+
else if (this instanceof AudioContent) {
1269+
return "audio";
1270+
}
12671271
else if (this instanceof EmbeddedResource) {
12681272
return "resource";
12691273
}
@@ -1293,6 +1297,15 @@ public record ImageContent( // @formatter:off
12931297
@JsonProperty("mimeType") String mimeType) implements Content { // @formatter:on
12941298
}
12951299

1300+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
1301+
@JsonIgnoreProperties(ignoreUnknown = true)
1302+
public record AudioContent( // @formatter:off
1303+
@JsonProperty("audience") List<Role> audience,
1304+
@JsonProperty("priority") Double priority,
1305+
@JsonProperty("data") String data,
1306+
@JsonProperty("mimeType") String mimeType) implements Content { // @formatter:on
1307+
}
1308+
12961309
@JsonInclude(JsonInclude.Include.NON_ABSENT)
12971310
@JsonIgnoreProperties(ignoreUnknown = true)
12981311
public record EmbeddedResource( // @formatter:off

mcp/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java

+41-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void testContentDeserializationWrongType() throws Exception {
5858
{"type":"WRONG","text":"XXX"}""", McpSchema.TextContent.class))
5959
.isInstanceOf(InvalidTypeIdException.class)
6060
.hasMessageContaining(
61-
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [image, resource, text]");
61+
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [audio, image, resource, text]");
6262
}
6363

6464
@Test
@@ -83,6 +83,46 @@ void testImageContentDeserialization() throws Exception {
8383
assertThat(imageContent.mimeType()).isEqualTo("image/png");
8484
}
8585

86+
@Test
87+
void testAudioContent() throws Exception {
88+
McpSchema.AudioContent test = new McpSchema.AudioContent(List.of(McpSchema.Role.USER), 0.8, "base64audiodata",
89+
"audio/mp3");
90+
91+
String value = mapper.writeValueAsString(test);
92+
93+
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
94+
.when(Option.IGNORING_EXTRA_ARRAY_ITEMS)
95+
.isObject()
96+
.isEqualTo(json("""
97+
{
98+
"type":"audio",
99+
"audience": ["user"],
100+
"priority": 0.8,
101+
"data": "base64audiodata",
102+
"mimeType": "audio/mp3"
103+
}"""));
104+
}
105+
106+
@Test
107+
void testAudioContentDeserialization() throws Exception {
108+
String json = """
109+
{
110+
"type":"audio",
111+
"audience": ["user"],
112+
"priority": 0.8,
113+
"data": "base64audiodata",
114+
"mimeType": "audio/mp3"
115+
}""";
116+
117+
McpSchema.AudioContent audioContent = mapper.readValue(json, McpSchema.AudioContent.class);
118+
119+
assertThat(audioContent).isNotNull();
120+
assertThat(audioContent.audience()).containsExactly(McpSchema.Role.USER);
121+
assertThat(audioContent.priority()).isEqualTo(0.8);
122+
assertThat(audioContent.data()).isEqualTo("base64audiodata");
123+
assertThat(audioContent.mimeType()).isEqualTo("audio/mp3");
124+
}
125+
86126
@Test
87127
void testEmbeddedResource() throws Exception {
88128
McpSchema.TextResourceContents resourceContents = new McpSchema.TextResourceContents("resource://test",

0 commit comments

Comments
 (0)