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
fix: move stateless mode docs from frozen README.md to README.v2.md
README.md is frozen at v1 per CI checks. Move the Understanding
Stateless Mode section and the refined note to README.v2.md instead.
Update code examples to use MCPServer (formerly FastMCP).
Copy file name to clipboardExpand all lines: README.md
+1-146Lines changed: 1 addition & 146 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1243,7 +1243,7 @@ Note that `uv run mcp run` or `uv run mcp dev` only supports server using FastMC
1243
1243
1244
1244
### Streamable HTTP Transport
1245
1245
1246
-
> **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.
1246
+
> **Note**: Streamable HTTP transport is the recommended transport for production deployments. Use `stateless_http=True` and `json_response=True`for optimal scalability.
@@ -1355,151 +1355,6 @@ The streamable HTTP transport supports:
1355
1355
- JSON or SSE response formats
1356
1356
- Better scalability for multi-node deployments
1357
1357
1358
-
#### Understanding Stateless Mode
1359
-
1360
-
The Streamable HTTP transport can operate in two modes: **stateful** (default) and **stateless**. Understanding the difference is important for choosing the right deployment model.
1361
-
1362
-
##### What "Stateless" Means
1363
-
1364
-
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:
1365
-
1366
-
-**No session tracking**: No `Mcp-Session-Id` header is used or required
1367
-
-**Per-request lifecycle**: Each request initializes a fresh server instance, processes the request, and terminates
1368
-
-**No state persistence**: No information is retained between requests
1369
-
-**No event store**: Resumability features are disabled
1370
-
1371
-
This is fundamentally different from **stateful mode** (default), where:
1372
-
1373
-
- A session persists across multiple requests
1374
-
- The `Mcp-Session-Id` header links requests to an existing session
1375
-
- Server state (e.g., subscriptions, context) is maintained between calls
1376
-
- Event stores can provide resumability if the connection drops
1377
-
1378
-
##### MCP Features Impacted by Stateless Mode
1379
-
1380
-
When running in stateless mode, certain MCP features are unavailable or behave differently:
1381
-
1382
-
| Feature | Stateful Mode | Stateless Mode |
1383
-
|---------|---------------|----------------|
1384
-
|**Server Notifications**| ✅ Supported | ❌ Not available<sup>1</sup> |
1385
-
|**Resource Subscriptions**| ✅ Supported | ❌ Not available<sup>1</sup> |
1386
-
|**Multi-turn Context**| ✅ Maintained | ❌ Lost between requests<sup>2</sup> |
1387
-
|**Long-running Tools**| ✅ Can use notifications for progress | ⚠️ Must complete within request timeout |
1388
-
|**Event Resumability**| ✅ With event store | ❌ Not applicable |
1. Client sends HTTP POST request to `/mcp` endpoint
1479
-
2. Server creates ephemeral `StreamableHTTPServerTransport` (no session ID)
1480
-
3. Server initializes fresh `Server` instance with `stateless=True` flag
1481
-
4. Request is processed using the ephemeral transport
1482
-
5. Response is sent back to client
1483
-
6. Transport and server instance are immediately terminated
1484
-
1485
-
**Performance Characteristics:**
1486
-
1487
-
-**Initialization overhead**: Each request pays the cost of server initialization
1488
-
-**Memory efficiency**: No long-lived sessions consuming memory
1489
-
-**Scalability**: Excellent horizontal scaling with no state synchronization
1490
-
-**Latency**: Slightly higher per-request latency due to initialization
1491
-
1492
-
**Stateless Mode Checklist:**
1493
-
1494
-
When designing for stateless mode, ensure:
1495
-
1496
-
- ✅ Tools are self-contained and don't rely on previous calls
1497
-
- ✅ All required context is passed in each request
1498
-
- ✅ Tools complete synchronously within request timeout
1499
-
- ✅ No server notifications or subscriptions are needed
1500
-
- ✅ Client handles any necessary state management
1501
-
- ✅ Operations are idempotent where possible
1502
-
1503
1358
#### CORS Configuration for Browser-Based Clients
1504
1359
1505
1360
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:
Copy file name to clipboardExpand all lines: README.v2.md
+149-1Lines changed: 149 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1239,7 +1239,7 @@ Note that `uv run mcp run` or `uv run mcp dev` only supports server using MCPSer
1239
1239
1240
1240
### Streamable HTTP Transport
1241
1241
1242
-
> **Note**: Streamable HTTP transport is the recommended transport for production deployments. Use `stateless_http=True` and `json_response=True`for optimal scalability.
1242
+
> **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.
@@ -1350,6 +1350,154 @@ The streamable HTTP transport supports:
1350
1350
- JSON or SSE response formats
1351
1351
- Better scalability for multi-node deployments
1352
1352
1353
+
#### Understanding Stateless Mode
1354
+
1355
+
The Streamable HTTP transport can operate in two modes: **stateful** (default) and **stateless**. Understanding the difference is important for choosing the right deployment model.
1356
+
1357
+
##### What "Stateless" Means
1358
+
1359
+
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:
1360
+
1361
+
-**No session tracking**: No `Mcp-Session-Id` header is used or required
1362
+
-**Per-request lifecycle**: Each request initializes a fresh server instance, processes the request, and terminates
1363
+
-**No state persistence**: No information is retained between requests
1364
+
-**No event store**: Resumability features are disabled
1365
+
1366
+
This is fundamentally different from **stateful mode** (default), where:
1367
+
1368
+
- A session persists across multiple requests
1369
+
- The `Mcp-Session-Id` header links requests to an existing session
1370
+
- Server state (e.g., subscriptions, context) is maintained between calls
1371
+
- Event stores can provide resumability if the connection drops
1372
+
1373
+
##### MCP Features Impacted by Stateless Mode
1374
+
1375
+
When running in stateless mode, certain MCP features are unavailable or behave differently:
1376
+
1377
+
| Feature | Stateful Mode | Stateless Mode |
1378
+
|---------|---------------|----------------|
1379
+
|**Server Notifications**| ✅ Supported | ❌ Not available<sup>1</sup> |
1380
+
|**Resource Subscriptions**| ✅ Supported | ❌ Not available<sup>1</sup> |
1381
+
|**Multi-turn Context**| ✅ Maintained | ❌ Lost between requests<sup>2</sup> |
1382
+
|**Long-running Tools**| ✅ Can use notifications for progress | ⚠️ Must complete within request timeout |
1383
+
|**Event Resumability**| ✅ With event store | ❌ Not applicable |
1. Client sends HTTP POST request to `/mcp` endpoint
1477
+
2. Server creates ephemeral `StreamableHTTPServerTransport` (no session ID)
1478
+
3. Server initializes fresh `Server` instance with `stateless=True` flag
1479
+
4. Request is processed using the ephemeral transport
1480
+
5. Response is sent back to client
1481
+
6. Transport and server instance are immediately terminated
1482
+
1483
+
**Performance Characteristics:**
1484
+
1485
+
-**Initialization overhead**: Each request pays the cost of server initialization
1486
+
-**Memory efficiency**: No long-lived sessions consuming memory
1487
+
-**Scalability**: Excellent horizontal scaling with no state synchronization
1488
+
-**Latency**: Slightly higher per-request latency due to initialization
1489
+
1490
+
**Stateless Mode Checklist:**
1491
+
1492
+
When designing for stateless mode, ensure:
1493
+
1494
+
- ✅ Tools are self-contained and don't rely on previous calls
1495
+
- ✅ All required context is passed in each request
1496
+
- ✅ Tools complete synchronously within request timeout
1497
+
- ✅ No server notifications or subscriptions are needed
1498
+
- ✅ Client handles any necessary state management
1499
+
- ✅ Operations are idempotent where possible
1500
+
1353
1501
#### CORS Configuration for Browser-Based Clients
1354
1502
1355
1503
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