You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+146-1Lines changed: 146 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1234,7 +1234,7 @@ Note that `uv run mcp run` or `uv run mcp dev` only supports server using FastMC
1234
1234
1235
1235
### Streamable HTTP Transport
1236
1236
1237
-
> **Note**: Streamable HTTP transport is the recommended transport for production deployments. Use `stateless_http=True` and `json_response=True`for optimal scalability.
1237
+
> **Note**: Streamable HTTP transport is the recommended transport for production deployments. For serverless and load-balanced environments, consider using `stateless_http=True` and `json_response=True`. See [Understanding Stateless Mode](#understanding-stateless-mode)for guidance on choosing between stateful and stateless operation.
@@ -1346,6 +1346,151 @@ The streamable HTTP transport supports:
1346
1346
- JSON or SSE response formats
1347
1347
- Better scalability for multi-node deployments
1348
1348
1349
+
#### Understanding Stateless Mode
1350
+
1351
+
The Streamable HTTP transport can operate in two modes: **stateful** (default) and **stateless**. Understanding the difference is important for choosing the right deployment model.
1352
+
1353
+
##### What "Stateless" Means
1354
+
1355
+
In **stateless mode** (`stateless_http=True`), each HTTP request creates a completely independent MCP session that exists only for the duration of that single request:
1356
+
1357
+
-**No session tracking**: No `Mcp-Session-Id` header is used or required
1358
+
-**Per-request lifecycle**: Each request initializes a fresh server instance, processes the request, and terminates
1359
+
-**No state persistence**: No information is retained between requests
1360
+
-**No event store**: Resumability features are disabled
1361
+
1362
+
This is fundamentally different from **stateful mode** (default), where:
1363
+
1364
+
- A session persists across multiple requests
1365
+
- The `Mcp-Session-Id` header links requests to an existing session
1366
+
- Server state (e.g., subscriptions, context) is maintained between calls
1367
+
- Event stores can provide resumability if the connection drops
1368
+
1369
+
##### MCP Features Impacted by Stateless Mode
1370
+
1371
+
When running in stateless mode, certain MCP features are unavailable or behave differently:
1372
+
1373
+
| Feature | Stateful Mode | Stateless Mode |
1374
+
|---------|---------------|----------------|
1375
+
|**Server Notifications**| ✅ Supported | ❌ Not available<sup>1</sup> |
1376
+
|**Resource Subscriptions**| ✅ Supported | ❌ Not available<sup>1</sup> |
1377
+
|**Multi-turn Context**| ✅ Maintained | ❌ Lost between requests<sup>2</sup> |
1378
+
|**Long-running Tools**| ✅ Can use notifications for progress | ⚠️ Must complete within request timeout |
1379
+
|**Event Resumability**| ✅ With event store | ❌ Not applicable |
1. Client sends HTTP POST request to `/mcp` endpoint
1470
+
2. Server creates ephemeral `StreamableHTTPServerTransport` (no session ID)
1471
+
3. Server initializes fresh `Server` instance with `stateless=True` flag
1472
+
4. Request is processed using the ephemeral transport
1473
+
5. Response is sent back to client
1474
+
6. Transport and server instance are immediately terminated
1475
+
1476
+
**Performance Characteristics:**
1477
+
1478
+
-**Initialization overhead**: Each request pays the cost of server initialization
1479
+
-**Memory efficiency**: No long-lived sessions consuming memory
1480
+
-**Scalability**: Excellent horizontal scaling with no state synchronization
1481
+
-**Latency**: Slightly higher per-request latency due to initialization
1482
+
1483
+
**Stateless Mode Checklist:**
1484
+
1485
+
When designing for stateless mode, ensure:
1486
+
1487
+
- ✅ Tools are self-contained and don't rely on previous calls
1488
+
- ✅ All required context is passed in each request
1489
+
- ✅ Tools complete synchronously within request timeout
1490
+
- ✅ No server notifications or subscriptions are needed
1491
+
- ✅ Client handles any necessary state management
1492
+
- ✅ Operations are idempotent where possible
1493
+
1349
1494
#### CORS Configuration for Browser-Based Clients
1350
1495
1351
1496
If you'd like your server to be accessible by browser-based MCP clients, you'll need to configure CORS headers. The `Mcp-Session-Id` header must be exposed for browser clients to access it:
0 commit comments