|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This is the **Docker MCP Gateway** - a CLI plugin that enables easy and secure running of Model Context Protocol (MCP) servers through Docker containers. The plugin acts as a gateway between AI clients and containerized MCP servers, providing isolation, security, and management capabilities. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +The codebase follows a gateway pattern where: |
| 12 | +- **AI Client** connects to the **MCP Gateway** |
| 13 | +- **MCP Gateway** (this CLI) manages multiple **MCP Servers** running in Docker containers |
| 14 | + |
| 15 | +Key architectural components: |
| 16 | +- **Gateway**: Core routing and protocol translation (`cmd/docker-mcp/internal/gateway/`) |
| 17 | +- **Client Management**: Handles connections to AI clients (`cmd/docker-mcp/client/`) |
| 18 | +- **Server Management**: Manages MCP server lifecycle (`cmd/docker-mcp/server/`) |
| 19 | +- **Catalog System**: Manages available MCP servers (`cmd/docker-mcp/catalog/`) |
| 20 | +- **Security**: Secrets management and OAuth flows (`cmd/docker-mcp/secret-management/`, `cmd/docker-mcp/oauth/`) |
| 21 | + |
| 22 | +## Development Commands |
| 23 | + |
| 24 | +### Building |
| 25 | +```bash |
| 26 | +# Build the CLI plugin locally |
| 27 | +make docker-mcp |
| 28 | + |
| 29 | +# Cross-compile for all platforms |
| 30 | +make docker-mcp-cross |
| 31 | +``` |
| 32 | + |
| 33 | +### Testing |
| 34 | +```bash |
| 35 | +# Run all tests |
| 36 | +make test |
| 37 | + |
| 38 | +# Run integration tests specifically |
| 39 | +make integration |
| 40 | + |
| 41 | +# Run long-lived integration tests |
| 42 | +go test -count=1 ./... -run 'TestLongLived' |
| 43 | + |
| 44 | +# Run specific tests by pattern |
| 45 | +go test -count=1 ./... -run 'TestIntegration' |
| 46 | + |
| 47 | +# Run a single test file |
| 48 | +go test ./cmd/docker-mcp/server/server_test.go |
| 49 | + |
| 50 | +# Run tests with coverage |
| 51 | +go test -cover ./... |
| 52 | +``` |
| 53 | + |
| 54 | +### Code Quality |
| 55 | +```bash |
| 56 | +# Format code |
| 57 | +make format |
| 58 | + |
| 59 | +# Run linter |
| 60 | +make lint |
| 61 | + |
| 62 | +# Run linter for specific platform |
| 63 | +make lint-linux |
| 64 | +make lint-darwin |
| 65 | + |
| 66 | +# Run Go vet (static analysis) |
| 67 | +go vet ./... |
| 68 | + |
| 69 | +# Run Go mod tidy to clean dependencies |
| 70 | +go mod tidy |
| 71 | +``` |
| 72 | + |
| 73 | +## Project Structure |
| 74 | + |
| 75 | +- `cmd/docker-mcp/` - Main CLI application entry point |
| 76 | +- `cmd/docker-mcp/internal/gateway/` - Core gateway implementation with client pooling, proxy management, and transport handling |
| 77 | +- `cmd/docker-mcp/internal/docker/` - Docker integration for container management |
| 78 | +- `cmd/docker-mcp/internal/mcp/` - MCP protocol implementations (stdio, SSE) |
| 79 | +- `cmd/docker-mcp/internal/desktop/` - Docker Desktop integration and authentication |
| 80 | +- `cmd/docker-mcp/catalog/` - Server catalog management commands |
| 81 | +- `cmd/docker-mcp/client/` - Client configuration and connection management |
| 82 | +- `cmd/docker-mcp/server/` - Server lifecycle management commands |
| 83 | +- `cmd/docker-mcp/tools/` - Tool execution and management |
| 84 | +- `examples/` - Usage examples and compose configurations |
| 85 | +- `docs/` - Technical documentation |
| 86 | + |
| 87 | +## Key Configuration Files |
| 88 | + |
| 89 | +The CLI uses these configuration files (typically in `~/.docker/mcp/`): |
| 90 | +- `docker-mcp.yaml` - Server catalog definitions |
| 91 | +- `registry.yaml` - Registry of enabled servers |
| 92 | +- `config.yaml` - Gateway configuration and options |
| 93 | + |
| 94 | +## Important Patterns |
| 95 | + |
| 96 | +### Transport Modes |
| 97 | +The gateway supports multiple transport modes: |
| 98 | +- `stdio` - Standard input/output (default) |
| 99 | +- `streaming` - HTTP streaming for multiple clients |
| 100 | +- `sse` - Server-sent events |
| 101 | + |
| 102 | +### Security Features |
| 103 | +- Container isolation for MCP servers |
| 104 | +- Secrets management via Docker Desktop |
| 105 | +- OAuth flow handling |
| 106 | +- API key and credential protection |
| 107 | +- Call interception and logging |
| 108 | + |
| 109 | +### Client Integration |
| 110 | +The system integrates with various AI clients: |
| 111 | +- VS Code / Cursor |
| 112 | +- Claude Desktop |
| 113 | +- Continue Dev |
| 114 | +- Custom MCP clients |
| 115 | + |
| 116 | +Configuration files for different clients are automatically managed in `cmd/docker-mcp/client/testdata/`. |
| 117 | + |
| 118 | +## CLI Plugin Development |
| 119 | + |
| 120 | +This is a Docker CLI plugin written in Go 1.24+. Key development patterns: |
| 121 | + |
| 122 | +### Plugin Installation |
| 123 | +The plugin is installed as `docker-mcp` and becomes available as `docker mcp <command>`. The Makefile handles building and installing to the correct Docker CLI plugins directory (`~/.docker/cli-plugins/`). |
| 124 | + |
| 125 | +### Command Structure |
| 126 | +Commands follow the Cobra CLI pattern with the main command tree defined in `cmd/docker-mcp/commands/`. Each major command area (catalog, server, client, etc.) has its own file. |
| 127 | + |
| 128 | +### Configuration Management |
| 129 | +The CLI uses YAML configuration files stored in `~/.docker/mcp/`: |
| 130 | +- Server definitions are loaded from catalog files |
| 131 | +- Runtime configuration is managed through config.yaml |
| 132 | +- Server enablement tracked in registry.yaml |
| 133 | + |
| 134 | +### Container Lifecycle |
| 135 | +MCP servers run as Docker containers with proper lifecycle management: |
| 136 | +- Images are pulled and validated before use |
| 137 | +- Containers have consistent naming patterns |
| 138 | +- Health checks and logging are built-in |
| 139 | +- Proper cleanup on shutdown |
| 140 | + |
| 141 | +### Testing Patterns |
| 142 | +- Integration tests require Docker daemon |
| 143 | +- Long-lived tests run actual container scenarios |
| 144 | +- Mock configurations in testdata directories |
| 145 | +- Use `go test -count=1` to disable test caching |
0 commit comments