We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a00b20a commit ce14d07Copy full SHA for ce14d07
1 file changed
README.md
@@ -434,15 +434,21 @@ def add_two(n: int) -> int:
434
435
```python
436
# main.py
437
+import contextlib
438
from fastapi import FastAPI
439
from mcp.echo import echo
440
from mcp.math import math
441
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
449
-# Use the session manager's lifespan
-app = FastAPI(lifespan=lambda app: echo.mcp.session_manager.run())
450
+
451
+app = FastAPI(lifespan=lifespan)
452
app.mount("/echo", echo.mcp.streamable_http_app())
453
app.mount("/math", math.mcp.streamable_http_app())
454
```
0 commit comments