Add example servers for SEP-2053 variant patterns (#4)
Add four new example servers demonstrating different SEP-2053 variant patterns: - model-optimized (same tools, different descriptions per LLM family) - trading (API versioning with deprecation lifecycle) - research (context budget management) - Refactor the existing variants-http example into a GitHub-style server with custom ranking. Signed-off-by: Kurt Degiorgio <kdegiorgio@bloomberg.net>
This commit is contained in:
parent
c01fd188d2
commit
e1c17e047f
1 changed files with 1218 additions and 147 deletions
47
go/sdk/examples/server/variants-stdio/main.go
Normal file
47
go/sdk/examples/server/variants-stdio/main.go
Normal file
|
|
@ -0,0 +1,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)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue