diff --git a/examples/client/listfeatures/main.go b/examples/client/listfeatures/main.go new file mode 100644 index 0000000..caf21bf --- /dev/null +++ b/examples/client/listfeatures/main.go @@ -0,0 +1,65 @@ +// Copyright 2025 The Go MCP SDK Authors. All rights reserved. +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file. + +// The listfeatures command lists all features of a stdio MCP server. +// +// Usage: listfeatures [] +// +// For example: +// +// listfeatures go run github.com/modelcontextprotocol/go-sdk/examples/server/hello +// +// or +// +// listfeatures npx @modelcontextprotocol/server-everything +package main + +import ( + "context" + "flag" + "fmt" + "iter" + "log" + "os" + "os/exec" + + "github.com/modelcontextprotocol/go-sdk/mcp" +) + +func main() { + flag.Parse() + args := flag.Args() + if len(args) == 0 { + fmt.Fprintf(os.Stderr, "Usage: listfeatures []") + fmt.Fprintf(os.Stderr, "List all features for a stdio MCP server") + fmt.Fprintln(os.Stderr) + fmt.Fprintf(os.Stderr, "Example: listfeatures npx @modelcontextprotocol/server-everything") + os.Exit(2) + } + + ctx := context.Background() + cmd := exec.Command(args[0], args[1:]...) + client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil) + cs, err := client.Connect(ctx, mcp.NewCommandTransport(cmd)) + if err != nil { + log.Fatal(err) + } + defer cs.Close() + + printSection("tools", cs.Tools(ctx, nil), func(t *mcp.Tool) string { return t.Name }) + printSection("resources", cs.Resources(ctx, nil), func(r *mcp.Resource) string { return r.Name }) + printSection("resource templates", cs.ResourceTemplates(ctx, nil), func(r *mcp.ResourceTemplate) string { return r.Name }) + printSection("prompts", cs.Prompts(ctx, nil), func(p *mcp.Prompt) string { return p.Name }) +} + +func printSection[T any](name string, features iter.Seq2[T, error], featName func(T) string) { + fmt.Printf("%s:\n", name) + for feat, err := range features { + if err != nil { + log.Fatal(err) + } + fmt.Printf("\t%s\n", featName(feat)) + } + fmt.Println() +} diff --git a/examples/completion/main.go b/examples/server/completion/main.go similarity index 100% rename from examples/completion/main.go rename to examples/server/completion/main.go diff --git a/examples/custom-transport/main.go b/examples/server/custom-transport/main.go similarity index 100% rename from examples/custom-transport/main.go rename to examples/server/custom-transport/main.go diff --git a/examples/hello/main.go b/examples/server/hello/main.go similarity index 100% rename from examples/hello/main.go rename to examples/server/hello/main.go diff --git a/examples/memory/kb.go b/examples/server/memory/kb.go similarity index 100% rename from examples/memory/kb.go rename to examples/server/memory/kb.go diff --git a/examples/memory/kb_test.go b/examples/server/memory/kb_test.go similarity index 100% rename from examples/memory/kb_test.go rename to examples/server/memory/kb_test.go diff --git a/examples/memory/main.go b/examples/server/memory/main.go similarity index 100% rename from examples/memory/main.go rename to examples/server/memory/main.go diff --git a/examples/rate-limiting/go.mod b/examples/server/rate-limiting/go.mod similarity index 100% rename from examples/rate-limiting/go.mod rename to examples/server/rate-limiting/go.mod diff --git a/examples/rate-limiting/go.sum b/examples/server/rate-limiting/go.sum similarity index 100% rename from examples/rate-limiting/go.sum rename to examples/server/rate-limiting/go.sum diff --git a/examples/rate-limiting/main.go b/examples/server/rate-limiting/main.go similarity index 100% rename from examples/rate-limiting/main.go rename to examples/server/rate-limiting/main.go diff --git a/examples/sequentialthinking/README.md b/examples/server/sequentialthinking/README.md similarity index 100% rename from examples/sequentialthinking/README.md rename to examples/server/sequentialthinking/README.md diff --git a/examples/sequentialthinking/main.go b/examples/server/sequentialthinking/main.go similarity index 100% rename from examples/sequentialthinking/main.go rename to examples/server/sequentialthinking/main.go diff --git a/examples/sequentialthinking/main_test.go b/examples/server/sequentialthinking/main_test.go similarity index 100% rename from examples/sequentialthinking/main_test.go rename to examples/server/sequentialthinking/main_test.go diff --git a/examples/sse/main.go b/examples/server/sse/main.go similarity index 100% rename from examples/sse/main.go rename to examples/server/sse/main.go