()
| 32 | ) |
| 33 | |
| 34 | func main() { |
| 35 | flag.Parse() |
| 36 | args := flag.Args() |
| 37 | if len(args) == 0 && *endpoint == "" { |
| 38 | fmt.Fprintln(os.Stderr, "Usage: listfeatures <command> [<args>]") |
| 39 | fmt.Fprintln(os.Stderr, "Usage: listfeatures --http=\"https://example.com/server/mcp\"") |
| 40 | fmt.Fprintln(os.Stderr, "List all features for a stdio MCP server") |
| 41 | fmt.Fprintln(os.Stderr) |
| 42 | fmt.Fprintln(os.Stderr, "Example:\n\tlistfeatures go run github.com/modelcontextprotocol/go-sdk/examples/server/hello") |
| 43 | os.Exit(2) |
| 44 | } |
| 45 | |
| 46 | var ( |
| 47 | ctx = context.Background() |
| 48 | transport mcp.Transport |
| 49 | ) |
| 50 | if *endpoint != "" { |
| 51 | transport = &mcp.StreamableClientTransport{ |
| 52 | Endpoint: *endpoint, |
| 53 | } |
| 54 | } else { |
| 55 | cmd := exec.Command(args[0], args[1:]...) |
| 56 | transport = &mcp.CommandTransport{Command: cmd} |
| 57 | } |
| 58 | client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil) |
| 59 | cs, err := client.Connect(ctx, transport, nil) |
| 60 | if err != nil { |
| 61 | log.Fatal(err) |
| 62 | } |
| 63 | defer cs.Close() |
| 64 | |
| 65 | if cs.InitializeResult().Capabilities.Tools != nil { |
| 66 | printSection("tools", cs.Tools(ctx, nil), func(t *mcp.Tool) string { return t.Name }) |
| 67 | } |
| 68 | if cs.InitializeResult().Capabilities.Resources != nil { |
| 69 | printSection("resources", cs.Resources(ctx, nil), func(r *mcp.Resource) string { return r.Name }) |
| 70 | printSection("resource templates", cs.ResourceTemplates(ctx, nil), func(r *mcp.ResourceTemplate) string { return r.Name }) |
| 71 | } |
| 72 | if cs.InitializeResult().Capabilities.Prompts != nil { |
| 73 | printSection("prompts", cs.Prompts(ctx, nil), func(p *mcp.Prompt) string { return p.Name }) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func printSection[T any](name string, features iter.Seq2[T, error], featName func(T) string) { |
| 78 | fmt.Printf("%s:\n", name) |
nothing calls this directly
no test coverage detected
searching dependent graphs…