Skip to main content

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

Tool What it returns Writes?
list_containers Name, image, status, health and restart count for each container No
inspect_container State, ports, mounts, labels and restart policy; environment variable keys only No
get_container_logs Recent log lines, with an optional time-bounded anomaly scan No
container_stats One sample of CPU %, memory, network and block I/O, and PIDs (like docker stats --no-stream) No
container_health Health-check status, failing streak and the last 5 probe results (output truncated) No
list_images Local images with tags, size and creation time (up to 500) No
list_compose_projects Containers grouped by Compose project and service, with status counts No
container_events Recent container events (start, die, OOM, health changes), newest first; exec events report the action only, never the command No
safe_restart_container Restarts a container only when GUARDIAN_ALLOW_WRITE=true and the name passes the deny/allow lists Yes, gated

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

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

Variable Default Purpose
GUARDIAN_ALLOW_WRITE false Must 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_REGEX error/exception/fatal/... Pattern the log scanner flags
GUARDIAN_REGEX_TIMEOUT 1 Total seconds one log scan may spend matching; slower scans return regex_timeout
GUARDIAN_DOCKER_TIMEOUT 5 Seconds per Docker API call
GUARDIAN_LOG_LEVEL INFO Log level (logs go to stderr only)
DOCKER_HOST (unset) Docker endpoint to use; always wins when set
GUARDIAN_ALLOW_ROOTFUL false Allow 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).

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

Metadata

Release files for docker-mcp-guardian 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docker-mcp-guardian 0.2.0
File Size Uploaded Provenance Actions
docker_mcp_guardian-0.2.0.tar.gz 21.6 kB With provenance Details for docker_mcp_guardian-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for docker-mcp-guardian 0.2.0
File Interpreter ABI Platform Actions
docker_mcp_guardian-0.2.0-py3-none-any.whl Python 3 none any Details for docker_mcp_guardian-0.2.0-py3-none-any.whl

Total release size: 36.8 kB

Release files / docker_mcp_guardian-0.2.0.tar.gz

Download URL docker_mcp_guardian-0.2.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d637057e004275a5aadfa19d30627d905a62784e4796543a989ad8c33bbc22e3
BLAKE2b-256 checksum
How to use checksums
5c387180693550d8a557f62d98f6ddb5713541028c71589cb6ca7415a2e51fb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / docker_mcp_guardian-0.2.0-py3-none-any.whl

Download URL docker_mcp_guardian-0.2.0-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a6b53b53960652199ac24b57a75709e945797a519d8ca4c6c776b2b2eb59938
BLAKE2b-256 checksum
How to use checksums
d7baa76471677d887336f9f5c60bf83e809a81ce1a1554d95f480b394fded694
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for docker-mcp-guardian 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for docker_mcp_guardian-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page