-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
I am having issue on task group inialization, First I added the lifespan with session menager it work for some days but after some days it gives me this error then I directly mount it. and some days it works fine but same error after some days so I have to again change it to lifespan. is this issue is for me or anybody else is also facing. I guess now This will be correct!
import contextlib
from fastapi import FastAPI
Create a combined lifespan to manage all session managers
@contextlib.asynccontextmanager
async def lifespan(app: FastAPI):
async with contextlib.AsyncExitStack() as stack:
# Initialize all session managers
I placholders the name here.
await stack.enter_async_context(1_mcp.session_manager.run())
await stack.enter_async_context(2_mcp.session_manager.run())
await stack.enter_async_context(3_mcp.session_manager.run())
await stack.enter_async_context(4_mcp.session_manager.run())
await stack.enter_async_context(5_mcp.session_manager.run())
yield
Create FastAPI app with lifespan
app = FastAPI(lifespan=lifespan)
app.mount("/1", 1_mcp.streamable_http_app())
app.mount("/2", 2_mcp.streamable_http_app())
app.mount("/3", 3_mcp.streamable_http_app())
app.mount("/4", 4_mcp.streamable_http_app())
app.mount("/5", 5_mcp.streamable_http_app())