Overview
TheSingleSessionHTTPServer class provides a complete, production-ready HTTP server for the n8n-MCP protocol. Unlike N8NMCPEngine, this class includes built-in authentication, CORS configuration, and session management out of the box.
When to use: Use
SingleSessionHTTPServer for standalone deployments or when you need a complete server solution. For embedding in existing applications, use N8NMCPEngine instead.Installation
Quick Start
Constructor
SingleSessionHTTPServer()
Creates a new HTTP server instance. Configuration is loaded from environment variables.Configuration
Environment Variables
Authentication token for Bearer auth. Minimum 32 characters recommended.Generate a secure token:
Path to file containing the auth token. Alternative to
AUTH_TOKEN for secret management systems.Port to listen on
Host interface to bind to
Session timeout in minutes. Inactive sessions are cleaned up after this period.
Maximum concurrent sessions allowed. Prevents memory exhaustion.
Allowed CORS origin. Set to specific domain in production.
Number of proxy hops to trust for IP logging. Set to 1 behind a reverse proxy.
Logging verbosity level
Environment mode. Production enables enhanced security checks.
Multi-Tenant Configuration
Enable multi-tenant mode with per-request instance contexts
Session isolation strategy:
instance: Each tenant gets isolated sessions (recommended)shared: Sessions shared across tenants with context switching
Methods
start()
Start the HTTP server and begin accepting requests.- Validates configuration (auth token, etc.)
- Creates Express app with security middleware
- Sets up MCP endpoints
- Starts listening on configured port
handleRequest()
Process a single MCP request. Primarily used internally, but available for custom routing.Express request object
Express response object
getSessionInfo()
Get current session information.Whether sessions are currently active
Active session identifier
Session age in seconds
exportSessionState()
Export all active session state for persistence. See Session Management for details.restoreSessionState()
Restore session state from previously exported data. See Session Management for details.shutdown()
Gracefully shutdown the server.Built-in Endpoints
The server automatically creates these endpoints:GET /
API information and available endpoints.GET /health
Health check endpoint with detailed metrics.POST /mcp
Main MCP JSON-RPC endpoint. Requires authentication.DELETE /mcp
Terminate a specific session.Multi-Tenant Usage
Enable multi-tenant mode to support multiple n8n instances with per-request configuration.Security Features
Rate Limiting
Built-in rate limiting prevents brute force attacks:- 20 authentication attempts per IP per 15 minutes
- Configurable via
AUTH_RATE_LIMIT_MAXandAUTH_RATE_LIMIT_WINDOW
Security Headers
Automatically applied headers:X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=blockStrict-Transport-Security: max-age=31536000
Token Validation
- Timing-safe comparison prevents timing attacks
- Minimum 32 character token requirement
- Production mode blocks default tokens
Production Deployment
Related
- N8NMCPEngine - Embeddable engine for custom apps
- Session Management - Session persistence guide
- Types - TypeScript interfaces