Docker MCP Gateway

repository·main·Indexed 23 days ago

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

A CLI plugin that provides a secure, container-based way to run and manage Model Context Protocol (MCP) servers. It acts as a central gateway allowing AI clients, such as Cursor or Claude, to discover and interact with tools, resources, and prompts hosted in isolated Docker containers. The gateway includes support for OpenTelemetry (OTEL) tracking, an embedded SQLite database for configuration and server catalogs, and integration with the ChatGPT App UI.

Tokens
65.2K
Snippets
169
Records
398
Agent score
77%

What's inside docker-mcp-gateway

  1. Security best practices for profiles

    main

    When managing profiles, follow these security guidelines:

    • Secrets Management: Use docker mcp secret set for sensitive values (API keys, tokens). Never use docker mcp profile config for secrets; that command is only for non-sensitive configuration.
    • Least Privilege: Use docker mcp profile tools to disable all tools (--disable-all) and then explicitly --enable only the specific tools required for the task.
    • Environment Isolation: Create separate profiles for dev, staging, and production to ensure production environments do not have access to development tools or debug servers.
    • Registry Security: Use private OCI registries for proprietary configurations and review all server references before importing from external sources.
  2. Catalog Precedence and Conflict Resolution

    main

    When multiple catalogs contain a server with the same name, the gateway follows a "last loaded wins" precedence order. The order of loading is:

    1. Built-in Gateway catalogs (future expansion point)
    2. Docker official catalog (docker-mcp.yaml)
    3. User configured catalogs (loaded when --use-configured-catalogs is used)
    4. CLI-specified catalogs (provided via --catalog or --additional-catalog flags)
  3. The Docker MCP OAuth Model

    main

    The Docker MCP OAuth model centralizes authorization logic to simplify development. Key characteristics include:

    • Centralized Implementation: Docker implements the OAuth flows, so third-party developers do not have to.
    • Developer Portal: Third parties can register OAuth clients by configuring client_id, client_secret, and redirect_uri via a developer portal.
    • Secure Secret Management: Docker provides a secure way to store and access secrets on the user's machine, leveraging the fact that Docker Desktop is already running in the background.
    • Trusted Environment: Because Docker Desktop operates in a trusted environment on the user's machine, it can act as a secure proxy for clients that might otherwise lack sufficient trust levels.
  4. Manage MCP profiles

    main

    Servers are organized into profiles. A profile groups related MCP servers together and can be connected to clients, exported, or shared via OCI registries.

    Servers in a profile can be sourced from:

    • Catalog references: catalog://mcp/docker-mcp-catalog/github
    • OCI image references: docker://my-server:latest
    • MCP Registry references: https://registry.modelcontextprotocol.io/v0/servers/<id>
    • Local file references: file://./server.yaml

    Note: Ensure you run docker mcp catalog pull mcp/docker-mcp-catalog before managing profiles that use the default catalog.

    # Create a new profile
    docker mcp profile create --name dev-tools \
      --server catalog://mcp/docker-mcp-catalog/github
    
    # Create a profile and connect it to a client
    docker mcp profile create --name dev-tools \
      --server catalog://mcp/docker-mcp-catalog/github \
      --connect cursor
    
    # List all profiles
    docker mcp profile list
    
    # Show profile details
    docker mcp profile show <profile-id>
    
    # Remove a profile
    docker mcp profile remove <profile-id>
    
    # Export/import profiles
    docker mcp profile export <profile-id> output.yaml
    docker mcp profile import input.yaml
    
    # Push/pull profiles to OCI registries
    docker mcp profile push <profile-id> <oci-reference>
    docker mcp profile pull <oci-reference>
  5. Understand Catalog Precedence

    main

    When the Docker MCP Gateway loads, it resolves server names using a specific precedence order. If multiple catalogs define a server with the same name, the last-loaded catalog wins.

    1. Docker Official Catalog: Always loaded first (base layer).
    2. Configured Catalogs: User-imported catalogs.
    3. CLI-specified Catalogs: Catalogs passed via the --catalog flag (highest precedence).
  6. How reloadConfiguration works

    main

    The reloadConfiguration process is responsible for synchronizing the gateway's state with the current configuration.

    When reloadConfiguration is triggered:

    • It extracts capabilities from the current configuration.
    • It updates the internal Server.
    • It starts up the server to apply these changes.

    Note on Dynamic Capabilities: If you are running servers that raise change notifications, their capabilities must also be reloaded during this process. Additionally, any updates to capabilities during a reload will cause change events to be sent to all currently connected clients.

  7. How Distributed Tracing works in the MCP Gateway

    main

    The gateway uses distributed tracing to provide visibility into the flow of an MCP request. Spans are created to track the hierarchy from the gateway execution down to specific server operations.

    Span Hierarchy Example

    gateway.run
    ├── tools/list
    ├── prompts/list
    ├── resources/list
    ├── resourceTemplates/list
    ├── mcp.tool.call
    │   └── [tool execution]
    ├── mcp.prompt.get
    │   └── [prompt retrieval]
    ├── mcp.resource.read
    │   └── [resource read]
    └── mcp.resource_template.read

    Each span captures the operation name, server information, duration, error details, and input parameters (like tool names or resource URIs).

  8. Verify Docker MCP image signatures

    main

    Signature verification is enabled by default for images in the Docker Hub mcp/ namespace.

    • Requirement: To enable verification, images must be referenced by their digest.
    • Disabling Verification: You can opt-out of signature verification using the --verify-signatures=false flag.
    • Third-party Images: Images outside the mcp/ namespace are not verified by Docker MCP signatures; their security depends on your specific catalog or profile configuration.
  9. Telemetry Behavior: Docker Desktop vs. Open Source

    main

    The telemetry implementation is designed to respect user privacy and existing Docker ecosystems:

    • Docker Desktop: Automatically configures an OTEL endpoint (typically a Unix socket). The gateway inherits this configuration and exports metrics to the Docker Desktop backend, which processes and filters them.
    • Open Source Docker: Does not include OTEL configuration in the Docker context. In this environment, the gateway's telemetry code runs but does not export any metrics, ensuring no external connections are made and maintaining privacy by default.
  10. How the Docker MCP Gateway message flow works

    main

    The Docker MCP Gateway acts as an intermediary between an MCP Client (like an LLM interface) and one or more Tool Servers. Instead of the Client communicating directly with a single server, it communicates with the Gateway, which aggregates tools from multiple backend Tool Servers.

    Discovery

    1. The Client sends a tools/list request to the Gateway.
    2. The Gateway forwards tools/list requests to the underlying Tool Servers.
    3. The Tool Servers return their specific tool lists to the Gateway.
    4. The Gateway combines these lists into a single, unified list and returns it to the Client.

    Tool Selection

    The LLM (via the Client) analyzes the combined tool list and selects a specific tool to use.

    Invocation

    1. The Client sends a tools/call request to the Gateway specifying the tool to use.
    2. The Gateway routes the tools/call request to the appropriate Tool Server.
    3. The Tool Server executes the tool and returns the result to the Gateway.
    4. The Gateway passes the tool result back to the Client.
    5. The Client provides the result to the LLM for processing.