docker-mcp

repository·main·Indexed 19 days ago

https://github.com/quantgeekdev/docker-mcp

A Model Context Protocol (MCP) server version 0.1.0 that enables AI models like Claude to interact with Docker. It provides tools to create containers, deploy Docker Compose stacks, list containers, and retrieve logs through a natural language interface. Includes a specialized 'deploy-stack' prompt to assist AI agents in transitioning from requirements to deployments.

Tokens
2K
Snippets
8
Records
10
Agent score
67%

What's inside docker-mcp

  1. Quickstart: Add docker-mcp to Claude Desktop

    main

    To use docker-mcp with the Claude Desktop app, add the server configuration to your Claude Desktop configuration file. This allows Claude to perform Docker operations like container management and log retrieval.

    Prerequisites:

    • UV (package manager)
    • Python 3.12+
    • Docker Desktop or Docker Engine
    • Claude Desktop
    {
      "mcpServers": {
        "docker-mcp": {
          "command": "uvx",
          "args": [
            "docker-mcp"
          ]
        }
      }
    }
  2. Configure Claude Desktop for docker-mcp

    main

    Depending on your environment, add the configuration to the appropriate file path:

    • MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%/Claude/claude_desktop_config.json

    Production Configuration

    Use this for standard usage with uvx:

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

    Development Configuration

    Use this when working on the local repository to run the server from a specific directory:

    {
      "mcpServers": {
        "docker-mcp": {
          "command": "uv",
          "args": [
            "--directory",
            "<path-to-docker-mcp>",
            "run",
            "docker-mcp"
          ]
        }
      }
    }
  3. Set up docker-mcp for development

    main

    To develop on docker-mcp, follow these steps to set up your local environment:

    1. Clone the repository:
      git clone https://github.com/QuantGeekDev/docker-mcp.git
      cd docker-mcp
    2. Create and activate a virtual environment:
      python -m venv venv
      source venv/bin/activate  # On Windows: venv\Scripts\activate
    3. Install dependencies using uv:
      uv sync
    git clone https://github.com/QuantGeekDev/docker-mcp.git
    cd docker-mcp
    python -m venv venv
    source venv/bin/activate
    uv sync
  4. Reference: Available Docker MCP Tools

    main

    The docker-mcp server exposes the following tools for managing Docker resources:

    • create-container: Creates a standalone Docker container.
    • deploy-compose: Deploys a Docker Compose stack.
    • get-logs: Retrieves logs from a specific container.
    • list-containers: Lists all Docker containers.
    ### create-container
    ```json
    {
        "image": "image-name",
        "name": "container-name",
        "ports": {"80": "80"},
        "environment": {"ENV_VAR": "value"}
    }

    deploy-compose

    {
        "project_name": "example-stack",
        "compose_yaml": "version: '3.8'\nservices:\n  service1:\n    image: image1:latest\n    ports:\n      - '8080:80'"
    }

    get-logs

    {
        "container_name": "my-container"
    }

    list-containers

    {}
  5. Current limitations of docker-mcp

    main

    The following features are currently not supported by docker-mcp:

    • Built-in environment variable support for containers
    • Volume management
    • Network management
    • Container health checks
    • Container restart policies
    • Container resource limits
  6. Use the deploy-stack prompt

    main

    The docker-mcp server includes a specialized prompt called deploy-stack designed to help an AI agent transition from high-level requirements to actual Docker deployments.

    When using this prompt, you must provide two arguments:

    1. requirements: A description of the desired Docker stack.
    2. project_name: The name for the Docker Compose project.

    The prompt instructs the agent to act as a Docker deployment specialist and follow a specific workflow:

    • Single container: Use the create-container tool.
    • Multi-container: Generate a docker-compose.yml and use the deploy-compose tool.
    • Debugging: Use list-containers to discover containers and get-logs to retrieve logs.
    {
      "name": "deploy-stack",
      "description": "Generate and deploy a Docker stack based on requirements",
      "arguments": [
        {
          "name": "requirements",
          "description": "Description of the desired Docker stack",
          "required": true
        },
        {
          "name": "project_name",
          "description": "Name for the Docker Compose project",
          "required": true
        }
      ]
    }
  7. Run the docker-mcp server via main()

    main

    The main() function serves as the primary entry point for the docker-mcp package. It initializes and runs the MCP server using an asynchronous event loop. This is the function you should call if you are running the package as a script or integrating its execution into a Python application.

    from docker_mcp import main
    
    if __name__ == "__main__":
        main()
  8. Available Tools in docker-mcp

    main

    The docker-mcp server provides four primary tools for managing Docker environments via the Model Context Protocol (MCP). These tools allow an AI agent to create containers, deploy multi-container stacks, list running containers, and retrieve logs.

    Tool Definitions

    Tool NameDescriptionRequired Arguments
    create-containerCreate a new standalone Docker containerimage
    deploy-composeDeploy a Docker Compose stackcompose_yaml, project_name
    get-logsRetrieve the latest logs for a specified Docker containercontainer_name
    list-containersList all Docker containersNone
    ### create-container
    Input Schema:
    ```json
    {
      "type": "object",
      "properties": {
        "image": {"type": "string"},
        "name": {"type": "string"},
        "ports": {
          "type": "object",
          "additionalProperties": {"type": "string"}
        },
        "environment": {
          "type": "object",
          "additionalProperties": {"type": "string"}
        }
      },
      "required": ["image"]
    }

    deploy-compose

    Input Schema:

    {
      "type": "object",
      "properties": {
        "compose_yaml": {"type": "string"},
        "project_name": {"type": "string"}
      },
      "required": ["compose_yaml", "project_name"]
    }

    get-logs

    Input Schema:

    {
      "type": "object",
      "properties": {
        "container_name": {"type": "string"}
      },
      "required": ["container_name"]
    }