Add message queue for SSE messages POST endpoint (#459)

This commit is contained in:
Akash D
2025-05-06 17:10:43 -07:00
committed by GitHub
parent 58c5e7223c
commit 3b1b213a96
26 changed files with 1247 additions and 50 deletions

View File

@@ -412,6 +412,30 @@ app.router.routes.append(Host('mcp.acme.corp', app=mcp.sse_app()))
For more information on mounting applications in Starlette, see the [Starlette documentation](https://www.starlette.io/routing/#submounting-routes).
#### Message Dispatch Options
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:
```python
# Using the built-in Redis message dispatch
from mcp.server.fastmcp import FastMCP
from mcp.server.message_queue import RedisMessageDispatch
# Create a Redis message dispatch
redis_dispatch = RedisMessageDispatch(
redis_url="redis://localhost:6379/0", prefix="mcp:pubsub:"
)
# Pass the message dispatch instance to the server
mcp = FastMCP("My App", message_queue=redis_dispatch)
```
To use Redis, add the Redis dependency:
```bash
uv add "mcp[redis]"
```
## Examples
### Echo Server