# =============================================================================
# Nginx configuration for Email MCP Server
# Protocol: MCP 2025-03-26 (Streamable HTTP)
# Add to /etc/nginx/sites-enabled/mcp.svsfinpro.ru
# =============================================================================
# Email MCP Server - Main endpoint (Streamable HTTP)
# Route: /email/* → localhost:3008
location /email/ {
# Rewrite /email/* to /*
rewrite ^/email/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:3008;
proxy_http_version 1.1;
# Standard 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;
# MCP Session ID header (Streamable HTTP)
proxy_set_header Mcp-Session-Id $http_mcp_session_id;
proxy_pass_header Mcp-Session-Id;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 120s;
# CORS headers
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type, Authorization, Mcp-Session-Id" always;
# Handle OPTIONS preflight
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type, Authorization, Mcp-Session-Id" always;
add_header Access-Control-Max-Age 86400;
add_header Content-Length 0;
add_header Content-Type text/plain;
return 204;
}
}
# Email MCP Server - MCP Endpoint (Streamable HTTP POST + optional SSE GET)
location = /email/mcp {
proxy_pass http://127.0.0.1:3008/mcp;
proxy_http_version 1.1;
# Standard 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;
proxy_set_header Content-Type $content_type;
proxy_set_header Accept $http_accept;
# MCP Session ID header (critical for Streamable HTTP)
proxy_set_header Mcp-Session-Id $http_mcp_session_id;
proxy_pass_header Mcp-Session-Id;
# For SSE streaming (GET /mcp with Accept: text/event-stream)
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
# Timeouts (longer for streaming)
proxy_connect_timeout 60s;
proxy_send_timeout 120s;
proxy_read_timeout 86400s;
# CORS headers
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type, Authorization, Mcp-Session-Id, Accept" always;
add_header Access-Control-Expose-Headers "Mcp-Session-Id" always;
}
# Email MCP Server - Health endpoint
location = /email/health {
proxy_pass http://127.0.0.1:3008/health;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_connect_timeout 5s;
proxy_read_timeout 10s;
}