Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c2f8730

Browse filesBrowse files
authored
Fix example for multiple stateless servers (#720)
1 parent 13f0182 commit c2f8730
Copy full SHA for c2f8730

File tree

1 file changed

+10
-3
lines changed
Filter options

1 file changed

+10
-3
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,22 @@ def add_two(n: int) -> int:
437437

438438
```python
439439
# main.py
440+
import contextlib
440441
from fastapi import FastAPI
441442
from mcp.echo import echo
442443
from 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)
449456
app.mount("/echo", echo.mcp.streamable_http_app())
450457
app.mount("/math", math.mcp.streamable_http_app())
451458
```

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.