Skip to content

Commit 1441619

Browse files
committed
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).
1 parent 5aabc33 commit 1441619

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func main() {
7171
log.Fatal("tool failed")
7272
}
7373
for _, c := range res.Content {
74-
log.Print(c.Text)
74+
log.Print(c.(*mcp.TextContent).Text)
7575
}
7676
}
7777
```
@@ -95,14 +95,18 @@ type HiParams struct {
9595

9696
func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParamsFor[HiParams]) (*mcp.CallToolResultFor[any], error) {
9797
return &mcp.CallToolResultFor[any]{
98-
Content: []*mcp.ContentBlock{mcp.NewTextContent("Hi " + params.Name)},
98+
Content: []mcp.Content{&mcp.TextContent{Text: "Hi " + params.Name}},
9999
}, nil
100100
}
101101

102102
func main() {
103103
// Create a server with a single tool.
104104
server := mcp.NewServer("greeter", "v1.0.0", nil)
105-
server.AddTools(mcp.NewServerTool("greet", "say hi", SayHi))
105+
server.AddTools(
106+
mcp.NewServerTool("greet", "say hi", SayHi, mcp.Input(
107+
mcp.Property("name", mcp.Description("the name of the person to greet")),
108+
)),
109+
)
106110
// Run the server over stdin/stdout, until the client disconnects
107111
if err := server.Run(context.Background(), mcp.NewStdioTransport()); err != nil {
108112
log.Fatal(err)

internal/readme/server/server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ func SayHi(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParam
2525
func main() {
2626
// Create a server with a single tool.
2727
server := mcp.NewServer("greeter", "v1.0.0", nil)
28-
server.AddTools(mcp.NewServerTool("greet", "say hi", SayHi))
28+
server.AddTools(
29+
mcp.NewServerTool("greet", "say hi", SayHi, mcp.Input(
30+
mcp.Property("name", mcp.Description("the name of the person to greet")),
31+
)),
32+
)
2933
// Run the server over stdin/stdout, until the client disconnects
3034
if err := server.Run(context.Background(), mcp.NewStdioTransport()); err != nil {
3135
log.Fatal(err)

0 commit comments

Comments
 (0)