Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions cmd/docker-mcp/commands/catalog_next.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,14 @@ import (

catalognext "github.com/docker/mcp-gateway/pkg/catalog_next"
"github.com/docker/mcp-gateway/pkg/db"
"github.com/docker/mcp-gateway/pkg/docker"
"github.com/docker/mcp-gateway/pkg/migrate"
"github.com/docker/mcp-gateway/pkg/oci"
"github.com/docker/mcp-gateway/pkg/workingset"
)

func catalogNextCommand(docker docker.Client) *cobra.Command {
func catalogNextCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "catalog-next",
Short: "Manage catalogs (next generation)",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
dao, err := db.New()
if err != nil {
return err
}
defer dao.Close()
migrate.MigrateConfig(cmd.Context(), docker, dao)
return nil
},
}

cmd.AddCommand(createCatalogNextCommand())
Expand Down
34 changes: 30 additions & 4 deletions cmd/docker-mcp/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package commands
import (
"context"
"os"
"slices"

"github.com/docker/cli/cli-plugins/plugin"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"

"github.com/docker/mcp-gateway/cmd/docker-mcp/version"
"github.com/docker/mcp-gateway/pkg/db"
"github.com/docker/mcp-gateway/pkg/desktop"
"github.com/docker/mcp-gateway/pkg/docker"
"github.com/docker/mcp-gateway/pkg/migrate"
)

// Note: We use a custom help template to make it more brief.
Expand All @@ -31,6 +34,8 @@ Examples:

// Root returns the root command for the init plugin
func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command {
dockerClient := docker.NewClient(dockerCli)

cmd := &cobra.Command{
Use: "mcp [OPTIONS]",
Short: "Manage MCP servers and clients",
Expand All @@ -46,6 +51,17 @@ func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command
}

if os.Getenv("DOCKER_MCP_IN_CONTAINER") != "1" {
if isWorkingSetsFeatureEnabled(dockerCli) {
if isSubcommandOf(cmd, []string{"catalog-next", "catalog", "profile"}) {
dao, err := db.New()
if err != nil {
return err
}
defer dao.Close()
migrate.MigrateConfig(cmd.Context(), dockerClient, dao)
}
}

runningInDockerCE, err := docker.RunningInDockerCE(ctx, dockerCli)
if err != nil {
return err
Expand All @@ -68,11 +84,9 @@ func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command
return []string{"--help"}, cobra.ShellCompDirectiveNoFileComp
})

dockerClient := docker.NewClient(dockerCli)

if isWorkingSetsFeatureEnabled(dockerCli) {
cmd.AddCommand(workingSetCommand(dockerClient))
cmd.AddCommand(catalogNextCommand(dockerClient))
cmd.AddCommand(workingSetCommand())
cmd.AddCommand(catalogNextCommand())
}
cmd.AddCommand(catalogCommand(dockerCli))
cmd.AddCommand(clientCommand(dockerCli, cwd))
Expand Down Expand Up @@ -101,3 +115,15 @@ func unhideHiddenCommands(cmd *cobra.Command) {
unhideHiddenCommands(c)
}
}

func isSubcommandOf(cmd *cobra.Command, names []string) bool {
if cmd == nil {
return false
}

if slices.Contains(names, cmd.Name()) {
return true
}

return isSubcommandOf(cmd.Parent(), names)
}
13 changes: 1 addition & 12 deletions cmd/docker-mcp/commands/workingset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,18 @@ import (

"github.com/docker/mcp-gateway/pkg/client"
"github.com/docker/mcp-gateway/pkg/db"
"github.com/docker/mcp-gateway/pkg/docker"
"github.com/docker/mcp-gateway/pkg/migrate"
"github.com/docker/mcp-gateway/pkg/oci"
"github.com/docker/mcp-gateway/pkg/registryapi"
"github.com/docker/mcp-gateway/pkg/sliceutil"
"github.com/docker/mcp-gateway/pkg/workingset"
)

func workingSetCommand(docker docker.Client) *cobra.Command {
func workingSetCommand() *cobra.Command {
cfg := client.ReadConfig()

cmd := &cobra.Command{
Use: "profile",
Short: "Manage profiles",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
dao, err := db.New()
if err != nil {
return err
}
defer dao.Close()
migrate.MigrateConfig(cmd.Context(), docker, dao)
return nil
},
}

cmd.AddCommand(exportWorkingSetCommand())
Expand Down
Loading