# Cluster Deployment Guide MCPHub supports cluster deployment, allowing you to run multiple nodes that work together as a unified system. This enables: - **High Availability**: Distribute MCP servers across multiple nodes for redundancy - **Load Distribution**: Balance requests across multiple replicas of the same MCP server - **Sticky Sessions**: Ensure client sessions are routed to the same node consistently - **Centralized Management**: One coordinator manages the entire cluster ## Architecture MCPHub cluster has three operating modes: 1. **Standalone Mode** (Default): Single node operation, no cluster features 2. **Coordinator Mode**: Central node that manages the cluster, routes requests, and maintains session affinity 3. **Node Mode**: Worker nodes that register with the coordinator and run MCP servers ``` ┌─────────────────────────────────────────┐ │ Coordinator Node │ │ - Manages cluster state │ │ - Routes client requests │ │ - Maintains session affinity │ │ - Health monitoring │ └───────────┬─────────────────────────────┘ │ ┌───────┴───────────────────┐ │ │ ┌───▼────────┐ ┌────────▼────┐ │ Node 1 │ │ Node 2 │ │ - MCP A │ │ - MCP A │ │ - MCP B │ │ - MCP C │ └────────────┘ └─────────────┘ ``` ## Configuration ### Coordinator Configuration Create or update `mcp_settings.json` on the coordinator node: ```json { "mcpServers": { // Optional: coordinator can also run MCP servers "example": { "command": "npx", "args": ["-y", "example-mcp-server"] } }, "systemConfig": { "cluster": { "enabled": true, "mode": "coordinator", "coordinator": { "nodeTimeout": 15000, "cleanupInterval": 30000, "stickySessionTimeout": 3600000 }, "stickySession": { "enabled": true, "strategy": "consistent-hash", "cookieName": "MCPHUB_NODE", "headerName": "X-MCPHub-Node" } } } } ``` **Configuration Options:** - `nodeTimeout`: Time (ms) before marking a node as unhealthy (default: 15000) - `cleanupInterval`: Interval (ms) for cleaning up inactive nodes (default: 30000) - `stickySessionTimeout`: Session affinity timeout (ms) (default: 3600000 - 1 hour) - `stickySession.enabled`: Enable sticky session routing (default: true) - `stickySession.strategy`: Session affinity strategy: - `consistent-hash`: Hash-based routing (default) - `cookie`: Cookie-based routing - `header`: Header-based routing ### Node Configuration Create or update `mcp_settings.json` on each worker node: ```json { "mcpServers": { "amap": { "command": "npx", "args": ["-y", "@amap/amap-maps-mcp-server"] }, "playwright": { "command": "npx", "args": ["@playwright/mcp@latest", "--headless"] } }, "systemConfig": { "cluster": { "enabled": true, "mode": "node", "node": { "id": "node-1", "name": "Worker Node 1", "coordinatorUrl": "http://coordinator:3000", "heartbeatInterval": 5000, "registerOnStartup": true } } } } ``` **Configuration Options:** - `node.id`: Unique node identifier (auto-generated if not provided) - `node.name`: Human-readable node name (defaults to hostname) - `node.coordinatorUrl`: URL of the coordinator node (required) - `node.heartbeatInterval`: Heartbeat interval (ms) (default: 5000) - `node.registerOnStartup`: Auto-register on startup (default: true) ## Deployment Scenarios ### Scenario 1: Docker Compose Create a `docker-compose.yml`: ```yaml version: '3.8' services: coordinator: image: samanhappy/mcphub:latest ports: - "3000:3000" volumes: - ./coordinator-config.json:/app/mcp_settings.json - coordinator-data:/app/data environment: - NODE_ENV=production node1: image: samanhappy/mcphub:latest volumes: - ./node1-config.json:/app/mcp_settings.json - node1-data:/app/data environment: - NODE_ENV=production depends_on: - coordinator node2: image: samanhappy/mcphub:latest volumes: - ./node2-config.json:/app/mcp_settings.json - node2-data:/app/data environment: - NODE_ENV=production depends_on: - coordinator volumes: coordinator-data: node1-data: node2-data: ``` Start the cluster: ```bash docker-compose up -d ``` ### Scenario 2: Kubernetes Create Kubernetes manifests: **Coordinator Deployment:** ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: mcphub-coordinator spec: replicas: 1 selector: matchLabels: app: mcphub-coordinator template: metadata: labels: app: mcphub-coordinator spec: containers: - name: mcphub image: samanhappy/mcphub:latest ports: - containerPort: 3000 volumeMounts: - name: config mountPath: /app/mcp_settings.json subPath: mcp_settings.json volumes: - name: config configMap: name: mcphub-coordinator-config --- apiVersion: v1 kind: Service metadata: name: mcphub-coordinator spec: selector: app: mcphub-coordinator ports: - port: 3000 targetPort: 3000 type: LoadBalancer ``` **Worker Node Deployment:** ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: mcphub-node spec: replicas: 3 selector: matchLabels: app: mcphub-node template: metadata: labels: app: mcphub-node spec: containers: - name: mcphub image: samanhappy/mcphub:latest volumeMounts: - name: config mountPath: /app/mcp_settings.json subPath: mcp_settings.json volumes: - name: config configMap: name: mcphub-node-config ``` Apply the manifests: ```bash kubectl apply -f coordinator.yaml kubectl apply -f nodes.yaml ``` ### Scenario 3: Manual Deployment **On Coordinator (192.168.1.100):** ```bash # Install MCPHub npm install -g @samanhappy/mcphub # Configure as coordinator cat > mcp_settings.json < mcp_settings.json <50 nodes), consider: - Increasing coordinator resources - Tuning heartbeat intervals - Using header-based sticky sessions (lower overhead) ### Network Latency Minimize latency between coordinator and nodes: - Deploy in the same datacenter/region - Use low-latency networking - Consider coordinator placement near clients ### Session Timeout Balance session timeout with resource usage: - Shorter timeout: Less memory, more re-routing - Longer timeout: Better stickiness, more memory Default is 1 hour, adjust based on your use case. ## Limitations 1. **Stateful Sessions**: Node-local state is lost if a node fails. Use external storage for persistent state. 2. **Single Coordinator**: Currently supports one coordinator. Consider load balancing at the infrastructure level. 3. **Network Partitions**: Nodes that lose connection to coordinator will be marked unhealthy. ## Best Practices 1. **Use Groups**: Organize MCP servers into groups for easier management 2. **Monitor Health**: Set up alerts for unhealthy nodes 3. **Version Consistency**: Run the same MCPHub version across all nodes 4. **Resource Planning**: Allocate appropriate resources based on MCP server requirements 5. **Backup Configuration**: Keep coordinator config backed up 6. **Gradual Rollout**: Test cluster configuration with a small number of nodes first ## See Also - [Docker Deployment](../deployment/docker.md) - [Kubernetes Deployment](../deployment/kubernetes.md) - [High Availability Setup](../deployment/high-availability.md)