
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.

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 |
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 server | docker-socket-proxy | Docker MCP Guardian | |
|---|---|---|---|
| What it is | The agent runs any docker command or API call | A proxy that allows or blocks Docker API endpoint groups | An MCP server with nine fixed tools |
| Can the agent start, stop, exec or delete? | Yes, anything the socket allows | Only the endpoint groups you enable | No. Only a gated restart, off by default |
| Environment variable values | Returned in full by inspect | Returned in full | Keys only; values withheld |
| Exec command lines in events | Returned | Returned | Action name only |
| Protected containers | No | No | Deny and allow lists on the daemon-resolved name |
| Best for | Trusted, interactive use | A hard API boundary for any client | Giving 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 unlessGUARDIAN_ALLOW_WRITE=trueis 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_containerstrips 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 structureddaemon_unavailableerror 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
| 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:
DOCKER_HOST, if set.- A rootless Docker socket:
$XDG_RUNTIME_DIR/docker.sock, then/run/user/<uid>/docker.sock. The second path covers MCP clients that start servers withoutXDG_RUNTIME_DIR. - The rootful
/var/run/docker.sock, only whenGUARDIAN_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.socksilently. If you rely on the rootful daemon, setDOCKER_HOST=unix:///var/run/docker.sock(orGUARDIAN_ALLOW_ROOTFUL=true) in your MCP server definition. Docker Desktop and Colima users should setDOCKER_HOSTto their socket, for exampleunix://$HOME/.docker/run/docker.sockorunix://$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
| Problem | What to do |
|---|---|
docker_socket_unresolved | No 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 directory | The 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 client | Clients 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 10001 | It was started with --cap-drop ALL and no --user. Add --user 10001:10001 --group-add <socket GID> |
forbidden on safe_restart_container | Expected 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_logs | The 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
- Don't Hand Claude Your Docker Socket — Build It a Guarded One (HackerNoon, October 21, 2026): why handing an AI agent the raw Docker socket is root-equivalent, and how this server's read-only default, canonical-name restart deny-list, secret redaction and bounded Docker API timeouts contain it.
docker-mcp-guardianpip install docker-mcp-guardianghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:0.1.1docker pull ghcr.io/sivasaikrishnasuryadevara/docker-mcp-guardian:0.1.1:undefined