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
For more information on mounting applications in Starlette, see the [Starlette documentation](https://www.starlette.io/routing/#submounting-routes).
387
414
415
+
#### Message Dispatch Options
416
+
417
+
By default, the SSE server uses an in-memory message dispatch system for incoming POST messages. For production deployments or distributed scenarios, you can use Redis or implement your own message dispatch system that conforms to the `MessageDispatch` protocol:
418
+
419
+
```python
420
+
# Using the built-in Redis message dispatch
421
+
from mcp.server.fastmcp import FastMCP
422
+
from mcp.server.message_queue import RedisMessageDispatch
# MCP Simple StreamableHttp Stateless Server Example
2
+
3
+
A stateless MCP server example demonstrating the StreamableHttp transport without maintaining session state. This example is ideal for understanding how to deploy MCP servers in multi-node environments where requests can be routed to any instance.
4
+
5
+
## Features
6
+
7
+
- Uses the StreamableHTTP transport in stateless mode (mcp_session_id=None)
8
+
- Each request creates a new ephemeral connection
9
+
- No session state maintained between requests
10
+
- Task lifecycle scoped to individual requests
11
+
- Suitable for deployment in multi-node environments
12
+
13
+
14
+
## Usage
15
+
16
+
Start the server:
17
+
18
+
```bash
19
+
# Using default port 3000
20
+
uv run mcp-simple-streamablehttp-stateless
21
+
22
+
# Using custom port
23
+
uv run mcp-simple-streamablehttp-stateless --port 3000
24
+
25
+
# Custom logging level
26
+
uv run mcp-simple-streamablehttp-stateless --log-level DEBUG
27
+
28
+
# Enable JSON responses instead of SSE streams
29
+
uv run mcp-simple-streamablehttp-stateless --json-response
30
+
```
31
+
32
+
The server exposes a tool named "start-notification-stream" that accepts three arguments:
33
+
34
+
-`interval`: Time between notifications in seconds (e.g., 1.0)
35
+
-`count`: Number of notifications to send (e.g., 5)
36
+
-`caller`: Identifier string for the caller
37
+
38
+
39
+
## Client
40
+
41
+
You can connect to this server using an HTTP client. For now, only the TypeScript SDK has streamable HTTP client examples, or you can use [Inspector](https://github.com/modelcontextprotocol/inspector) for testing.
0 commit comments