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- Single machine deployment
- Stdio transport for client communication
- Local in-memory cache
- Ideal for: Development, testing, single-user scenarios
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- 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
3. Docker Compose with Observability
Use Case: Production with monitoring, debugging, team deployments- Complete observability stack
- Distributed tracing with Jaeger
- Log aggregation with Loki
- Metrics with Prometheus
- Unified dashboards in Grafana
- Inter-service communication via Docker network
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- 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
enkrypt_mcp_config.json
- Tool cache:
mcp_tools:{config_id}:{server_name} - Gateway config:
mcp_gateway_config:{config_id} - API key mapping:
mcp_key_to_id:{gateway_key}
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)
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_timeoutfrom config) - Round-robin or least-connections algorithm
5. Remote Gateway Deployment
Use Case: Centralized gateway, remote MCP clients, cloud deployment- 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.py
claude_desktop_config.json
- AWS
- GCP
- Azure
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
6. Hybrid Deployment
Use Case: Gateway in cloud, MCP servers on-premise or distributed- 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
- 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 operationsHorizontal Scaling (Scale Out)
When to use: High throughput, high availability, distributed clients Requirements:- External cache (Redis/KeyDB)
- Load balancer
- Stateless gateway design ✓ (already implemented)
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):- 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
- 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
- Increase
tool_execution_timeoutfor slow MCP servers - Decrease
guardrail_timeoutif using fast local guardrails - Set
connectivity_timeoutlow to fail fast on network issues
Async Guardrails
- Reduced latency (guardrails run in parallel)
- Improved throughput
- Better resource utilization
- 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:- 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
Troubleshooting Production Issues
High Latency
-
Check cache hit ratio:
-
Review timeout metrics:
-
Analyze traces in Jaeger:
- Identify slow MCP servers
- Look for guardrail bottlenecks
- Check network latency
High Error Rate
-
Check Grafana dashboards:
- Error rate by server
- Error types (auth, timeout, execution)
-
Review logs in Loki:
-
Common causes:
- MCP server crashes
- Network connectivity issues
- Invalid API keys
- Guardrail blocks
Cache Issues
-
Verify Redis connectivity:
-
Check Redis memory:
-
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