feat: add AudioContent support to MCP schema (#243)
- Add AudioContent record class implementing Annotated and Content interfaces
- Update Content sealed interface to permit AudioContent
- Add audio type handling in Content.type() method
- Include AudioContent in JsonSubTypes annotation for polymorphic deserialization
- Add comprehensive tests for AudioContent serialization and deserialization
- Update error message test to include audio in known type ids
c87a0da6d8/schema/2025-03-26/schema.ts (L987-L1009)
This commit is contained in:
parent
b539b9889e
commit
9a63538840
1 changed files with 36 additions and 2 deletions
|
|
@ -59,7 +59,7 @@ public class McpSchemaTests {
|
|||
{"type":"WRONG","text":"XXX"}""", McpSchema.TextContent.class))
|
||||
.isInstanceOf(InvalidTypeIdException.class)
|
||||
.hasMessageContaining(
|
||||
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [image, resource, text]");
|
||||
"Could not resolve type id 'WRONG' as a subtype of `io.modelcontextprotocol.spec.McpSchema$TextContent`: known type ids = [audio, image, resource, text]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -84,6 +84,28 @@ public class McpSchemaTests {
|
|||
assertThat(imageContent.mimeType()).isEqualTo("image/png");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAudioContent() throws Exception {
|
||||
McpSchema.AudioContent audioContent = new McpSchema.AudioContent(null, "base64encodeddata", "audio/wav");
|
||||
String value = mapper.writeValueAsString(audioContent);
|
||||
|
||||
assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
|
||||
.when(Option.IGNORING_EXTRA_ARRAY_ITEMS)
|
||||
.isObject()
|
||||
.isEqualTo(json("""
|
||||
{"type":"audio","data":"base64encodeddata","mimeType":"audio/wav"}"""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAudioContentDeserialization() throws Exception {
|
||||
McpSchema.AudioContent audioContent = mapper.readValue("""
|
||||
{"type":"audio","data":"base64encodeddata","mimeType":"audio/wav"}""", McpSchema.AudioContent.class);
|
||||
assertThat(audioContent).isNotNull();
|
||||
assertThat(audioContent.type()).isEqualTo("audio");
|
||||
assertThat(audioContent.data()).isEqualTo("base64encodeddata");
|
||||
assertThat(audioContent.mimeType()).isEqualTo("audio/wav");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmbeddedResource() throws Exception {
|
||||
McpSchema.TextResourceContents resourceContents = new McpSchema.TextResourceContents("resource://test",
|
||||
|
|
|
|||
Loading…
Reference in a new issue