-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (38 loc) · 1.23 KB
/
main.go
File metadata and controls
47 lines (38 loc) · 1.23 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
// Example: Minimal variant-aware MCP server over stdio. Registers a single
// variant with one tool to demonstrate the simplest possible setup.
//
// Run over stdio:
//
// go run ./examples/server/variants-stdio
package main
import (
"context"
"log"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/modelcontextprotocol/experimental-ext-variants/go/sdk/variants"
)
type GreetInput struct {
Name string `json:"name" jsonschema:"name to greet"`
}
type GreetOutput struct {
Message string `json:"message"`
}
func greet(_ context.Context, _ *mcp.CallToolRequest, in GreetInput) (*mcp.CallToolResult, GreetOutput, error) {
return nil, GreetOutput{Message: "Hello, " + in.Name + "!"}, nil
}
func main() {
inner := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v1.0.0"}, nil)
mcp.AddTool(inner, &mcp.Tool{
Name: "greet",
Description: "Greet someone by name",
}, greet)
vs := variants.NewServer(&mcp.Implementation{Name: "greeter", Version: "v1.0.0"}).
WithVariant(variants.ServerVariant{
ID: "default",
Description: "Default greeting variant.",
Status: variants.Stable,
}, inner, 0)
if err := vs.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
log.Fatal(err)
}
}