From 14416198ed8cd13a0f5bc019610567cab6a9ce9d Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Wed, 25 Jun 2025 18:51:27 +0000 Subject: [PATCH] README.md: add description to tool input It is unrealistic to demonstrate a tool that doesn't use descriptions (and makes the API look too clean). --- README.md | 10 +++++++--- internal/readme/server/server.go | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 504eccc6..e60947cc 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ func main() { log.Fatal("tool failed") } for _, c := range res.Content { - log.Print(c.Text) + log.Print(c.(*mcp.TextContent).Text) } } ``` @@ -95,14 +95,18 @@ type HiParams struct { func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParamsFor[HiParams]) (*mcp.CallToolResultFor[any], error) { return &mcp.CallToolResultFor[any]{ - Content: []*mcp.ContentBlock{mcp.NewTextContent("Hi " + params.Name)}, + Content: []mcp.Content{&mcp.TextContent{Text: "Hi " + params.Name}}, }, nil } func main() { // Create a server with a single tool. server := mcp.NewServer("greeter", "v1.0.0", nil) - server.AddTools(mcp.NewServerTool("greet", "say hi", SayHi)) + server.AddTools( + mcp.NewServerTool("greet", "say hi", SayHi, mcp.Input( + mcp.Property("name", mcp.Description("the name of the person to greet")), + )), + ) // Run the server over stdin/stdout, until the client disconnects if err := server.Run(context.Background(), mcp.NewStdioTransport()); err != nil { log.Fatal(err) diff --git a/internal/readme/server/server.go b/internal/readme/server/server.go index b709cd75..177cf8fa 100644 --- a/internal/readme/server/server.go +++ b/internal/readme/server/server.go @@ -25,7 +25,11 @@ func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParam func main() { // Create a server with a single tool. server := mcp.NewServer("greeter", "v1.0.0", nil) - server.AddTools(mcp.NewServerTool("greet", "say hi", SayHi)) + server.AddTools( + mcp.NewServerTool("greet", "say hi", SayHi, mcp.Input( + mcp.Property("name", mcp.Description("the name of the person to greet")), + )), + ) // Run the server over stdin/stdout, until the client disconnects if err := server.Run(context.Background(), mcp.NewStdioTransport()); err != nil { log.Fatal(err)