|
| 1 | +package commands |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | + |
| 8 | + workingset "github.com/docker/mcp-gateway/cmd/docker-mcp/working-set" |
| 9 | +) |
| 10 | + |
| 11 | +func workingSetCommand() *cobra.Command { |
| 12 | + cmd := &cobra.Command{ |
| 13 | + Use: "working-set", |
| 14 | + Aliases: []string{"ws"}, |
| 15 | + Short: "Manage MCP server working-sets", |
| 16 | + Long: `Manage working-sets of MCP servers for organizing and grouping servers together.`, |
| 17 | + } |
| 18 | + cmd.AddCommand(createWorkingSetCommand()) |
| 19 | + cmd.AddCommand(listWorkingSetCommand()) |
| 20 | + cmd.AddCommand(showWorkingSetCommand()) |
| 21 | + return cmd |
| 22 | +} |
| 23 | + |
| 24 | +func createWorkingSetCommand() *cobra.Command { |
| 25 | + var opts struct { |
| 26 | + Name string |
| 27 | + Description string |
| 28 | + Servers []string |
| 29 | + } |
| 30 | + cmd := &cobra.Command{ |
| 31 | + Use: "create --name <name> [--description <description>] --server <server1> --server <server2> ...", |
| 32 | + Short: "Create a new working-set of MCP servers", |
| 33 | + Long: `Create a new working-set that groups multiple MCP servers together. |
| 34 | +A working-set allows you to organize and manage related servers as a single unit.`, |
| 35 | + Example: ` # Create a working-set with multiple servers |
| 36 | + docker mcp working-set create --name dev-tools --description "Development tools" --server github --server slack |
| 37 | +
|
| 38 | + # Create a working-set with a single server |
| 39 | + docker mcp working-set create --name docker-only --server docker`, |
| 40 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 41 | + return workingset.Create(opts.Name, opts.Description, opts.Servers) |
| 42 | + }, |
| 43 | + } |
| 44 | + flags := cmd.Flags() |
| 45 | + flags.StringVar(&opts.Name, "name", "", "Name of the working-set (required)") |
| 46 | + flags.StringVar(&opts.Description, "description", "", "Description of the working-set") |
| 47 | + flags.StringArrayVar(&opts.Servers, "server", []string{}, "Server to include in the working-set (can be specified multiple times)") |
| 48 | + |
| 49 | + _ = cmd.MarkFlagRequired("name") |
| 50 | + _ = cmd.MarkFlagRequired("server") |
| 51 | + |
| 52 | + return cmd |
| 53 | +} |
| 54 | + |
| 55 | +func listWorkingSetCommand() *cobra.Command { |
| 56 | + var opts struct { |
| 57 | + Format workingset.Format |
| 58 | + } |
| 59 | + cmd := &cobra.Command{ |
| 60 | + Use: "ls", |
| 61 | + Aliases: []string{"list"}, |
| 62 | + Short: "List all working-sets", |
| 63 | + Long: `List all configured working-sets and their associated servers.`, |
| 64 | + Example: ` # List all working-sets in human-readable format |
| 65 | + docker mcp working-set ls |
| 66 | +
|
| 67 | + # List working-sets in JSON format |
| 68 | + docker mcp working-set ls --format json |
| 69 | +
|
| 70 | + # List working-sets in YAML format |
| 71 | + docker mcp working-set ls --format yaml`, |
| 72 | + Args: cobra.NoArgs, |
| 73 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 74 | + return workingset.List(opts.Format) |
| 75 | + }, |
| 76 | + } |
| 77 | + flags := cmd.Flags() |
| 78 | + flags.Var(&opts.Format, "format", fmt.Sprintf("Output format. Supported: %s.", workingset.SupportedFormats())) |
| 79 | + return cmd |
| 80 | +} |
| 81 | + |
| 82 | +func showWorkingSetCommand() *cobra.Command { |
| 83 | + var opts struct { |
| 84 | + Format workingset.Format |
| 85 | + } |
| 86 | + cmd := &cobra.Command{ |
| 87 | + Use: "show <name>", |
| 88 | + Short: "Display working-set details", |
| 89 | + Long: `Display the details of a specific working-set including all its servers.`, |
| 90 | + Example: ` # Show a working-set in human-readable format |
| 91 | + docker mcp working-set show my-dev-tools |
| 92 | +
|
| 93 | + # Show a working-set in JSON format |
| 94 | + docker mcp working-set show my-dev-tools --format json |
| 95 | +
|
| 96 | + # Show a working-set in YAML format |
| 97 | + docker mcp working-set show my-dev-tools --format yaml`, |
| 98 | + Args: cobra.ExactArgs(1), |
| 99 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 100 | + return workingset.Show(args[0], opts.Format) |
| 101 | + }, |
| 102 | + } |
| 103 | + flags := cmd.Flags() |
| 104 | + flags.Var(&opts.Format, "format", fmt.Sprintf("Output format. Supported: %s.", workingset.SupportedFormats())) |
| 105 | + return cmd |
| 106 | +} |
0 commit comments