Skip to main content

Model Context Protocol server for Docker management with AI assistants

Project description

MCP Docker Server

Category Status
Build & CI CI CodeQL Pre-commit Dependency Review License Compliance Documentation codecov
SonarQube Quality Gate Status Maintainability Rating Reliability Rating Security Rating
Security OpenSSF Scorecard Bandit Dependabot Fuzzing
Package GitHub release PyPI version PyPI status PyPI downloads
Technology Python 3.11-3.14 Docker License: MIT Code style: ruff type-checked: mypy MCP

A Model Context Protocol server that exposes Docker functionality to AI assistants. Manage containers, images, networks, and volumes through a type-safe API with configurable safety controls.

33 tools | 5 AI prompts | 2 resource templates | stdio and HTTP transports

Quick Start

Claude Code:

claude mcp add --transport stdio docker uvx mcp-docker@latest

Codex:

codex mcp add docker -- uvx mcp-docker@latest

Claude Desktop — add to claude_desktop_config.json:

{
  "mcpServers": {
    "docker": {
      "command": "uvx",
      "args": ["mcp-docker"]
    }
  }
}

No additional configuration needed for local use. The Docker socket is auto-detected for your OS.

uvx caches packages. Use uvx mcp-docker@latest or uv cache prune to get updates.

HTTP Transport

For network deployments:

mcp-docker --transport http --host 127.0.0.1 --port 8000

For production, deploy behind a reverse proxy (NGINX, Caddy) for TLS, authentication, and rate limiting.

Tools

Container (10 tools)

Tool Description Safety
docker_list_containers List containers with filters Safe
docker_inspect_container Detailed container info Safe
docker_container_logs Get container logs Safe
docker_container_stats Resource usage stats Safe
docker_create_container Create new container Moderate
docker_start_container Start container Moderate
docker_stop_container Stop container gracefully Moderate
docker_restart_container Restart container Moderate
docker_exec_command Execute command in container Moderate
docker_remove_container Remove container Destructive

Image (9 tools)

Tool Description Safety
docker_list_images List images Safe
docker_inspect_image Image details Safe
docker_image_history View layer history Safe
docker_pull_image Pull from registry Moderate
docker_build_image Build from Dockerfile Moderate
docker_push_image Push to registry Moderate
docker_tag_image Tag image Moderate
docker_remove_image Remove image Destructive
docker_prune_images Clean unused images Destructive

Network (6 tools)

Tool Description Safety
docker_list_networks List networks Safe
docker_inspect_network Network details Safe
docker_create_network Create network Moderate
docker_connect_container Connect container to network Moderate
docker_disconnect_container Disconnect from network Moderate
docker_remove_network Remove network Destructive

Volume (5 tools)

Tool Description Safety
docker_list_volumes List volumes Safe
docker_inspect_volume Volume details Safe
docker_create_volume Create volume Moderate
docker_remove_volume Remove volume Destructive
docker_prune_volumes Clean unused volumes Destructive

System (3 tools)

Tool Description Safety
docker_version Docker version info Safe
docker_events Docker events with filters Safe
docker_prune_system Clean all unused resources Destructive

Prompts

Prompt Purpose
troubleshoot_container Diagnose container issues with logs and config analysis
optimize_container Resource usage and security optimization suggestions
generate_compose Generate docker-compose.yml from containers or descriptions
debug_networking Systematic L3-L7 network troubleshooting
security_audit CIS Docker Benchmark security analysis

Resource Templates

Discoverable via resources/templates/list:

  • container://logs/{container_id} — Last 100 lines of container logs
  • container://stats/{container_id} — Real-time resource usage (CPU, memory, network, I/O)

Safety System

Three-tier classification controls what operations are permitted:

Level Description Default Examples
Safe Read-only operations Always allowed list, inspect, logs, stats
Moderate Reversible state changes Allowed create, start, stop, pull
Destructive Permanent changes Blocked remove, prune

Configuration

# Control operation levels
SAFETY_ALLOW_MODERATE_OPERATIONS=true      # default: true
SAFETY_ALLOW_DESTRUCTIVE_OPERATIONS=false  # default: false

# Fine-grained tool filtering
SAFETY_ALLOWED_TOOLS="docker_list_containers,docker_inspect_container"  # whitelist (empty = all)
SAFETY_DENIED_TOOLS="docker_prune_system"                               # blacklist (takes precedence)

