Docker MCP Guardian
Connects to the local Docker daemon to provide guarded container inspection and optional restart capabilities, with read-only defaults, credential redaction, canonical ID resolution, and bounded API timeouts.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Docker MCP Guardian what Docker containers are running right now?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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.
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.
Related MCP server: Docker-MCPilotS
Quickstart
Prerequisites
Python 3.10+
Docker Engine / Docker Desktop
mcp>=1.0.0,<2(pinned to FastMCP API)
Local Installation
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/ -vConnect 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 |
|
| Must be |
|
| Containers that can never be restarted (always wins) |
| (unset) | If set, only matching containers can be restarted |
| error/exception/fatal/... | Pattern the log scanner flags |
|
| Total seconds one log scan may spend matching; slower scans return |
|
| Seconds per Docker API call |
|
| Log level (logs go to stderr only) |
| (unset) | Docker endpoint to use; always wins when set |
|
| Allow falling back to the rootful |
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).
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-guardianBoth 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.
Available Tools
9 toolscontainer_eventsA
Recent container events (start, die, oom, health_status, restart...), newest first, max 200. Read-only.
since_minutes is clamped to 1-1440. Exec events report the action only, never the command.
Inputs: container, since_minutes. Returns: object
container_healthB
A container's health-check status, failing streak and last 5 probe results (output truncated). Read-only.
Inputs: container (required). Returns: object
container_statsA
One sample of CPU, memory, network, block I/O and PIDs, like docker stats --no-stream. Read-only.
Inputs: container (required). Returns: object
get_container_logsB
Fetch the last tail log lines and scan them for error anomalies. Read-only.
Inputs: container (required), tail, anomaly_regex. Returns: object
inspect_containerA
Inspect a container's state, config, and networking. Read-only; env values are redacted.
Inputs: container (required). Returns: object
list_compose_projectsB
Containers grouped by Docker Compose project and service, with status counts. Read-only.
Inputs: no named parameters. Returns: object
list_containersA
List containers (running only unless all=true). Read-only.
Inputs: all. Returns: object
list_imagesA
List local images with tags, size and creation time (up to 500). Read-only.
Inputs: no named parameters. Returns: object
safe_restart_containerA
Restart a container only if write mode is enabled and its name passes the deny/allow guard.
Inputs: container (required), timeout. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool maps to a clearly different observation target: logs, events, health probes, stats sample, inspect state, listings, and the single write action. The only mild overlap is inspect_container versus container_health/container_stats, since inspect also surfaces state and networking, but the descriptions make the boundary (health-check history vs. single resource sample vs. full config) reasonably clear.
Half the set follows verb_noun (safe_restart_container, get_container_logs, inspect_container, list_*), but container_events, container_health and container_stats are bare noun-first names with no verb, and safe_restart_container adds an unusual qualifier prefix. Still readable, but the pattern is mixed rather than predictable.
Nine tools is a well-scoped surface for a guarded Docker monitoring server, and each tool earns its place by covering a distinct observability angle plus one explicitly gated mutation. No tool feels redundant or tacked on.
The read-only diagnostics side (logs, events, health, stats, inspect, listings) is comprehensive, but the write surface is essentially a single restart operation, so an agent cannot stop, start, remove, create, or exec into containers, nor manage images or compose lifecycle. These are notable gaps for a Docker control domain, though the 'guardian' framing suggests a deliberately narrow mutation surface.
Maintenance
Related MCP Connectors
Secure Linux sandboxes for AI agents, as MCP tools.
Remote MCP access to user-authorized Linux, Windows and Intel Mac devices for AI assistants.
Zero-secret MCP gateway for AI agents: risk-scored, audited calls with human-in-the-loop approval.
MCP gateway with runtime security policy, tool-call-level control, and audit of agent actions.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to interact with Docker containers through safe, permission-controlled access to inspect, manage, and diagnose containers, images, and compose services with built-in timeouts and AI-powered analysis.-
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to manage Docker containers through a secure MCP interface, supporting container lifecycle operations, log inspection, resource monitoring, and system diagnostics with role-based access control.2MIT
- AlicenseNot gradedqualityBmaintenanceEnables read-only inspection and narrowly scoped maintenance of a local Docker Desktop environment, covering containers, images, logs, stats, Compose status, and Scout vulnerability/SBOM data, plus limited actions such as image pulls, container restarts, dangling-image pruning, and allowlisted Compose redeploys, all without exposing the raw Docker socket to the client.1MIT
- AlicenseNot gradedqualityBmaintenanceEnables agents to perform core Docker container operations via MCP tools, including listing, inspecting, running, starting, stopping, and removing containers, listing and pulling images, reading logs, and listing volumes. It executes commands safely through the host's docker CLI using argument arrays rather than shell strings.64 npmMIT