Skip to main content
FastMCP’s stateless mode makes it ideal for serverless deployments where each request is handled independently without maintaining persistent sessions.

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/await for all I/O operations
  • Bundle size: Minimize dependencies to reduce cold start time
Stateless mode means each request is independent. Do not rely on in-memory state between requests.

Next Steps