Repository avatar
Developer Tools
v0.1.1
active

docker-mcp-guardian

io.github.SivaSaiKrishnaSuryadevara/docker-mcp-guardian

Read-only-by-default Docker MCP server: inspect, logs and gated restarts with secret redaction.

Documentation

Docker MCP Guardian

A security-hardened Model Context Protocol (MCP) server written in Python with FastMCP that connects local LLM agents (Claude Desktop, Claude Code) to the Docker daemon with strict zero-trust boundaries.

CI License: MIT PyPI MCP Registry

Install in VS Code Install in Cursor

docker-mcp-guardian demo: an agent lists and inspects containers with secrets redacted; restarts are refused in read-only mode and for protected containers

The install buttons add the signed container with the Docker socket mounted; that works with Docker Desktop and rootful Docker on Linux. For uvx or rootless Docker, see Quickstart.

Tools

ToolWhat it returnsWrites?
list_containersName, image, status, health and restart count for each containerNo
inspect_containerState, ports, mounts, labels and restart policy; environment variable keys onlyNo
get_container_logsRecent log lines, with an optional time-bounded anomaly scanNo
container_statsOne sample of CPU %, memory, network and block I/O, and PIDs (like docker stats --no-stream)No
container_healthHealth-check status, failing streak and the last 5 probe results (output truncated)No
list_imagesLocal images with tags, size and creation time (up to 500)No
list_compose_projectsContainers grouped by Compose project and service, with status countsNo
container_eventsRecent container events (start, die, OOM, health changes), newest first; exec events report the action only, never the commandNo
safe_restart_containerRestarts a container only when GUARDIAN_ALLOW_WRITE=true and the name passes the deny/allow listsYes, gated

How it compares

Ways to let an agent see Docker, and what each one allows. This is what each option is for, not a scoreboard.

Raw socket or Docker CLI serverdocker-socket-proxyDocker MCP Guardian
What it isThe agent runs any docker command or API callA proxy that allows or blocks Docker API endpoint groupsAn MCP server with nine fixed tools
Can the agent start, stop, exec or delete?Yes, anything the socket allowsOnly the endpoint groups you enableNo. Only a gated restart, off by default
Environment variable valuesReturned in full by inspectReturned in fullKeys only; values withheld
Exec command lines in eventsReturnedReturnedAction name only
Protected containersNoNoDeny and allow lists on the daemon-resolved name
Best forTrusted, interactive useA hard API boundary for any clientGiving an agent visibility without handing it control

The two can be combined: point DOCKER_HOST at a socket proxy that allows only the container and image endpoints, and Guardian's limits apply on top of the proxy's.

Core Capabilities & Safeguards

  • Read-Only by Default: Mutation tools (safe_restart_container) reject calls before touching the Docker socket unless GUARDIAN_ALLOW_WRITE=true is explicitly set.
  • Canonical ID Resolution: Resolves container IDs to Docker's internal canonical name before evaluating regex denylists, preventing evasion via hex IDs.
  • Credential & Secret Redaction: inspect_container strips all environment variable values, returning only variable keys to prevent LLM prompt leakage.
  • Isolated Stdio JSON-RPC: Strict logging separation ensures zero unstructured stdout writes, preventing JSON-RPC stream corruption in MCP clients.
  • Bounded Daemon Timeouts: Every Docker API call is capped by GUARDIAN_DOCKER_TIMEOUT (default 5s), so a wedged or missing daemon returns a structured daemon_unavailable error instead of hanging the session.

Quickstart

Prerequisites

  • Python 3.10+
  • Docker Engine / Docker Desktop
  • uv for the one-line install, or Docker to run the container

Install with uvx (recommended)

uvx downloads and runs the latest release from PyPI; there is nothing to clone. Set DOCKER_HOST to your Docker socket (see Docker endpoint resolution):

