cli icon indicating copy to clipboard operation
cli copied to clipboard

docker: unknown command: docker mcp

Open s97712 opened this issue 8 months ago • 7 comments

Description

   this.transport = new StdioClientTransport({
        "command": "docker",
        "args": [
          "mcp",
          "gateway",
          "run"
        ]
      });
      await this.mcp.connect(this.transport);
      const toolsResult = await this.mcp.listTools();

Error:

docker: unknown command: docker mcp

Run 'docker --help' for more information
Failed to connect to MCP server:  McpError: MCP error -32000: Connection closed
    at Client._onclose (D:\workspace\fix\mcp\node_modules\.pnpm\@[email protected]\node_modules\@modelcontex
tprotocol\sdk\dist\cjs\shared\protocol.js:101:23)
    at _transport.onclose (D:\workspace\fix\mcp\node_modules\.pnpm\@[email protected]\node_modules\@modelcon
textprotocol\sdk\dist\cjs\shared\protocol.js:73:18)
    at ChildProcess.<anonymous> (D:\workspace\fix\mcp\node_modules\.pnpm\@[email protected]\node_modules\@mo
delcontextprotocol\sdk\dist\cjs\client\stdio.js:97:77)
    at ChildProcess.emit (node:events:518:28)
    at cp.emit (D:\workspace\fix\mcp\node_modules\.pnpm\[email protected]\node_modules\cross-spawn\lib\enoent.js:34:29)   
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: -32000,
  data: undefined
}

Reproduce

mcp sdk will execute commands in the following way:

spawn("docker", [],{
    stdio: "inherit",
    env: getDefaultEnvironment()
  })

The mcp subcommand cannot be found when calling with this method.

