File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -437,15 +437,22 @@ def add_two(n: int) -> int:
437437
438438``` python
439439# main.py
440+ import contextlib
440441from fastapi import FastAPI
441442from mcp.echo import echo
442443from mcp.math import math
443444
444445
445- app = FastAPI()
446+ # Create a combined lifespan to manage both session managers
447+ @contextlib.asynccontextmanager
448+ async def lifespan (app : FastAPI):
449+ async with contextlib.AsyncExitStack() as stack:
450+ await stack.enter_async_context(echo.mcp.session_manager.run())
451+ await stack.enter_async_context(math.mcp.session_manager.run())
452+ yield
446453
447- # Use the session manager's lifespan
448- app = FastAPI(lifespan = lambda app : echo.mcp.session_manager.run() )
454+
455+ app = FastAPI(lifespan = lifespan )
449456app.mount(" /echo" , echo.mcp.streamable_http_app())
450457app.mount(" /math" , math.mcp.streamable_http_app())
451458```
You can’t perform that action at this time.
0 commit comments