Skip to main content

Overview

The Secure MCP Gateway supports multiple deployment patterns to meet different scalability, availability, and security requirements. This guide covers common architectures from single-instance local deployments to distributed cloud deployments.

Architecture Patterns

1. Local Development

Use Case: Development, testing, personal use
Characteristics:
  • Single machine deployment
  • Stdio transport for client communication
  • Local in-memory cache
  • Ideal for: Development, testing, single-user scenarios
Setup:
This is the simplest deployment pattern. Configuration is stored locally at ~/.enkrypt/enkrypt_mcp_config.json.

2. Docker Single Instance

Use Case: Production single-server, consistent environment
Characteristics:
  • Containerized gateway with volume-mounted config
  • Includes Python 3.12, Node.js 22.x runtime
  • Supports both Python and JavaScript MCP servers
  • Local cache within container
Setup:

3. Docker Compose with Observability

Use Case: Production with monitoring, debugging, team deployments
Characteristics:
  • Complete observability stack
  • Distributed tracing with Jaeger
  • Log aggregation with Loki
  • Metrics with Prometheus
  • Unified dashboards in Grafana
  • Inter-service communication via Docker network
Setup:
Observability Features:

Distributed Tracing

Track requests across gateway, clients, and MCP servers. Visualize latency bottlenecks.

Log Aggregation

Centralized logs from all services. Query with LogQL, correlate with traces.

Metrics Monitoring

Request rates, error rates, cache hit ratios, timeout metrics, OAuth metrics.

Grafana Dashboards

Pre-configured dashboards for gateway health, performance, and security insights.

4. Distributed with External Cache

Use Case: Multi-instance deployments, high availability, load balancing
Characteristics:
  • Multiple gateway instances behind load balancer
  • Shared Redis/KeyDB for distributed caching
  • Session affinity not required (stateless gateway)
  • Horizontal scaling for high throughput
  • Fault tolerance via redundancy
Configuration:
enkrypt_mcp_config.json
Cache Keys (MD5 hashed for security):
  • Tool cache: mcp_tools:{config_id}:{server_name}
  • Gateway config: mcp_gateway_config:{config_id}
  • API key mapping: mcp_key_to_id:{gateway_key}
Scaling Considerations:
1

Cache Sizing

Estimate cache size based on:
  • Number of MCP servers: N
  • Average tools per server: T
  • Cache entry size: ~1-5 KB per server
  • Total: N * (T * 1KB + 5KB config)
Example: 100 servers, 20 tools each = ~500 KB cache
2

Redis Configuration

Recommended Redis/KeyDB settings:
3

Load Balancer Setup

  • Use HTTP health check: GET /health (port 8000)
  • No session affinity needed (stateless)
  • Timeout: 30s (or default_timeout from config)
  • Round-robin or least-connections algorithm

5. Remote Gateway Deployment

Use Case: Centralized gateway, remote MCP clients, cloud deployment
Characteristics:
  • Gateway hosted in cloud (AWS, GCP, Azure)
  • Clients connect via HTTPS (streamable HTTP transport)
  • TLS termination at load balancer
  • Distributed caching with managed Redis
  • Centralized monitoring and logging
  • API key authentication over HTTPS
Gateway Configuration:
gateway.py
Client Configuration:
claude_desktop_config.json
Security Considerations:
  • Always use HTTPS for remote deployments
  • Store API keys in environment variables or secrets manager
  • Enable rate limiting at load balancer
  • Use VPC/private subnets for internal services
  • Rotate API keys regularly with CLI: secure-mcp-gateway apikey rotate
Cloud Deployment Examples:
Architecture:
  • ALB: Application Load Balancer with TLS
  • ECS Fargate: Containerized gateway instances
  • ElastiCache Redis: Managed cache cluster
  • CloudWatch: Logs and metrics
  • X-Ray: Distributed tracing
Terraform Example:

6. Hybrid Deployment

Use Case: Gateway in cloud, MCP servers on-premise or distributed
Characteristics:
  • Gateway in cloud for scalability
  • MCP servers on-premise for data security
  • Secure connectivity via VPN or private link
  • Sensitive data never leaves private network
  • Gateway acts as secure proxy
Use Cases:
  • Accessing internal databases without exposing them
  • File system operations on private networks
  • Compliance requirements (HIPAA, SOC 2)
  • Legacy system integration

Scaling Strategies

