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

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.1.1

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.1.1
File Size Uploaded Provenance Actions
docker_mcp_guardian-0.1.1.tar.gz 15.9 kB With provenance Details for docker_mcp_guardian-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 27.7 kB

Release files / docker_mcp_guardian-0.1.1.tar.gz

Download URL docker_mcp_guardian-0.1.1.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bad1a86eb2d221972498fa6e47d3ad45f8896f4ea5feb7c843081541417c09c1
BLAKE2b-256 checksum
How to use checksums
f2498c874180f991ae409fb05d312858cdcb5acf630c159e246287ab711399aa
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.1.1-py3-none-any.whl

Download URL docker_mcp_guardian-0.1.1-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76b238e1d013f8b7901f54a8ff2d82007c4199b2c95e264a778f75dcd8f81fe5
BLAKE2b-256 checksum
How to use checksums
ab3c6a636a1a5bc8377eeed165e3fb57f927700eeff9c1fc9149ec62119c91f7
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.1.1

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.1.1.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.1.1 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