> tsc && chmod 755 build/index.js

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Authenticate to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  builder     Manage builds
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  plugin      Manage plugins
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Swarm Commands:
  swarm       Manage Swarm

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Global Options:
      --config string      Location of client config files (default
                           "C:\\Users\\chen\\.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket to connect to
  -l, --log-level string   Set the logging level ("debug", "info",
                           "warn", "error", "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "C:\\Users\\chen\\.docker\\ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "C:\\Users\\chen\\.docker\\cert.pem")
      --tlskey string      Path to TLS key file (default
                           "C:\\Users\\chen\\.docker\\key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit


### Expected behavior

Working properly

### docker version

```bash
Client:
 Version:           28.2.2
 API version:       1.50
 Go version:        go1.24.3
 Git commit:        e6534b4
 Built:             Fri May 30 12:07:16 2025
 OS/Arch:           windows/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.42.1 (196648)
 Engine:
  Version:          28.2.2
  API version:      1.50 (minimum version 1.24)
  Go version:       go1.24.3
  Git commit:       45873be
  Built:            Fri May 30 12:07:26 2025
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.27
  GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
 runc:
  Version:          1.2.5
  GitCommit:        v1.2.5-0-g59923ef
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    28.2.2
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v1.4.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-ai.exe
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.24.0-desktop.2
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  cloud: Docker Cloud (Docker Inc.)
    Version:  v0.3.9
    Path:     C:\Program Files\Docker\cli-plugins\docker-cloud.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.37.1-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.41
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  desktop: Docker Desktop commands (Docker Inc.)
    Version:  v0.1.9
    Path:     C:\Program Files\Docker\cli-plugins\docker-desktop.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.29
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  dev
    Path:     C:\Program Files\Docker\cli-plugins\docker-mcp.exe
  model: Docker Model Runner (Docker Inc.)
    Version:  v0.1.24
    Path:     C:\Program Files\Docker\cli-plugins\docker-model.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.18.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 3
  Running: 3
  Paused: 0
  Stopped: 0
 Images: 6
 Server Version: 28.2.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Discovered Devices:
  cdi: docker.com/gpu=webgpu
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.10.14-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 1.917GiB
 Name: docker-desktop
 ID: d68fa413-95e0-459a-85db-9981cfd3060f
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=npipe://\\.\pipe\docker_cli
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: DOCKER_INSECURE_NO_IPTABLES_RAW is set

Additional Info

No response

s97712 avatar Jun 20 '25 12:06 s97712

What kind of environment is required to run mcp? I'm unable to find the mcp command whenever I set the environment (env), but I can't prevent the mcp sdk from setting it.

s97712 avatar Jun 20 '25 12:06 s97712

  spawn("docker", ["mcp", "gateway", "run"],
    {
      stdio: "inherit",
      env: {
        ...getDefaultEnvironment(),
        PROGRAMFILES: "C:\\Program Files"
      }
    });

Through debugging, I found that if the PROGRAMFILES variable is missing, Docker can't find the mcp subcommand. What role does this variable play for Docker?

s97712 avatar Jun 20 '25 12:06 s97712

Thanks for reporting. I think this is "expected" behavior, but let me slightly expand on that.

The mcp subcommand is provided through a CLI plugin. CLI plugins are distributed as separate binaries, and discovered by the CLI through various defined locations in order of priority;

  1. The "cli-plugins" directory inside the CLIs config-directory (usually "~/.docker/cli-plugins").
  2. Additional plugin directories as configured through ConfigFile.CLIPluginsExtraDirs.
  3. Platform-specific defaultSystemPluginDirs.

The Platform-specific defaultSystemPluginDirs for windows are inside %ProgramData\Docker\cli-plugins and %ProgramFiles\Docker\cli-plugins; https://github.com/docker/cli/blob/f03fb6c40bbfa46694fe18c274bf6ad2233cb17a/cli-plugins/manager/manager_windows.go#L8-L21 For Linux and macOS, the default locations are defined here; https://github.com/docker/cli/blob/f03fb6c40bbfa46694fe18c274bf6ad2233cb17a/cli-plugins/manager/manager_unix.go#L15-L20

In your case, it looks like you're executing the docker binary from code, but not propagating env-vars for the executed process, which means that it will search 1. (based on the home-directory for the user that the process is executed as), 2. (additional locations, but these are based on the CLI's config file in the home-directory - if present); if the plugin is not installed in either of those, it will use 3. for the system-wide locations, but those (on Windows) depend on these env-vars to be set.

Based on the output of your docker info it looks indeed that the cli-plugin is found in one of the system-wide paths;

  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  dev
    Path:     C:\Program Files\Docker\cli-plugins\docker-mcp.exe

thaJeztah avatar Jun 23 '25 12:06 thaJeztah

It's going as planned, but we've run into a couple of problems.

s97712 avatar Jun 23 '25 22:06 s97712

@thaJeztah so how can the "mcp toolkit" plugin be used from a Windows/WSL setup with a docker outside of docker dev container? When I run docker info inside the container most of the plugins like "MCP toolkit" are missing

thoughtfuldata avatar Jun 29 '25 19:06 thoughtfuldata

Yes, to run these CLI plugins in a container, they'd have to be installed there. AFAIK, the mcp CLI-plugin is currently closed-source, and only ships as part of Docker Desktop; not sure if there's a separate download available for that one (also not sure if it'd be able to run inside a container).

cc @dgageot

thaJeztah avatar Jun 30 '25 08:06 thaJeztah

I have the same problem... :'(

The Platform-specific defaultSystemPluginDirs for windows are inside %ProgramData\Docker\cli-plugins and %ProgramFiles\Docker\cli-plugins;

Just updating that, on Windows 11, I don't have the %ProgramData%\Docker\cli-plugins. It's a default installer path, since I have the %ProgramFiles%\Docker\cli-plugins .

So, it looks on both paths or just the first, then fails?

Edit:

Also, running directly on Powershell (v7), the command works:

> docker mcp
Docker MCP Toolkit's CLI - Manage your MCP servers and clients.
(...)

AdrianoCahete avatar Oct 31 '25 21:10 AdrianoCahete