File tree 1 file changed +10
-3
lines changed
Filter options
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:
437
437
438
438
``` python
439
439
# main.py
440
+ import contextlib
440
441
from fastapi import FastAPI
441
442
from mcp.echo import echo
442
443
from mcp.math import math
443
444
444
445
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
446
453
447
- # Use the session manager's lifespan
448
- app = FastAPI(lifespan = lambda app : echo.mcp.session_manager.run() )
454
+
455
+ app = FastAPI(lifespan = lifespan )
449
456
app.mount(" /echo" , echo.mcp.streamable_http_app())
450
457
app.mount(" /math" , math.mcp.streamable_http_app())
451
458
```
You can’t perform that action at this time.
0 commit comments