# Claude Code, with Docker Desktop on macOS
claude mcp add docker-guardian -e DOCKER_HOST="unix://$HOME/.docker/run/docker.sock" -- uvx docker-mcp-guardian

# Claude Code, with rootless Docker on Linux
claude mcp add docker-guardian -e DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock" -- uvx docker-mcp-guardian

Claude Desktop, Cursor and other clients (mcpServers in their JSON config; write the socket path literally):

{
  "mcpServers": {
    "docker-guardian": {
      "command": "uvx",
      "args": ["docker-mcp-guardian"],
      "env": { "DOCKER_HOST": "unix:///Users/you/.docker/run/docker.sock" }
    }
  }
}

Run the container

The signed image from GHCR finds the mounted socket's group on its own:

claude mcp add docker-guardian -- docker run --rm -i \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e GUARDIAN_ALLOW_ROOTFUL=true \
  ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:latest

Install from source

git clone https://github.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian.git
cd docker-mcp-guardian
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pytest tests/ -v

# connect it to Claude Code
claude mcp add docker-guardian -- "$PWD/.venv/bin/python" "$PWD/server.py"

For Claude Desktop, add the same interpreter and script paths (absolute) under mcpServers in claude_desktop_config.json.

Configuration

VariableDefaultPurpose
GUARDIAN_ALLOW_WRITEfalseMust be true for safe_restart_container to do anything
GUARDIAN_RESTART_DENY_REGEX^(prod|db|kube|vault)-.*Containers that can never be restarted (always wins)
GUARDIAN_RESTART_ALLOW_REGEX(unset)If set, only matching containers can be restarted
GUARDIAN_ANOMALY_REGEXerror/exception/fatal/...Pattern the log scanner flags
GUARDIAN_REGEX_TIMEOUT1Total seconds one log scan may spend matching; slower scans return regex_timeout
GUARDIAN_DOCKER_TIMEOUT5Seconds per Docker API call
GUARDIAN_LOG_LEVELINFOLog level (logs go to stderr only)
DOCKER_HOST(unset)Docker endpoint to use; always wins when set
GUARDIAN_ALLOW_ROOTFULfalseAllow falling back to the rootful /var/run/docker.sock

Docker endpoint resolution

Guardian picks its Docker endpoint in this order, and logs the choice to stderr:

  1. DOCKER_HOST, if set.
  2. A rootless Docker socket: $XDG_RUNTIME_DIR/docker.sock, then /run/user/<uid>/docker.sock. The second path covers MCP clients that start servers without XDG_RUNTIME_DIR.
  3. The rootful /var/run/docker.sock, only when GUARDIAN_ALLOW_ROOTFUL=true. Guardian logs a warning, because rootful API access is root-equivalent.

If none applies, tools return a docker_socket_unresolved error instead of connecting. The system socket is never used while a rootless socket exists.

Upgrading: earlier versions fell back to /var/run/docker.sock silently. If you rely on the rootful daemon, set DOCKER_HOST=unix:///var/run/docker.sock (or GUARDIAN_ALLOW_ROOTFUL=true) in your MCP server definition. Docker Desktop and Colima users should set DOCKER_HOST to their socket, for example unix://$HOME/.docker/run/docker.sock or unix://$HOME/.colima/default/docker.sock.

Rootless Docker

MCP clients (Claude Desktop, Claude Code, Cursor, Cline) start Guardian as a child process, often with a reduced environment that has no XDG_RUNTIME_DIR or DOCKER_HOST. Guardian still checks /run/user/<uid>/docker.sock, but if your rootless runtime directory is elsewhere, or you want the endpoint pinned, set DOCKER_HOST in the server definition:

{
  "mcpServers": {
    "docker-guardian": {
      "command": "/path/to/docker-mcp-guardian/.venv/bin/python",
      "args": ["/path/to/docker-mcp-guardian/server.py"],
      "env": {
        "DOCKER_HOST": "unix:///run/user/1000/docker.sock"
      }
    }
  }
}

