Skip to content

Task Group inialization error on lifespan and mounting on FastMcp #1220

@MuazAshraf

Description

@MuazAshraf

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions