Bring the Server implementation up to date with the spec by renaming ServerConnection to ServerSession. Also update variable names, which were in various states of disarray from the multiple renamings of this type. Change-Id: I4aec883db6d0500fb91e6daa51b702614877cf8a Reviewed-on: https://go-review.googlesource.com/c/tools/+/672655 Auto-Submit: Robert Findley <rfindley@google.com> TryBot-Bypass: Robert Findley <rfindley@google.com> Commit-Queue: Robert Findley <rfindley@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
53 lines
1.4 KiB
Go
53 lines
1.4 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 (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// testPromptHandler is used for type inference in TestNewPrompt.
|
|
func testPromptHandler[T any](context.Context, *mcp.ServerSession, T) (*mcp.GetPromptResult, error) {
|
|
panic("not implemented")
|
|
}
|
|
|
|
func TestNewPrompt(t *testing.T) {
|
|
tests := []struct {
|
|
prompt *mcp.ServerPrompt
|
|
want []*mcp.PromptArgument
|
|
}{
|
|
{
|
|
mcp.NewPrompt("empty", "", testPromptHandler[struct{}]),
|
|
nil,
|
|
},
|
|
{
|
|
mcp.NewPrompt("add_arg", "", testPromptHandler[struct{}], mcp.Argument("x")),
|
|
[]*mcp.PromptArgument{{Name: "x"}},
|
|
},
|
|
{
|
|
mcp.NewPrompt("combo", "", testPromptHandler[struct {
|
|
Name string `json:"name"`
|
|
Country string `json:"country,omitempty"`
|
|
State string
|
|
}],
|
|
mcp.Argument("name", mcp.Description("the person's name")),
|
|
mcp.Argument("State", mcp.Required(false))),
|
|
[]*mcp.PromptArgument{
|
|
{Name: "State"},
|
|
{Name: "country"},
|
|
{Name: "name", Required: true, Description: "the person's name"},
|
|
},
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
if diff := cmp.Diff(test.want, test.prompt.Definition.Arguments); diff != "" {
|
|
t.Errorf("NewPrompt(%v) mismatch (-want +got):\n%s", test.prompt.Definition.Name, diff)
|
|
}
|
|
}
|
|
}
|