go-sdk/mcp/content_test.go
Jonathan Amsterdam 71265ba130 internal/mcp: adjust content types
- Change the names of some content-related types to better match
  the spec. Most notably, rename Resource to EmbeddedResource,
  because the former has a different meaning in the spec.

- Use []byte intead of string where the spec says "base64-encoded data."

- Unexport EmbeddedResource.ToWire.

Change-Id: I9f65efaadadda1b3abc0e58c64a743af1a72852c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/671362
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Bypass: Jonathan Amsterdam <jba@google.com>
Commit-Queue: Jonathan Amsterdam <jba@google.com>
2025-05-13 08:21:01 -07:00

71 lines
1.7 KiB
Go

// Copyright 2025 The Go MCP SDK Authors. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package mcp_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/modelcontextprotocol/go-sdk/mcp/protocol"
)
func TestContent(t *testing.T) {
tests := []struct {
in mcp.Content
want protocol.Content
}{
{mcp.TextContent{Text: "hello"}, protocol.Content{Type: "text", Text: "hello"}},
{
mcp.ImageContent{Data: []byte("a1b2c3"), MIMEType: "image/png"},
protocol.Content{Type: "image", Data: []byte("a1b2c3"), MIMEType: "image/png"},
},
{
mcp.AudioContent{Data: []byte("a1b2c3"), MIMEType: "audio/wav"},
protocol.Content{Type: "audio", Data: []byte("a1b2c3"), MIMEType: "audio/wav"},
},
{
mcp.ResourceContent{
Resource: mcp.TextResourceContents{
URI: "file://foo",
MIMEType: "text",
Text: "abc",
},
},
protocol.Content{
Type: "resource",
Resource: &protocol.ResourceContents{
URI: "file://foo",
MIMEType: "text",
Text: "abc",
},
},
},
{
mcp.ResourceContent{
Resource: mcp.BlobResourceContents{
URI: "file://foo",
MIMEType: "text",
Blob: []byte("a1b2c3"),
},
},
protocol.Content{
Type: "resource",
Resource: &protocol.ResourceContents{
URI: "file://foo",
MIMEType: "text",
Blob: []byte("a1b2c3"),
},
},
},
}
for _, test := range tests {
got := test.in.ToWire()
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("ToWire mismatch (-want +got):\n%s", diff)
}
}
}