| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package main |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"log" |
| 11 |
|
| 12 |
"github.com/modelcontextprotocol/go-sdk/mcp" |
| 13 |
) |
| 14 |
|
| 15 |
type Input struct { |
| 16 |
Name string `json:"name" jsonschema:"the name of the person to greet"` |
| 17 |
} |
| 18 |
|
| 19 |
type Output struct { |
| 20 |
Greeting string `json:"greeting" jsonschema:"the greeting to tell to the user"` |
| 21 |
} |
| 22 |
|
| 23 |
func SayHi(ctx context.Context, req *mcp.CallToolRequest, input Input) ( |
| 24 |
*mcp.CallToolResult, |
| 25 |
Output, |
| 26 |
error, |
| 27 |
) { |
| 28 |
return nil, Output{Greeting: "Hi " + input.Name}, nil |
| 29 |
} |
| 30 |
|
| 31 |
func main() { |
| 32 |
|
| 33 |
server := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v1.0.0"}, nil) |
| 34 |
mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi) |
| 35 |
|
| 36 |
if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil { |
| 37 |
log.Fatal(err) |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|