Stateless Mode
Enable stateless mode for serverless environments:Why Stateless Mode?
In stateless mode:- No sessions tracked - Each request creates a temporary session discarded after response
- Reduced memory usage - Better scalability and lower costs
- No session state - Perfect for serverless environments that don’t guarantee instance persistence
- Independent requests - Each invocation is completely isolated
Stateless mode is only available with HTTP streaming transport. Features depending on persistent sessions will not be available.
Configuration Methods
Enable stateless mode in three ways:AWS Lambda Deployment
1
Create Lambda Handler
Create a handler that wraps your FastMCP server:
src/lambda.ts
2
Configure SAM or Serverless Framework
3
Deploy
Google Cloud Functions
1
Create HTTP Function
src/index.ts
2
Deploy to Google Cloud
Azure Functions
1
Create HTTP Trigger Function
src/functions/mcp.ts
2
Configure host.json
host.json
3
Deploy to Azure
Best Practices
Environment Variables
Manage configuration across environments:Cold Start Optimization
Minimize cold start times:Error Handling
Implement robust error handling:Health Checks
The/ready endpoint reports stateless mode status:
Monitoring
Each platform provides monitoring tools:Performance Considerations
- Memory allocation: Increase for complex operations (512MB-1GB recommended)
- Timeout settings: Set appropriate timeouts (30-60s for most operations)
- Connection pooling: Reuse HTTP clients across invocations
- Async operations: Use
async/awaitfor all I/O operations - Bundle size: Minimize dependencies to reduce cold start time
Next Steps
- Production Checklist - Security and monitoring best practices
- Cloudflare Workers - Deploy to Cloudflare’s edge network
- Authentication - Secure your serverless MCP server