Debian Codegraph @

debian/go/src/github.com/modelcontextprotocol/go-sdk/internal/readme/server/server.go

raw symbols SCIP
1 // Copyright 2025 The Go MCP SDK Authors. All rights reserved.
2 // Use of this source code is governed by an MIT-style
3 // license that can be found in the LICENSE file.
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 // Create a server with a single tool.
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 // Run the server over stdin/stdout, until the client disconnects.
36 if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
37 log.Fatal(err)
38 }
39 }
40
41 // !-