@@ -3,14 +3,17 @@ package commands
33import (
44 "context"
55 "os"
6+ "slices"
67
78 "github.com/docker/cli/cli-plugins/plugin"
89 "github.com/docker/cli/cli/command"
910 "github.com/spf13/cobra"
1011
1112 "github.com/docker/mcp-gateway/cmd/docker-mcp/version"
13+ "github.com/docker/mcp-gateway/pkg/db"
1214 "github.com/docker/mcp-gateway/pkg/desktop"
1315 "github.com/docker/mcp-gateway/pkg/docker"
16+ "github.com/docker/mcp-gateway/pkg/migrate"
1417)
1518
1619// Note: We use a custom help template to make it more brief.
@@ -31,6 +34,8 @@ Examples:
3134
3235// Root returns the root command for the init plugin
3336func Root (ctx context.Context , cwd string , dockerCli command.Cli ) * cobra.Command {
37+ dockerClient := docker .NewClient (dockerCli )
38+
3439 cmd := & cobra.Command {
3540 Use : "mcp [OPTIONS]" ,
3641 Short : "Manage MCP servers and clients" ,
@@ -46,6 +51,17 @@ func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command
4651 }
4752
4853 if os .Getenv ("DOCKER_MCP_IN_CONTAINER" ) != "1" {
54+ if isWorkingSetsFeatureEnabled (dockerCli ) {
55+ if isSubcommandOf (cmd , []string {"catalog-next" , "catalog" , "profile" }) {
56+ dao , err := db .New ()
57+ if err != nil {
58+ return err
59+ }
60+ defer dao .Close ()
61+ migrate .MigrateConfig (cmd .Context (), dockerClient , dao )
62+ }
63+ }
64+
4965 runningInDockerCE , err := docker .RunningInDockerCE (ctx , dockerCli )
5066 if err != nil {
5167 return err
@@ -68,11 +84,9 @@ func Root(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command
6884 return []string {"--help" }, cobra .ShellCompDirectiveNoFileComp
6985 })
7086
71- dockerClient := docker .NewClient (dockerCli )
72-
7387 if isWorkingSetsFeatureEnabled (dockerCli ) {
74- cmd .AddCommand (workingSetCommand (dockerClient ))
75- cmd .AddCommand (catalogNextCommand (dockerClient ))
88+ cmd .AddCommand (workingSetCommand ())
89+ cmd .AddCommand (catalogNextCommand ())
7690 }
7791 cmd .AddCommand (catalogCommand (dockerCli ))
7892 cmd .AddCommand (clientCommand (dockerCli , cwd ))
@@ -101,3 +115,15 @@ func unhideHiddenCommands(cmd *cobra.Command) {
101115 unhideHiddenCommands (c )
102116 }
103117}
118+
119+ func isSubcommandOf (cmd * cobra.Command , names []string ) bool {
120+ if cmd == nil {
121+ return false
122+ }
123+
124+ if slices .Contains (names , cmd .Name ()) {
125+ return true
126+ }
127+
128+ return isSubcommandOf (cmd .Parent (), names )
129+ }
0 commit comments