|
| 1 | +# RFC: Docker Integration for MCPM |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +This RFC proposes adding native Docker integration to MCPM (Model Context Protocol Manager), enabling seamless orchestration between MCP server profiles and Docker Compose services with bidirectional synchronization. |
| 6 | + |
| 7 | +## Motivation |
| 8 | + |
| 9 | +Currently, MCPM excels at managing MCP servers across various clients through profiles and a router system. However, for production deployments, many users need Docker containerization for: |
| 10 | + |
| 11 | +1. **Isolation**: Containerized MCP servers provide better security and resource isolation |
| 12 | +2. **Scalability**: Docker Compose enables easy scaling and load balancing |
| 13 | +3. **Production Readiness**: Container orchestration with health checks, restart policies, and monitoring |
| 14 | +4. **Environment Consistency**: Consistent deployment across development, staging, and production |
| 15 | +5. **Dependency Management**: Self-contained environments with all dependencies |
| 16 | + |
| 17 | +This proposal bridges the gap between MCPM's excellent client management and Docker's production deployment capabilities. |
| 18 | + |
| 19 | +## Detailed Design |
| 20 | + |
| 21 | +### 1. New Command Structure |
| 22 | + |
| 23 | +Add a new top-level `docker` command group with subcommands: |
| 24 | + |
| 25 | +```bash |
| 26 | +mcpm docker sync PROFILE_NAME # Sync profile to Docker Compose |
| 27 | +mcpm docker status # Show Docker integration status |
| 28 | +mcpm docker deploy [SERVICES...] # Deploy Docker services |
| 29 | +mcpm docker generate PROFILE_NAME # Generate Docker Compose from profile |
| 30 | +``` |
| 31 | + |
| 32 | +### 2. Architecture Components |
| 33 | + |
| 34 | +#### A. DockerIntegration Class (`mcpm/commands/docker.py`) |
| 35 | +- Main orchestrator for Docker operations |
| 36 | +- Manages server-to-Docker mappings |
| 37 | +- Handles Docker Compose generation and deployment |
| 38 | +- Provides status monitoring |
| 39 | + |
| 40 | +#### B. DockerSyncOperations Class (`mcpm/commands/target_operations/docker_sync.py`) |
| 41 | +- Bidirectional sync operations |
| 42 | +- Conflict resolution strategies |
| 43 | +- Change detection and smart sync |
| 44 | +- Integration with existing target operations |
| 45 | + |
| 46 | +#### C. Enhanced Profile Schema |
| 47 | +Future enhancement to add Docker metadata to profiles: |
| 48 | +```python |
| 49 | +class Profile(BaseModel): |
| 50 | + name: str |
| 51 | + api_key: Optional[str] |
| 52 | + servers: list[ServerConfig] |
| 53 | + docker_metadata: Optional[DockerMetadata] = None # New field |
| 54 | + |
| 55 | +class DockerMetadata(BaseModel): |
| 56 | + compose_file: Optional[str] = "docker-compose.yml" |
| 57 | + auto_deploy: bool = False |
| 58 | + conflict_resolution: str = "profile_wins" |
| 59 | + last_sync_hash: Optional[str] = None |
| 60 | +``` |
| 61 | + |
| 62 | +### 3. Server Mapping System |
| 63 | + |
| 64 | +#### A. MCP Server → Docker Service Mapping |
| 65 | +```python |
| 66 | +server_mappings = { |
| 67 | + 'postgresql': { |
| 68 | + 'image': 'postgres:16-alpine', |
| 69 | + 'environment': ['POSTGRES_USER=${POSTGRES_USER:-mcpuser}', ...], |
| 70 | + 'ports': ['5432:5432'], |
| 71 | + 'volumes': ['postgres-data:/var/lib/postgresql/data'], |
| 72 | + 'networks': ['mcp-network'], |
| 73 | + 'healthcheck': {...} |
| 74 | + }, |
| 75 | + 'context7': {...}, |
| 76 | + 'github': {...}, |
| 77 | + 'obsidian': {...} |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +#### B. Detection Logic |
| 82 | +- **Name-based**: Direct matching (postgresql → postgresql service) |
| 83 | +- **Package-based**: NPM package detection (@modelcontextprotocol/server-postgres → postgresql) |
| 84 | +- **Command-based**: Command line analysis for custom servers |
| 85 | + |
| 86 | +### 4. Bidirectional Sync |
| 87 | + |
| 88 | +#### A. Sync Directions |
| 89 | +1. **Profile → Docker**: Generate Docker Compose from MCPM profile |
| 90 | +2. **Docker → Profile**: Create/update MCPM profile from Docker services |
| 91 | +3. **Bidirectional**: Intelligent sync with conflict resolution |
| 92 | + |
| 93 | +#### B. Conflict Resolution Strategies |
| 94 | +- `profile_wins`: MCPM profile takes precedence |
| 95 | +- `docker_wins`: Docker Compose takes precedence |
| 96 | +- `manual`: Require manual intervention |
| 97 | +- `merge`: Intelligent merging (future enhancement) |
| 98 | + |
| 99 | +#### C. Change Detection |
| 100 | +- File hash comparison for Docker Compose files |
| 101 | +- Profile modification timestamps |
| 102 | +- Service configuration checksums |
| 103 | + |
| 104 | +### 5. Integration Points |
| 105 | + |
| 106 | +#### A. Command Registration |
| 107 | +Add to `mcpm/cli.py`: |
| 108 | +```python |
| 109 | +from mcpm.commands import docker |
| 110 | +main.add_command(docker.docker, name="docker") |
| 111 | +``` |
| 112 | + |
| 113 | +#### B. Target Operations Extension |
| 114 | +Extend existing target operations (`add`, `remove`, `transfer`) to optionally sync with Docker: |
| 115 | +```bash |
| 116 | +mcpm add postgresql --target %production --sync-docker |
| 117 | +mcpm rm postgresql --target %production --sync-docker |
| 118 | +``` |
| 119 | + |
| 120 | +#### C. Router Integration |
| 121 | +Future enhancement to add Docker service discovery to the router: |
| 122 | +- Health monitoring of containerized servers |
| 123 | +- Automatic port mapping |
| 124 | +- Load balancing across container replicas |
| 125 | + |
| 126 | +### 6. Docker Compose Structure |
| 127 | + |
| 128 | +Generated Docker Compose files include: |
| 129 | + |
| 130 | +#### A. Standard Networks |
| 131 | +```yaml |
| 132 | +networks: |
| 133 | + mcp-network: |
| 134 | + driver: bridge |
| 135 | + ipam: |
| 136 | + config: |
| 137 | + - subnet: 10.200.0.0/16 |
| 138 | + mcp-management: |
| 139 | + driver: bridge |
| 140 | + ipam: |
| 141 | + config: |
| 142 | + - subnet: 10.201.0.0/16 |
| 143 | +``` |
| 144 | +
|
| 145 | +#### B. Service Template |
| 146 | +```yaml |
| 147 | +services: |
| 148 | + postgresql: |
| 149 | + image: postgres:16-alpine |
| 150 | + container_name: mcp-postgresql |
| 151 | + environment: |
| 152 | + - POSTGRES_USER=${POSTGRES_USER:-mcpuser} |
| 153 | + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password} |
| 154 | + - POSTGRES_DB=${POSTGRES_DB:-mcpdb} |
| 155 | + ports: |
| 156 | + - "5432:5432" |
| 157 | + volumes: |
| 158 | + - postgres-data:/var/lib/postgresql/data |
| 159 | + networks: |
| 160 | + - mcp-network |
| 161 | + restart: unless-stopped |
| 162 | + healthcheck: |
| 163 | + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-mcpuser}"] |
| 164 | + interval: 10s |
| 165 | + timeout: 5s |
| 166 | + retries: 3 |
| 167 | + start_period: 30s |
| 168 | +``` |
| 169 | +
|
| 170 | +## Implementation Plan |
| 171 | +
|
| 172 | +### Phase 1: Core Docker Commands (Week 1-2) |
| 173 | +- [x] Implement `DockerIntegration` class |
| 174 | +- [x] Add `mcpm docker` command group |
| 175 | +- [x] Basic profile → Docker sync |
| 176 | +- [x] Docker service status monitoring |
| 177 | + |
| 178 | +### Phase 2: Bidirectional Sync (Week 3-4) |
| 179 | +- [x] Implement `DockerSyncOperations` class |
| 180 | +- [x] Docker → profile sync |
| 181 | +- [x] Conflict resolution strategies |
| 182 | +- [ ] Change detection and smart sync |
| 183 | + |
| 184 | +### Phase 3: Enhanced Integration (Month 2) |
| 185 | +- [ ] Extend existing target operations with Docker sync |
| 186 | +- [ ] Enhanced profile schema with Docker metadata |
| 187 | +- [ ] Router integration for container health monitoring |
| 188 | +- [ ] Comprehensive testing and documentation |
| 189 | + |
| 190 | +### Phase 4: Advanced Features (Month 3+) |
| 191 | +- [ ] Multi-environment support (dev/staging/prod) |
| 192 | +- [ ] Container scaling and load balancing |
| 193 | +- [ ] Advanced conflict resolution (merge strategies) |
| 194 | +- [ ] Performance monitoring and metrics |
| 195 | + |
| 196 | +## Backward Compatibility |
| 197 | + |
| 198 | +This proposal maintains full backward compatibility: |
| 199 | + |
| 200 | +1. **Existing Profiles**: All current profiles continue to work unchanged |
| 201 | +2. **Existing Commands**: No changes to existing command behavior |
| 202 | +3. **Optional Feature**: Docker integration is entirely opt-in |
| 203 | +4. **Schema Evolution**: Docker metadata is optional and backward-compatible |
| 204 | + |
| 205 | +## Testing Strategy |
| 206 | + |
| 207 | +### Unit Tests |
| 208 | +- Server detection and mapping logic |
| 209 | +- Docker Compose generation |
| 210 | +- Bidirectional sync operations |
| 211 | +- Conflict resolution strategies |
| 212 | + |
| 213 | +### Integration Tests |
| 214 | +- End-to-end profile → Docker → profile workflows |
| 215 | +- Docker deployment and health checks |
| 216 | +- Multi-service synchronization |
| 217 | +- Error handling and recovery |
| 218 | + |
| 219 | +### Compatibility Tests |
| 220 | +- Existing MCPM functionality unchanged |
| 221 | +- Various Docker environments (local, remote, CI/CD) |
| 222 | +- Different MCP server types and configurations |
| 223 | + |
| 224 | +## Alternatives Considered |
| 225 | + |
| 226 | +### 1. External Tool Approach |
| 227 | +**Rejected**: Maintain separate tools for MCPM and Docker |
| 228 | +- **Pros**: No changes to MCPM core |
| 229 | +- **Cons**: Poor user experience, manual coordination required, configuration drift |
| 230 | + |
| 231 | +### 2. Plugin System |
| 232 | +**Future Enhancement**: Implement as MCPM plugin |
| 233 | +- **Pros**: Modular, extensible |
| 234 | +- **Cons**: Added complexity, plugin infrastructure needed |
| 235 | + |
| 236 | +### 3. Docker-First Approach |
| 237 | +**Rejected**: Make Docker the primary deployment method |
| 238 | +- **Pros**: Production-ready by default |
| 239 | +- **Cons**: Breaking change, removes client flexibility |
| 240 | + |
| 241 | +## Risks and Mitigations |
| 242 | + |
| 243 | +### Risk 1: Docker Dependency |
| 244 | +**Mitigation**: Docker integration is optional, graceful fallback when Docker unavailable |
| 245 | + |
| 246 | +### Risk 2: Configuration Complexity |
| 247 | +**Mitigation**: Sensible defaults, comprehensive documentation, example configurations |
| 248 | + |
| 249 | +### Risk 3: Performance Impact |
| 250 | +**Mitigation**: Lazy loading, efficient change detection, background operations |
| 251 | + |
| 252 | +### Risk 4: Security Concerns |
| 253 | +**Mitigation**: Secure defaults, environment variable handling, container isolation |
| 254 | + |
| 255 | +## Success Metrics |
| 256 | + |
| 257 | +1. **Adoption**: >20% of MCPM users enable Docker integration within 6 months |
| 258 | +2. **Reliability**: >99% successful sync operations |
| 259 | +3. **Performance**: <2s for typical profile → Docker sync |
| 260 | +4. **Community**: Positive feedback, contributions, and documentation improvements |
| 261 | + |
| 262 | +## Conclusion |
| 263 | + |
| 264 | +This Docker integration proposal provides significant value to MCPM users by bridging client management and production deployment. The design maintains backward compatibility while enabling powerful new workflows for containerized MCP server deployments. |
| 265 | + |
| 266 | +The phased implementation allows for iterative development and community feedback, ensuring a robust and well-tested feature that enhances MCPM's production readiness without compromising its core strengths. |
0 commit comments