mcp: don't omit required fields in ImageContent and AudioContent (#95)

Update `ImageContent` and `AudioContent` to use an inline wire format
to ensure that required fields are not omitted during JSON marshaling,
matching TypeScript schema requirements. This follows the TextContent
approach.

- `ImageContent` requires `data` and `mimeType` fields.
- `AudioContent` requires `data` and `mimeType` fields.
This commit is contained in:
Martin Emde 2025-07-19 14:08:56 -07:00 • committed by GitHub
commit dced3e4503
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,6 +45,14 @@ func TestContent(t *testing.T) {
},
`{"type":"image","mimeType":"image/png","data":"YTFiMmMz"}`,
},
{
&mcp.ImageContent{MIMEType: "image/png", Data: []byte{}},
`{"type":"image","mimeType":"image/png","data":""}`,
},
{
&mcp.ImageContent{Data: []byte("test")},
`{"type":"image","mimeType":"","data":"dGVzdA=="}`,
},
{
&mcp.ImageContent{
Data: []byte("a1b2c3"),
@ -61,6 +69,14 @@ func TestContent(t *testing.T) {
},
`{"type":"audio","mimeType":"audio/wav","data":"YTFiMmMz"}`,
},
{
&mcp.AudioContent{MIMEType: "audio/wav", Data: []byte{}},
`{"type":"audio","mimeType":"audio/wav","data":""}`,
},
{
&mcp.AudioContent{Data: []byte("test")},
`{"type":"audio","mimeType":"","data":"dGVzdA=="}`,
},
{
&mcp.AudioContent{
Data: []byte("a1b2c3"),