A Docker MCP Server with enhanced session management and streamable-http support
Project description
🐋 Docker MCP server
An MCP server for managing Docker with natural language!
🔧 FIXED: Resolved anyio.ClosedResourceError and added streamable-http transport support!
🪩 What can it do?
- 🚀 Compose containers with natural language
- 🔍 Introspect & debug running containers
- 📀 Manage persistent data with Docker volumes
- 🌐 Works with both stdio and streamable-http transports
- 🔧 Enhanced error handling and session management
❓ Who is this for?
- Server administrators: connect to remote Docker engines for e.g. managing a public-facing website.
- Tinkerers: run containers locally and experiment with open-source apps supporting Docker.
- AI enthusiasts: push the limits of that an LLM is capable of!
- Agno app users: seamless integration with improved stability
🆕 Recent Improvements
- Fixed
anyio.ClosedResourceError: Improved session management prevents premature session closure - Streamable HTTP Support: Added proper HTTP transport for better integration with modern MCP clients
- Enhanced Error Handling: Comprehensive error handling prevents crashes and provides better debugging
- Agno Integration: Specifically tested and optimized for Agno app compatibility
- Health Monitoring: Added health check endpoint for HTTP transport monitoring
Demo
A quick demo showing a WordPress deployment using natural language:
https://github.com/user-attachments/assets/65e35e67-bce0-4449-af7e-9f4dd773b4b3
🏎️ Quickstart
Transport Options
Streamable HTTP (Recommended for Agno)
# Install dependencies
pip install -e .
# Start server with HTTP transport
python run_server.py --transport streamable-http --host 0.0.0.0 --port 8080
# Test health endpoint
curl http://localhost:8080/health
Standard I/O (Claude Desktop)
# Install dependencies
pip install -e .
# Start server with stdio transport
python run_server.py --transport stdio
Install
Claude Desktop
On MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
On Windows: %APPDATA%/Claude/claude_desktop_config.json
Install from PyPi with uv
If you don't have uv installed, follow the installation instructions for your
system:
link
Then add the following to your MCP servers file:
"mcpServers": {
"mcp-server-docker": {
"command": "uvx",
"args": [
"mcp-server-docker"
]
}
}
Install with Docker
Purely for convenience, the server can run in a Docker container.
After cloning this repository, build the Docker image:
docker build -t mcp-server-docker .
And then add the following to your MCP servers file:
"mcpServers": {
"mcp-server-docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/var/run/docker.sock:/var/run/docker.sock",
"mcp-server-docker:latest"
]
}
}
Note that we mount the Docker socket as a volume; this ensures the MCP server can connect to and control the local Docker daemon.
📝 Prompts
🎻 docker_compose
Use natural language to compose containers. See above for a demo.
Provide a Project Name, and a description of desired containers, and let the LLM do the rest.
This prompt instructs the LLM to enter a plan+apply loop. Your interaction
with the LLM will involve the following steps:
- You give the LLM instructions for which containers to bring up
- The LLM calculates a concise natural language plan and presents it to you
- You either:
- Apply the plan
- Provide the LLM feedback, and the LLM recalculates the plan
Examples
- name:
nginx, containers: "deploy an nginx container exposing it on port 9000" - name:
wordpress, containers: "deploy a WordPress container and a supporting MySQL container, exposing Wordpress on port 9000"
Resuming a Project
When starting a new chat with this prompt, the LLM will receive the status of
any containers, volumes, and networks created with the given project name.
This is mainly useful for cleaning up, in-case you lose a chat that was responsible for many containers.
📔 Resources
The server implements a couple resources for every container:
- Stats: CPU, memory, etc. for a container
- Logs: tail some logs from a container
🔨 Tools
Containers
list_containerscreate_containerrun_containerrecreate_containerstart_containerfetch_container_logsstop_containerremove_container
Images
list_imagespull_imagepush_imagebuild_imageremove_image
Networks
list_networkscreate_networkremove_network
Volumes
list_volumescreate_volumeremove_volume
🚧 Disclaimers
Sensitive Data
DO NOT CONFIGURE CONTAINERS WITH SENSITIVE DATA. This includes API keys, database passwords, etc.
Any sensitive data exchanged with the LLM is inherently compromised, unless the LLM is running on your local machine.
If you are interested in securely passing secrets to containers, file an issue on this repository with your use-case.
Reviewing Created Containers
Be careful to review the containers that the LLM creates. Docker is not a secure sandbox, and therefore the MCP server can potentially impact the host machine through Docker.
For safety reasons, this MCP server doesn't support sensitive Docker options
like --privileged or --cap-add/--cap-drop. If these features are of interest
to you, file an issue on this repository with your use-case.
🛠️ Configuration
This server uses the Python Docker SDK's from_env method. For configuration
details, see
the documentation.
Connect to Docker over SSH
This MCP server can connect to a remote Docker daemon over SSH.
Simply set a ssh:// host URL in the MCP server definition:
"mcpServers": {
"mcp-server-docker": {
"command": "uvx",
"args": [
"mcp-server-docker"
],
"env": {
"DOCKER_HOST": "ssh://myusername@myhost.example.com"
}
}
}
💻 Development
Prefer using Devbox to configure your development environment.
See the devbox.json for helpful development commands.
After setting up devbox you can configure your Claude MCP config to use it:
"docker": {
"command": "/path/to/repo/.devbox/nix/profile/default/bin/uv",
"args": [
"--directory",
"/path/to/repo/",
"run",
"mcp-server-docker"
]
},
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cgx_mcp_server_docker-0.3.0.tar.gz.
File metadata
- Download URL: cgx_mcp_server_docker-0.3.0.tar.gz
- Upload date:
- Size: 83.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c69e2cdef9df8e43b251ed3d1803193dda3226e3a96a0c3c7d41d68b60b628db
|
|
| MD5 |
d32c728976096de01a140cabf4e15d3a
|
|
| BLAKE2b-256 |
3e1f1465d8f2cc5976ee40589bad10eef2cbf057206741ee0657340ecee643c8
|
File details
Details for the file cgx_mcp_server_docker-0.3.0-py3-none-any.whl.
File metadata
- Download URL: cgx_mcp_server_docker-0.3.0-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fea8f97b6653ff440898fe170e218ae81c5d3dfb53c88ac854ecd3bf31d09ff
|
|
| MD5 |
3eddf3d6f1d50b1ae516751824fa2347
|
|
| BLAKE2b-256 |
58e3fba4b5589925b8fc93e943eb6ac895f2672d5a0e80458473a6dc6573a90a
|