Vertical Scaling (Scale Up)

When to use: Initial growth, simpler operations
Limits: Single machine CPU/memory capacity (~16 cores, 64GB RAM typical)

Horizontal Scaling (Scale Out)

When to use: High throughput, high availability, distributed clients Requirements:
  1. External cache (Redis/KeyDB)
  2. Load balancer
  3. Stateless gateway design ✓ (already implemented)
Scaling Steps:
1

Enable External Cache

Update enkrypt_mcp_config.json:
2

Deploy Redis Cluster

For high availability:
3

Launch Gateway Instances

4

Configure Load Balancer

Nginx Example:

Auto-Scaling

Kubernetes HPA (Horizontal Pod Autoscaler):
Metrics to Monitor:
  • CPU Utilization: Target 60-70%
  • Memory Usage: Target < 80%
  • Request Rate: Requests/second
  • Response Time: p50, p95, p99 latency
  • Error Rate: % failed requests
  • Cache Hit Ratio: > 80% ideal

Performance Optimization

Cache Configuration

Tuning Guidelines:
  • Frequent tool changes: Reduce to 1-2 hours
  • Stable environments: Increase to 12-24 hours
  • High cache hit ratio: Longer expiration acceptable
  • Low memory: Shorter expiration to free space

Timeout Configuration

Optimization:
  • Increase tool_execution_timeout for slow MCP servers
  • Decrease guardrail_timeout if using fast local guardrails
  • Set connectivity_timeout low to fail fast on network issues

Async Guardrails

Benefits:
  • Reduced latency (guardrails run in parallel)
  • Improved throughput
  • Better resource utilization
Trade-offs:
  • Slightly higher complexity
  • Potential for race conditions in logging

High Availability

Components for HA

Multiple Gateway Instances

  • Minimum 3 instances for quorum
  • Deploy across availability zones
  • Use health checks for automatic failover

Redis Sentinel

  • 3-node Sentinel cluster
  • Automatic failover (< 30s)
  • Monitors master health

Load Balancer

  • Active health checks every 10s
  • Remove unhealthy instances
  • SSL/TLS termination

Observability

  • Real-time alerts on failures
  • Distributed tracing for debugging
  • Historical metrics for capacity planning

Disaster Recovery

Backup Strategy:
Restore Procedure:
Multi-Region Setup:
  • Deploy gateway in multiple regions
  • Use global load balancer (AWS Route 53, Cloudflare)
  • Replicate Redis across regions (async replication)
  • Geo-routing for low latency

Cost Optimization

Resource Sizing Guidelines

Cost Reduction Tips:
  • Use spot/preemptible instances for non-critical environments
  • Enable auto-scaling to scale down during low traffic
  • Use reserved instances for predictable workloads (40-60% savings)
  • Optimize cache expiration to reduce Redis memory
  • Consider managed services (ECS Fargate, Cloud Run) for operational simplicity

Security Best Practices

Production Security Checklist:
  • ✓ Use HTTPS for all remote connections
  • ✓ Store API keys in secrets manager (AWS Secrets Manager, HashiCorp Vault)
  • ✓ Enable Redis authentication (requirepass)
  • ✓ Use VPC/private subnets for internal services
  • ✓ Enable TLS for OTLP endpoints
  • ✓ Rotate API keys every 90 days
  • ✓ Enable guardrails on production servers
  • ✓ Set up alerting for security events
  • ✓ Regular security audits and penetration testing
  • ✓ Keep dependencies updated

Troubleshooting Production Issues

High Latency

  1. Check cache hit ratio:
  2. Review timeout metrics:
  3. Analyze traces in Jaeger:
    • Identify slow MCP servers
    • Look for guardrail bottlenecks
    • Check network latency

High Error Rate

  1. Check Grafana dashboards:
    • Error rate by server
    • Error types (auth, timeout, execution)
  2. Review logs in Loki:
  3. Common causes:
    • MCP server crashes
    • Network connectivity issues
    • Invalid API keys
    • Guardrail blocks

Cache Issues

  1. Verify Redis connectivity:
  2. Check Redis memory:
  3. Clear cache if stale:

Next Steps

External Cache Setup

Configure Redis/KeyDB for distributed caching

Load Balancing

Set up Nginx or cloud load balancers

Monitoring & Alerting

Configure alerts for production incidents

Security Hardening

Implement production security controls