go-sdk/mcp/content_test.go
Rob Findley 8efb54691d internal/mcp/protocol: move out of mcp/internal, as it's used in the API
The generated protocol package is part of the SDK API, so it shouldn't
be internal.

Change-Id: I5306af48019b1599707b939b348eb6ae4f766ca9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/670356
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-05-06 10:18:38 -07:00

75 lines
1.6 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: "a1b2c3", MimeType: "image/png"},
protocol.Content{Type: "image", Data: "a1b2c3", MIMEType: "image/png"},
},
{
mcp.AudioContent{Data: "a1b2c3", MimeType: "audio/wav"},
protocol.Content{Type: "audio", Data: "a1b2c3", MIMEType: "audio/wav"},
},
{
mcp.ResourceContent{
Resource: mcp.TextResource{
URI: "file://foo",
MimeType: "text",
Text: "abc",
},
},
protocol.Content{
Type: "resource",
Resource: &protocol.Resource{
URI: "file://foo",
MIMEType: "text",
Text: "abc",
},
},
},
{
mcp.ResourceContent{
Resource: mcp.BlobResource{
URI: "file://foo",
MimeType: "text",
Blob: "a1b2c3",
},
},
protocol.Content{
Type: "resource",
Resource: &protocol.Resource{
URI: "file://foo",
MIMEType: "text",
Blob: ptr("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)
}
}
}
func ptr[T any](t T) *T {
return &t
}