Write the path literally: most clients do not expand $XDG_RUNTIME_DIR or $HOME in env. To find the value for your user, run either of these in a shell where rootless Docker works:

echo "unix://$XDG_RUNTIME_DIR/docker.sock"
docker context inspect rootless --format '{{.Endpoints.docker.Host}}'

With Claude Code, the shell expands the variable when the server is added:

claude mcp add docker-guardian -e DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock" -- "$PWD/.venv/bin/python" "$PWD/server.py"

To confirm the endpoint is the rootless daemon, check that this lists name=rootless:

DOCKER_HOST=unix:///run/user/1000/docker.sock docker info --format '{{.SecurityOptions}}'

On the first tool call, Guardian logs the endpoint it chose to stderr, for example Using Docker endpoint unix:///run/user/1000/docker.sock (DOCKER_HOST is set).

Troubleshooting

ProblemWhat to do
docker_socket_unresolvedNo socket Guardian may use was found. Set DOCKER_HOST (see Docker endpoint resolution), or GUARDIAN_ALLOW_ROOTFUL=true to use /var/run/docker.sock
daemon_unavailable with Permission denied (uvx or source install)Your user cannot open the socket. Add it to the docker group, use rootless Docker, or point DOCKER_HOST at Docker Desktop's socket
daemon_unavailable with No such file or directoryThe path in DOCKER_HOST does not exist. Docker Desktop on macOS: unix://$HOME/.docker/run/docker.sock. Colima: unix://$HOME/.colima/default/docker.sock. Rootless Linux: unix:///run/user/<uid>/docker.sock
Works in a terminal but not in the MCP clientClients start servers with a reduced environment and do not expand $HOME or $XDG_RUNTIME_DIR. Write the socket path literally in the client's env
Container exits with cannot drop to UID 10001It was started with --cap-drop ALL and no --user. Add --user 10001:10001 --group-add <socket GID>
forbidden on safe_restart_containerExpected in read-only mode. Set GUARDIAN_ALLOW_WRITE=true, and check that the name does not match GUARDIAN_RESTART_DENY_REGEX
regex_timeout from get_container_logsThe anomaly pattern took longer than GUARDIAN_REGEX_TIMEOUT. Use a simpler pattern or a smaller tail

Anything else: open an issue. Report security problems privately, as described in SECURITY.md.

Verifying Release Images

Release images are published to ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian for linux/amd64 and linux/arm64 by release-signed.yml when a v*.*.* tag is pushed. Each image is:

  • signed with keyless Sigstore cosign: the signing certificate is bound to this repository's release workflow through GitHub OIDC, and the signature is recorded in the public Rekor transparency log. No signing key exists to leak.
  • attested with a GitHub build provenance attestation (SLSA provenance) for the same image digest.

Verify both before running an image (requires cosign 3.x and the GitHub CLI):

IMAGE=ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:<version>   # e.g. 1.0.0

# 1. Sigstore signature: issued to this repository's release workflow, for a version tag.
cosign verify "$IMAGE" \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  --certificate-identity-regexp '^https://github\.com/SivaSaiKrishnaSuryadevara/docker-mcp-guardian/\.github/workflows/release-signed\.yml@refs/tags/v'

# 2. Build provenance: built by this repository's GitHub Actions workflow.
gh attestation verify "oci://$IMAGE" --repo SivaSaiKrishnaSuryadevara/docker-mcp-guardian

Both commands exit non-zero if the image was not built and signed by this repository's release workflow. To run exactly what you verified, pull by digest: docker pull ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian@sha256:<digest>, using the digest that cosign verify prints.

Write-up

The security model, tool surface, and policy engine are documented in docs/SECURITY_ARCHITECTURE.md.

Deep Dive & Publications

PYPI
docker-mcp-guardian
Install Command
pip install docker-mcp-guardian
Runtime: uvx
OCI
ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:0.1.1
Install Command
docker pull ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:0.1.1:undefined
Runtime: docker