Production-ready MCP IMAP server for hosted N8N workflows. Changes: - SSE transport using create_sse_app() for N8N compatibility - API key authentication middleware for multi-tenant access - Systemd service file for auto-restart on Hetzner - Nginx reverse proxy config with TLS and rate limiting - Complete deployment guide (DEPLOY.md) - Removed REST API bridge (api_server.py) - N8N uses MCP protocol Deployment: - SSE endpoint: https://imap.maxtheweb.ai/mcp/sse - Messages endpoint: https://imap.maxtheweb.ai/mcp/messages - Authentication: Bearer token in Authorization header Stack: FastMCP 2.13 + uvicorn + nginx + systemd
95 lines
2.8 KiB
Plaintext
95 lines
2.8 KiB
Plaintext
# Nginx configuration for MCP IMAP Agent
|
|
# Place in: /etc/nginx/sites-available/mcp-imap
|
|
# Enable with: ln -s /etc/nginx/sites-available/mcp-imap /etc/nginx/sites-enabled/
|
|
# Get SSL cert: certbot --nginx -d imap.maxtheweb.ai
|
|
|
|
upstream mcp_backend {
|
|
server 127.0.0.1:8000;
|
|
keepalive 32;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
server_name imap.maxtheweb.ai;
|
|
|
|
# Redirect HTTP to HTTPS
|
|
return 301 https://$server_name$request_uri;
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name imap.maxtheweb.ai;
|
|
|
|
# SSL certificates (certbot will populate these)
|
|
ssl_certificate /etc/letsencrypt/live/imap.maxtheweb.ai/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/imap.maxtheweb.ai/privkey.pem;
|
|
|
|
# SSL configuration (Mozilla Intermediate)
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options "DENY" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
# Logging
|
|
access_log /var/log/nginx/mcp-imap-access.log;
|
|
error_log /var/log/nginx/mcp-imap-error.log;
|
|
|
|
# MCP SSE endpoint for N8N (streaming)
|
|
location /mcp/sse {
|
|
proxy_pass http://mcp_backend;
|
|
|
|
# Proxy headers
|
|
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;
|
|
|
|
# SSE support (critical for MCP protocol)
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
proxy_read_timeout 86400s;
|
|
proxy_send_timeout 86400s;
|
|
|
|
# Chunked transfer encoding for streaming
|
|
chunked_transfer_encoding on;
|
|
|
|
# Rate limiting
|
|
limit_req zone=api_limit burst=10 nodelay;
|
|
}
|
|
|
|
# MCP messages endpoint for N8N (posting)
|
|
location /mcp/messages {
|
|
proxy_pass http://mcp_backend;
|
|
|
|
# Proxy headers
|
|
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;
|
|
|
|
# Standard HTTP
|
|
proxy_http_version 1.1;
|
|
|
|
# Rate limiting
|
|
limit_req zone=api_limit burst=10 nodelay;
|
|
}
|
|
|
|
# Health check endpoint (no auth required)
|
|
location /health {
|
|
proxy_pass http://mcp_backend;
|
|
access_log off;
|
|
}
|
|
}
|
|
|
|
# Rate limiting zone (10 req/sec per IP)
|
|
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;
|