Deny list is checked before allow list. Both apply on top of the safety level gates.

Preset Modes

Read-only — monitoring and observability only:

SAFETY_ALLOW_MODERATE_OPERATIONS=false
SAFETY_ALLOW_DESTRUCTIVE_OPERATIONS=false

Balanced (default) — development and operations:

SAFETY_ALLOW_MODERATE_OPERATIONS=true
SAFETY_ALLOW_DESTRUCTIVE_OPERATIONS=false

Full access — infrastructure management:

SAFETY_ALLOW_MODERATE_OPERATIONS=true
SAFETY_ALLOW_DESTRUCTIVE_OPERATIONS=true

Security

Container logs may contain malicious prompts (RADE risk). See SECURITY.md for the full threat model.

Built-in security features: rate limiting, audit logging, IP filtering, OAuth support, error sanitization, and command injection validation.

For complete configuration reference, see CONFIGURATION.md.

MCP Server vs Docker CLI

Aspect Docker CLI MCP Server
Claude Desktop No CLI access Required (only option)
Claude Code Works directly Optional (adds safety)
Safety controls None Three-tier with filtering
Data format Text (needs parsing) Structured JSON
Audit logging Manual Built-in
Rate limiting None Configurable
Input validation None Pydantic schemas
Docker coverage Full 33 core operations

Use MCP Server for Claude Desktop (required), production automation, compliance, or when you need safety controls.

Use CLI directly in Claude Code for simple tasks or features beyond the 33 tools.

Development

Setup

git clone https://github.com/williajm/mcp_docker.git
cd mcp_docker
uv sync --group dev

Testing

Four test levels: unit (no Docker, ~5s), integration (Docker, ~10s), E2E (Docker, ~60s), and fuzz (security).

uv run pytest --cov=mcp_docker --cov-report=html   # All tests with coverage
uv run pytest tests/unit/ -v                         # Unit only
uv run pytest tests/integration/ -v -m integration   # Integration
uv run pytest tests/e2e/ -v -m "e2e and not stress"  # E2E (no stress)

Linting and Type Checking

uv run ruff check src/ tests/       # Lint
uv run ruff format --check src/ tests/  # Format check
uv run mypy src/mcp_docker/         # Type check (strict)

Project Structure

src/mcp_docker/
├── __main__.py          # Entry point (transport selection)
├── config.py            # Pydantic settings (env vars)
├── server/              # MCP server, prompts, resources
├── tools/               # Tool implementations by category
├── docker/              # Docker SDK wrapper
├── services/            # Audit, rate limiting, safety
├── middleware/           # Auth, safety, rate limiting
└── utils/               # Validation, helpers, errors

Requirements

  • Python 3.11+
  • Docker 20.10+
  • Key dependencies: mcp>=1.2.0, docker>=7.1.0, pydantic>=2.0.0, loguru, authlib, limits

License

MIT — see LICENSE.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_docker-1.2.8.tar.gz (199.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_docker-1.2.8-py3-none-any.whl (97.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_docker-1.2.8.tar.gz.

File metadata

  • Download URL: mcp_docker-1.2.8.tar.gz
  • Upload date:
  • Size: 199.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_docker-1.2.8.tar.gz
Algorithm Hash digest
SHA256 348fb17b57430a098e50788389811dc5c61d29c732acbca6fcae24a695813fe4
MD5 cd61a35ff23821d6ed8915abcebc108d
BLAKE2b-256 6a1db4975cfd23855c5fd8a76140385283c12bf2f094de55d4170352f3b5a63a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_docker-1.2.8.tar.gz:

Publisher: release.yml on williajm/mcp_docker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_docker-1.2.8-py3-none-any.whl.

File metadata

  • Download URL: mcp_docker-1.2.8-py3-none-any.whl
  • Upload date:
  • Size: 97.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_docker-1.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8a7be5bd643e879ce8a3cbad3f7830983a52eff8f33f51159874db98d2b9853c
MD5 706397399197abbd40dd4b6ea7b89096
BLAKE2b-256 601967a8ccfd95a385002258eca99d37920a9c640f7443b0d3d6507a33358ac4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_docker-1.2.8-py3-none-any.whl:

Publisher: release.yml on williajm/mcp_docker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page