Production Deployment
Best practices for deploying TONL-MCP Bridge in production environments.
Pre-Deployment Checklist
Before deploying to production:
- [ ] Environment variables configured
- [ ] Authentication token generated
- [ ] HTTPS/TLS configured (reverse proxy)
- [ ] Monitoring setup
- [ ] Backup strategy defined
- [ ] Resource limits set
- [ ] Testing completed
Security Configuration
Authentication
Generate secure token:
# Linux/macOS
openssl rand -base64 32
# Or use a password manager
# Example output: kJ8mN2pQ4rS6tU8vW0xY2zA4bC6dE8fG0hI2jK4lM6n=Set as environment variable:
export TONL_AUTH_TOKEN=kJ8mN2pQ4rS6tU8vW0xY2zA4bC6dE8fG0hI2jK4lM6n=HTTPS Setup
Use reverse proxy (nginx example):
server {
listen 443 ssl http2;
server_name api.yourdomain.com;
ssl_certificate /etc/ssl/certs/cert.pem;
ssl_certificate_key /etc/ssl/private/key.pem;
# Strong SSL configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Pass through Authorization header
proxy_set_header Authorization $http_authorization;
proxy_pass_header Authorization;
}
}
# Redirect HTTP to HTTPS
server {
listen 80;
server_name api.yourdomain.com;
return 301 https://$server_name$request_uri;
}Environment Variables
Never hardcode secrets. Use environment variables:
# .env file (never commit this!)
TONL_AUTH_TOKEN=your-secure-token
NODE_ENV=production
PORT=3000Load with Docker:
docker run -d \
--env-file .env \
-p 3000:3000 \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestOr docker-compose:
services:
tonl-server:
image: ghcr.io/kryptomrx/tonl-mcp-bridge:latest
env_file:
- .envResource Management
Memory Limits
Set appropriate limits:
docker run -d \
--memory="512m" \
--memory-swap="1g" \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestdocker-compose:
services:
tonl-server:
image: ghcr.io/kryptomrx/tonl-mcp-bridge:latest
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.5'
memory: 256MCPU Limits
Prevent CPU exhaustion:
docker run -d \
--cpus="1.0" \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestMonitoring
Health Checks
Docker health check:
services:
tonl-server:
image: ghcr.io/kryptomrx/tonl-mcp-bridge:latest
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40sManual check:
curl http://localhost:3000/
# Should return 200 OKLog Monitoring
View logs:
# Docker
docker logs -f tonl-server
# docker-compose
docker-compose logs -f tonl-server
# Last 100 lines
docker logs --tail 100 tonl-serverLog to file:
docker logs tonl-server > /var/log/tonl-server.log 2>&1Container Stats
Monitor resource usage:
docker stats tonl-serverOutput:
CONTAINER CPU % MEM USAGE / LIMIT NET I/O
tonl-server 2.5% 128MB / 512MB 1.2MB / 890kBRestart Policies
Always Restart
docker run -d \
--restart always \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestUnless Stopped
Recommended for production:
docker run -d \
--restart unless-stopped \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestOn Failure
Restart only on crash:
docker run -d \
--restart on-failure:3 \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestScaling
Horizontal Scaling
Run multiple instances behind load balancer:
version: '3.8'
services:
nginx:
image: nginx:alpine
ports:
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- tonl-1
- tonl-2
- tonl-3
tonl-1:
image: ghcr.io/kryptomrx/tonl-mcp-bridge:latest
environment:
- TONL_AUTH_TOKEN=${TONL_AUTH_TOKEN}
expose:
- "3000"
tonl-2:
image: ghcr.io/kryptomrx/tonl-mcp-bridge:latest
environment:
- TONL_AUTH_TOKEN=${TONL_AUTH_TOKEN}
expose:
- "3000"
tonl-3:
image: ghcr.io/kryptomrx/tonl-mcp-bridge:latest
environment:
- TONL_AUTH_TOKEN=${TONL_AUTH_TOKEN}
expose:
- "3000"nginx load balancer:
upstream tonl_backend {
least_conn;
server tonl-1:3000;
server tonl-2:3000;
server tonl-3:3000;
}
server {
listen 443 ssl;
server_name api.yourdomain.com;
location / {
proxy_pass http://tonl_backend;
proxy_set_header Host $host;
proxy_set_header Authorization $http_authorization;
}
}Vertical Scaling
Increase resources for single instance:
services:
tonl-server:
image: ghcr.io/kryptomrx/tonl-mcp-bridge:latest
deploy:
resources:
limits:
cpus: '4.0'
memory: 4G
reservations:
cpus: '2.0'
memory: 2GGraceful Shutdown
Server handles SIGTERM/SIGINT gracefully:
# Stop container
docker stop tonl-server
# Logs show:
# 🛑 Received SIGTERM. Shutting down gracefully...
# ✅ Server stopped cleanly.Configure timeout:
docker stop --time 30 tonl-serverBackup & Recovery
Configuration Backup
Backup environment file:
# Backup
cp .env .env.backup.$(date +%Y%m%d)
# Encrypt backup
gpg -c .env.backup.$(date +%Y%m%d)Container State
Export container:
docker export tonl-server > tonl-server-backup.tarImport:
docker import tonl-server-backup.tarUpdate Strategy
Rolling Update
- Pull new image:
docker pull ghcr.io/kryptomrx/tonl-mcp-bridge:latest- Stop old container:
docker stop tonl-server- Remove old container:
docker rm tonl-server- Start new container:
docker run -d \
--name tonl-server \
--restart unless-stopped \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=${TONL_AUTH_TOKEN} \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestBlue-Green Deployment
Run both versions:
# Start new version (green)
docker run -d \
--name tonl-green \
-p 3001:3000 \
-e TONL_AUTH_TOKEN=${TONL_AUTH_TOKEN} \
ghcr.io/kryptomrx/tonl-mcp-bridge:latest
# Test new version
curl -H "Authorization: Bearer ${TONL_AUTH_TOKEN}" \
http://localhost:3001/mcp
# Switch traffic (update nginx)
# Stop old version (blue)
docker stop tonl-blue
docker rm tonl-blueTroubleshooting
Check Container Status
docker ps -a | grep tonl-serverView Detailed Logs
docker logs --timestamps tonl-serverInspect Container
docker inspect tonl-serverExecute Commands in Container
# Check environment
docker exec tonl-server printenv
# Check user
docker exec tonl-server whoami
# Check network
docker exec tonl-server netstat -tlnpPerformance Issues
Check resource usage:
docker stats tonl-serverIf high CPU:
- Increase CPU limits
- Scale horizontally
- Check for infinite loops in requests
If high memory:
- Increase memory limits
- Check for memory leaks
- Review payload sizes
Connection Issues
Test connectivity:
# From host
curl http://localhost:3000/
# From another container
docker run --rm --network container:tonl-server \
curlimages/curl:latest \
curl http://localhost:3000/Authentication Issues
Verify token:
docker exec tonl-server printenv | grep TONL_AUTH_TOKENTest auth:
# Should fail (401)
curl http://localhost:3000/mcp
# Should succeed
curl -H "Authorization: Bearer ${TONL_AUTH_TOKEN}" \
http://localhost:3000/mcpSecurity Hardening
Read-Only Root Filesystem
docker run -d \
--read-only \
--tmpfs /tmp \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestDrop Capabilities
docker run -d \
--cap-drop=ALL \
--cap-add=NET_BIND_SERVICE \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestSecurity Options
docker run -d \
--security-opt=no-new-privileges:true \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=token \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestCI/CD Integration
GitHub Actions Example
name: Deploy to Production
on:
push:
tags:
- 'v*'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
docker pull ghcr.io/kryptomrx/tonl-mcp-bridge:latest
docker stop tonl-server || true
docker rm tonl-server || true
docker run -d \
--name tonl-server \
--restart unless-stopped \
-p 3000:3000 \
-e TONL_AUTH_TOKEN=${{ secrets.TONL_AUTH_TOKEN }} \
ghcr.io/kryptomrx/tonl-mcp-bridge:latestNext Steps
- Docker Guide - Docker deployment details
- MCP Server Guide - MCP server configuration
- Monitoring - Advanced monitoring setup
- Security - Security best practices