|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "sort" |
| 6 | + |
| 7 | + "github.com/github/github-mcp-server/pkg/github" |
| 8 | + "github.com/github/github-mcp-server/pkg/translations" |
| 9 | + "github.com/spf13/cobra" |
| 10 | + "github.com/spf13/viper" |
| 11 | +) |
| 12 | + |
| 13 | +var listToolsPocCmd = &cobra.Command{ |
| 14 | + Use: "list-tools", |
| 15 | + Short: "List available MCP tools grouped by toolset", |
| 16 | + Long: `Display all registered MCP tools, grouped by toolset.`, |
| 17 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 18 | + fmt.Println("TODO: Implement list-tools functionality") |
| 19 | + fmt.Println("This is a proof of concept for the list-tools command.") |
| 20 | + fmt.Println("Would display all available MCP tools grouped by toolset.") |
| 21 | + return nil |
| 22 | + }, |
| 23 | +} |
| 24 | + |
| 25 | +func init() { |
| 26 | + rootCmd.AddCommand(listToolsPocCmd) |
| 27 | +} |
| 28 | + |
| 29 | +// TODO: Add filtering by toolset (e.g., --toolset=repos) |
| 30 | +// TODO: Support output formats (e.g., --format=json, yaml, table) |
| 31 | +// TODO: Respect active toolsets, dynamic toolsets, and read-only flags |
| 32 | +// TODO: Add unit tests once design is confirmed useful |
| 33 | + |
| 34 | +func listTools() error { |
| 35 | + // Get configuration from viper |
| 36 | + var enabledToolsets []string |
| 37 | + if err := viper.UnmarshalKey("toolsets", &enabledToolsets); err != nil { |
| 38 | + return fmt.Errorf("failed to unmarshal toolsets: %w", err) |
| 39 | + } |
| 40 | + |
| 41 | + readOnly := viper.GetBool("read-only") |
| 42 | + |
| 43 | + // Create translation helper |
| 44 | + t, _ := translations.TranslationHelper() |
| 45 | + |
| 46 | + // Create toolset group with mock clients |
| 47 | + tsg := github.DefaultToolsetGroup(readOnly, mockGetClient, mockGetGQLClient, mockGetRawClient, t) |
| 48 | + |
| 49 | + // Enable specified toolsets |
| 50 | + if err := tsg.EnableToolsets(enabledToolsets); err != nil { |
| 51 | + return fmt.Errorf("failed to enable toolsets: %w", err) |
| 52 | + } |
| 53 | + |
| 54 | + // Get sorted toolset names |
| 55 | + var toolsetNames []string |
| 56 | + for name := range tsg.Toolsets { |
| 57 | + toolsetNames = append(toolsetNames, name) |
| 58 | + } |
| 59 | + sort.Strings(toolsetNames) |
| 60 | + |
| 61 | + for _, toolsetName := range toolsetNames { |
| 62 | + toolset := tsg.Toolsets[toolsetName] |
| 63 | + |
| 64 | + // Skip if toolset is not enabled |
| 65 | + if !toolset.Enabled { |
| 66 | + continue |
| 67 | + } |
| 68 | + |
| 69 | + fmt.Printf("\nToolset: %s\n", toolsetName) |
| 70 | + fmt.Printf("Description: %s\n", toolset.Description) |
| 71 | + fmt.Println() |
| 72 | + |
| 73 | + tools := toolset.GetActiveTools() |
| 74 | + if len(tools) == 0 { |
| 75 | + fmt.Println(" No tools available") |
| 76 | + continue |
| 77 | + } |
| 78 | + |
| 79 | + // Sort tools by name |
| 80 | + sort.Slice(tools, func(i, j int) bool { |
| 81 | + return tools[i].Tool.Name < tools[j].Tool.Name |
| 82 | + }) |
| 83 | + |
| 84 | + for _, serverTool := range tools { |
| 85 | + tool := serverTool.Tool |
| 86 | + fmt.Printf("- %s: %s\n", tool.Name, tool.Description) |
| 87 | + } |
| 88 | + fmt.Println() |
| 89 | + } |
| 90 | + |
| 91 | + return nil |
| 92 | +} |
0 commit comments