mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2026-01-25 00:34:21 +01:00
Add message queue for SSE messages POST endpoint (#459)
This commit is contained in:
24
README.md
24
README.md
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user