internal/mcp: simplify prompt API

Remove NewServerPrompt.

Schema inference is irrelevant for prompts.
All arguments are strings.
So using a struct is not as valuable as with tools.
The only advantage is catching misspellings at compile time.
It's not worth it.

Change-Id: I45aaa5d55c8940cc9e32dc277bd543f79d932519
Reviewed-on: https://go-review.googlesource.com/c/tools/+/682797
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Jonathan Amsterdam 2025-06-19 02:40:37 -04:00 • committed by Robert Findley
commit a6ec3f5f4e

View file

@ -32,11 +32,11 @@ func SayHi(ctx context.Context, ss *mcp.ServerSession, params *mcp.CallToolParam
// TODO(jba): it should be OK for args to be a pointer, but this fails in
// jsonschema. Needs investigation.
func PromptHi(ctx context.Context, ss *mcp.ServerSession, args HiArgs, _ *mcp.GetPromptParams) (*mcp.GetPromptResult, error) {
func PromptHi(ctx context.Context, ss *mcp.ServerSession, params *mcp.GetPromptParams) (*mcp.GetPromptResult, error) {
return &mcp.GetPromptResult{
Description: "Code review prompt",
Messages: []*mcp.PromptMessage{
{Role: "user", Content: mcp.NewTextContent("Say hi to " + args.Name)},
{Role: "user", Content: mcp.NewTextContent("Say hi to " + params.Arguments["name"])},
},
}, nil
}
@ -48,7 +48,10 @@ func main() {
server.AddTools(mcp.NewServerTool("greet", "say hi", SayHi, mcp.Input(
mcp.Property("name", mcp.Description("the name to say hi to")),
)))
server.AddPrompts(mcp.NewServerPrompt("greet", "", PromptHi))
server.AddPrompts(&mcp.ServerPrompt{
Prompt: &mcp.Prompt{Name: "greet"},
Handler: PromptHi,
})
server.AddResources(&mcp.ServerResource{
Resource: &mcp.Resource{
Name: "info",