internal/mcp: support prompts
Add support for 'prompts/list' and 'prompts/get', and registering prompts on the server using AddPrompts. Add a 'MakePrompt' helper to construct prompts from a prompt handler using reflection. Change-Id: I479cb9c9b99313cca99640c1f5ea1939363759e6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/669015 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
parent
e082a340be
commit
af4d138732
1 changed files with 531 additions and 98 deletions
54
mcp/prompt_test.go
Normal file
54
mcp/prompt_test.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// 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"
|
||||
"github.com/modelcontextprotocol/go-sdk/internal/protocol"
|
||||
)
|
||||
|
||||
// testPromptHandler is used for type inference in TestMakePrompt.
|
||||
func testPromptHandler[T any](context.Context, *mcp.ClientConnection, T) (*protocol.GetPromptResult, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func TestMakePrompt(t *testing.T) {
|
||||
tests := []struct {
|
||||
prompt *mcp.Prompt
|
||||
want []protocol.PromptArgument
|
||||
}{
|
||||
{
|
||||
mcp.MakePrompt("empty", "", testPromptHandler[struct{}]),
|
||||
nil,
|
||||
},
|
||||
{
|
||||
mcp.MakePrompt("add_arg", "", testPromptHandler[struct{}], mcp.Argument("x")),
|
||||
[]protocol.PromptArgument{{Name: "x"}},
|
||||
},
|
||||
{
|
||||
mcp.MakePrompt("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))),
|
||||
[]protocol.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("MakePrompt(%v) mismatch (-want +got):\n%s", test.prompt.Definition.Name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue