Skip to content

Commit ce14d07

Browse files
committed
fix example
1 parent a00b20a commit ce14d07

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,21 @@ def add_two(n: int) -> int:
434434

435435
```python
436436
# main.py
437+
import contextlib
437438
from fastapi import FastAPI
438439
from mcp.echo import echo
439440
from 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)
446452
app.mount("/echo", echo.mcp.streamable_http_app())
447453
app.mount("/math", math.mcp.streamable_http_app())
448454
```

0 commit comments

Comments
 (0)