diff --git a/README.md b/README.md index b281b5513..dc357ad3a 100644 --- a/README.md +++ b/README.md @@ -434,15 +434,22 @@ def add_two(n: int) -> int: ```python # main.py +import contextlib from fastapi import FastAPI from mcp.echo import echo from mcp.math import math -app = FastAPI() +# Create a combined lifespan to manage both session managers +@contextlib.asynccontextmanager +async def lifespan(app: FastAPI): + async with contextlib.AsyncExitStack() as stack: + await stack.enter_async_context(echo.mcp.session_manager.run()) + await stack.enter_async_context(math.mcp.session_manager.run()) + yield -# Use the session manager's lifespan -app = FastAPI(lifespan=lambda app: echo.mcp.session_manager.run()) + +app = FastAPI(lifespan=lifespan) app.mount("/echo", echo.mcp.streamable_http_app()) app.mount("/math", math.mcp.streamable_http_app()) ```