จากประสบการณ์ตรงของผู้เขียนที่ได้ deploy MCP server จริงในระบบ production ที่รองรับ concurrent requests มากกว่า 10,000 requests ต่อนาที บทความนี้จะแชร์ architecture pattern, performance tuning และ cost optimization ที่ใช้งานได้จริง ผมพบว่า supergateway เป็น tool ที่ทรงพลังมากสำหรับการ bridge ระหว่าง stdio-based MCP server ไปยัง HTTP/SSE แต่มี gotchas หลายอย่างที่ต้องระวังเมื่อ scale ขึ้นระดับ production โดยเฉพาะเรื่อง connection lifecycle, memory leak และ tool schema compatibility กับ LLM API ภายนอก

สถาปัตยกรรม Supergateway ในมุมมอง Production

Supergateway ทำหน้าที่เป็น proxy layer ที่แปลง stdio MCP protocol ไปเป็น HTTP หรือ Server-Sent Events ทำให้ MCP server ที่ออกแบบมาสำหรับ local execution สามารถ expose ผ่าน network ได้อย่างปลอดภัย

Docker Compose สำหรับ Single-node Production

version: '3.8'

services:
  mcp-supergateway:
    image: node:20-alpine
    container_name: mcp-supergateway-prod
    restart: unless-stopped
    working_dir: /app
    command: >
      sh -c "npm install -g supergateway &&
             supergateway --stdio 'npx -y @modelcontextprotocol/server-filesystem /data'
             --port 8080
             --baseUrl http://0.0.0.0:8080
             --ssePath /sse
             --messagePath /message
             --logLevel info"
    ports:
      - "8080:8080"
    volumes:
      - /host/data:/data:ro
    environment:
      - NODE_ENV=production
      - MCP_TIMEOUT=30000
      - UV_THREADPOOL_SIZE=16
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G
        reservations:
          cpus: '1.0'
          memory: 1G
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - mcp-network

  nginx-lb:
    image: nginx:alpine
    container_name: nginx-lb
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./certs:/etc/nginx/certs:ro
    depends_on:
      - mcp-supergateway
    networks:
      - mcp-network

networks:
  mcp-network:
    driver: bridge

Horizontal Scaling ด้วย Docker Swarm

# docker-stack.yml สำหรับ Docker Swarm
version: '3.8'

services:
  mcp-supergateway:
    image: your-registry/mcp-supergateway:latest
    deploy:
      mode: replicated
      replicas: 4
      update_config:
        parallelism: 2
        delay: 10s
        order: start-first
      rollback_config:
        parallelism: 0
        order: stop-first
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
      placement:
        constraints:
          - node.role == worker
        preferences:
          - spread: node.labels.zone
    resources:
      limits:
        cpus: '1.5'
        memory: 1.5G
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 15s
      timeout: 5s
      retries: 3
    networks:
      - mcp-overlay

  mcp-lb:
    image: traefik:v3.0
    command:
      - "--providers.swarm=true"
      - "--entrypoints.web