@@ -40,36 +40,36 @@ stdin/stdout:
4040package main
4141
4242import (
43- " context"
44- " log"
43+ " context"
44+ " log"
4545
46- " github.com/modelcontextprotocol/go-sdk/mcp"
46+ " github.com/modelcontextprotocol/go-sdk/mcp"
4747)
4848
4949type Input struct {
50- Name string ` json:"name" jsonschema:"the name of the person to greet"`
50+ Name string ` json:"name" jsonschema:"the name of the person to greet"`
5151}
5252
5353type Output struct {
54- Greeting string ` json:"greeting" jsonschema:"the greeting to tell to the user"`
54+ Greeting string ` json:"greeting" jsonschema:"the greeting to tell to the user"`
5555}
5656
5757func SayHi (ctx context .Context , req *mcp .CallToolRequest , input Input ) (
58- *mcp.CallToolResult,
59- Output,
60- error,
58+ *mcp.CallToolResult,
59+ Output,
60+ error,
6161) {
62- return nil , Output{Greeting: " Hi " + input.Name }, nil
62+ return nil , Output{Greeting: " Hi " + input.Name }, nil
6363}
6464
6565func main () {
66- // Create a server with a single tool.
67- server := mcp.NewServer (&mcp.Implementation {Name: " greeter" , Version: " v1.0.0" }, nil )
68- mcp.AddTool (server, &mcp.Tool {Name: " greet" , Description: " say hi" }, SayHi)
69- // Run the server over stdin/stdout, until the client disconnects.
70- if err := server.Run (context.Background (), &mcp.StdioTransport {}); err != nil {
71- log.Fatal (err)
72- }
66+ // Create a server with a single tool.
67+ server := mcp.NewServer (&mcp.Implementation {Name: " greeter" , Version: " v1.0.0" }, nil )
68+ mcp.AddTool (server, &mcp.Tool {Name: " greet" , Description: " say hi" }, SayHi)
69+ // Run the server over stdin/stdout, until the client disconnects.
70+ if err := server.Run (context.Background (), &mcp.StdioTransport {}); err != nil {
71+ log.Fatal (err)
72+ }
7373}
7474```
7575
@@ -81,42 +81,42 @@ stdin/stdout:
8181package main
8282
8383import (
84- " context"
85- " log"
86- " os/exec"
84+ " context"
85+ " log"
86+ " os/exec"
8787
88- " github.com/modelcontextprotocol/go-sdk/mcp"
88+ " github.com/modelcontextprotocol/go-sdk/mcp"
8989)
9090
9191func main () {
92- ctx := context.Background ()
93-
94- // Create a new client, with no features.
95- client := mcp.NewClient (&mcp.Implementation {Name: " mcp-client" , Version: " v1.0.0" }, nil )
96-
97- // Connect to a server over stdin/stdout.
98- transport := &mcp.CommandTransport {Command: exec.Command (" myserver" )}
99- session , err := client.Connect (ctx, transport, nil )
100- if err != nil {
101- log.Fatal (err)
102- }
103- defer session.Close ()
104-
105- // Call a tool on the server.
106- params := &mcp.CallToolParams {
107- Name: " greet" ,
108- Arguments: map [string ]any{" name" : " you" },
109- }
110- res , err := session.CallTool (ctx, params)
111- if err != nil {
112- log.Fatalf (" CallTool failed: %v " , err)
113- }
114- if res.IsError {
115- log.Fatal (" tool failed" )
116- }
117- for _ , c := range res.Content {
118- log.Print (c.(*mcp.TextContent ).Text )
119- }
92+ ctx := context.Background ()
93+
94+ // Create a new client, with no features.
95+ client := mcp.NewClient (&mcp.Implementation {Name: " mcp-client" , Version: " v1.0.0" }, nil )
96+
97+ // Connect to a server over stdin/stdout.
98+ transport := &mcp.CommandTransport {Command: exec.Command (" myserver" )}
99+ session , err := client.Connect (ctx, transport, nil )
100+ if err != nil {
101+ log.Fatal (err)
102+ }
103+ defer session.Close ()
104+
105+ // Call a tool on the server.
106+ params := &mcp.CallToolParams {
107+ Name: " greet" ,
108+ Arguments: map [string ]any{" name" : " you" },
109+ }
110+ res , err := session.CallTool (ctx, params)
111+ if err != nil {
112+ log.Fatalf (" CallTool failed: %v " , err)
113+ }
114+ if res.IsError {
115+ log.Fatal (" tool failed" )
116+ }
117+ for _ , c := range res.Content {
118+ log.Print (c.(*mcp.TextContent ).Text )
119+ }
120120}
121121```
122122
0 commit comments