Skip to content

Commit 7ed2b0d

Browse files
authored
Merge pull request #45 from dgageot/docker-ce
Make the MCP Gateway work out of the box with Docker CE
2 parents e3b68fc + 565c7d0 commit 7ed2b0d

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

cmd/docker-mcp/command.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/docker/cli/cli-plugins/plugin"
12+
"github.com/docker/cli/cli/command"
1213
"github.com/spf13/cobra"
1314

1415
"github.com/docker/mcp-gateway/cmd/docker-mcp/backup"
@@ -43,7 +44,7 @@ Examples:
4344
`
4445

4546
// rootCommand returns the root command for the init plugin
46-
func rootCommand(ctx context.Context, cwd string, docker docker.Client) *cobra.Command {
47+
func rootCommand(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command {
4748
cmd := &cobra.Command{
4849
Use: "mcp [OPTIONS]",
4950
TraverseChildren: true,
@@ -58,7 +59,14 @@ func rootCommand(ctx context.Context, cwd string, docker docker.Client) *cobra.C
5859
}
5960

6061
if os.Getenv("DOCKER_MCP_IN_CONTAINER") != "1" {
61-
return desktop.CheckFeatureIsEnabled(ctx, "enableDockerMCPToolkit", "Docker MCP Toolkit")
62+
runningInDockerCE, err := docker.RunningInDockerCE(ctx, dockerCli)
63+
if err != nil {
64+
return err
65+
}
66+
67+
if !runningInDockerCE {
68+
return desktop.CheckFeatureIsEnabled(ctx, "enableDockerMCPToolkit", "Docker MCP Toolkit")
69+
}
6270
}
6371

6472
return nil
@@ -73,15 +81,17 @@ func rootCommand(ctx context.Context, cwd string, docker docker.Client) *cobra.C
7381
return []string{"--help"}, cobra.ShellCompDirectiveNoFileComp
7482
})
7583

76-
cmd.AddCommand(secret.NewSecretsCmd(docker))
84+
dockerClient := docker.NewClient(dockerCli)
85+
86+
cmd.AddCommand(secret.NewSecretsCmd(dockerClient))
7787
cmd.AddCommand(policy.NewPolicyCmd())
7888
cmd.AddCommand(oauth.NewOAuthCmd())
7989
cmd.AddCommand(client.NewClientCmd(cwd))
8090
cmd.AddCommand(catalog.NewCatalogCmd())
8191
cmd.AddCommand(versionCommand())
82-
cmd.AddCommand(gatewayCommand(docker))
83-
cmd.AddCommand(configCommand(docker))
84-
cmd.AddCommand(serverCommand(docker))
92+
cmd.AddCommand(gatewayCommand(dockerClient))
93+
cmd.AddCommand(configCommand(dockerClient))
94+
cmd.AddCommand(serverCommand(dockerClient))
8595
cmd.AddCommand(toolsCommand())
8696

8797
if os.Getenv("DOCKER_MCP_SHOW_HIDDEN") == "1" {

cmd/docker-mcp/internal/docker/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package docker
22

33
import (
44
"context"
5+
"fmt"
56
"io"
7+
"runtime"
68
"sync"
79

810
"github.com/docker/cli/cli/command"
@@ -51,3 +53,16 @@ func NewClient(cli command.Cli) Client {
5153
}),
5254
}
5355
}
56+
57+
func RunningInDockerCE(ctx context.Context, dockerCli command.Cli) (bool, error) {
58+
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
59+
return false, nil
60+
}
61+
62+
info, err := dockerCli.Client().Info(ctx)
63+
if err != nil {
64+
return false, fmt.Errorf("failed to ping Docker daemon: %w", err)
65+
}
66+
67+
return info.OperatingSystem != "Docker Desktop", nil
68+
}

cmd/docker-mcp/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/docker/cli/cli/command"
1313
"github.com/spf13/cobra"
1414

15-
"github.com/docker/mcp-gateway/cmd/docker-mcp/internal/docker"
1615
"github.com/docker/mcp-gateway/cmd/docker-mcp/version"
1716
)
1817

@@ -31,8 +30,7 @@ func main() {
3130
}
3231

3332
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
34-
dockerClient := docker.NewClient(dockerCli)
35-
return rootCommand(ctx, cwd, dockerClient)
33+
return rootCommand(ctx, cwd, dockerCli)
3634
},
3735
manager.Metadata{
3836
SchemaVersion: "0.1.0",

0 commit comments

Comments
 (0)