-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (57 loc) · 1.6 KB
/
Copy pathmain.go
File metadata and controls
64 lines (57 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"fmt"
"os"
"github.com/BackendStack21/go-mcp/gomcp"
)
func main() {
srv := gomcp.NewServer("greeter", "1.0.0")
// Tool: greet
srv.AddTool(gomcp.Tool{
Name: "greet",
Description: "Greet a person by name",
InputSchema: gomcp.InputSchema{
Type: "object",
Properties: map[string]gomcp.Property{
"name": {Type: "string", Description: "The name to greet"},
},
Required: []string{"name"},
},
Handler: func(ctx context.Context, args map[string]any) (string, error) {
name, ok := args["name"].(string)
if !ok {
return "", fmt.Errorf("name must be a string")
}
return fmt.Sprintf("Hello, %s!", name), nil
},
})
// Resource: greeting
srv.AddResource(gomcp.Resource{
URI: "greeting://world",
Name: "World Greeting",
Description: "A greeting for the world",
MimeType: "text/plain",
Handler: func(ctx context.Context) (string, error) {
return "Hello, World! 🌍", nil
},
})
// Prompt: polite-greeting
srv.AddPrompt(gomcp.Prompt{
Name: "polite-greeting",
Description: "A polite greeting prompt template",
Arguments: []gomcp.PromptArg{
{Name: "name", Description: "The name to greet", Required: true},
},
Handler: func(ctx context.Context, args map[string]any) ([]gomcp.PromptMessage, error) {
name := args["name"].(string)
return []gomcp.PromptMessage{
{Role: "user", Content: gomcp.NewTextContent("Please greet " + name + " in a friendly and polite manner.")},
}, nil
},
})
if err := srv.Run(); err != nil {
fmt.Fprintf(os.Stderr, "server error: %v\n", err)
os.Exit(1)
}
}