File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -434,15 +434,21 @@ def add_two(n: int) -> int:
434434
435435``` python
436436# main.py
437+ import contextlib
437438from fastapi import FastAPI
438439from mcp.echo import echo
439440from mcp.math import math
440441
441442
442- app = FastAPI()
443+ # Create a combined lifespan to manage both session managers
444+ @contextlib.asynccontextmanager
445+ async def lifespan (app : FastAPI):
446+ async with echo.mcp.session_manager.run():
447+ async with math.mcp.session_manager.run():
448+ yield
443449
444- # Use the session manager's lifespan
445- app = FastAPI(lifespan = lambda app : echo.mcp.session_manager.run() )
450+
451+ app = FastAPI(lifespan = lifespan )
446452app.mount(" /echo" , echo.mcp.streamable_http_app())
447453app.mount(" /math" , math.mcp.streamable_http_app())
448454```
You can’t perform that action at this time.
0 commit comments