File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 4343logger = logging .getLogger (__name__ )
4444
4545
46+ # Create MCP HTTP app (needed for lifespan integration)
47+ mcp_http_app = mcp_server .http_app (path = "/mcp" )
48+
49+
4650@asynccontextmanager
4751async def lifespan (app : FastAPI ):
4852 """Manage application lifecycle."""
@@ -56,7 +60,10 @@ async def lifespan(app: FastAPI):
5660 except Exception as e :
5761 logger .error (f"Failed to initialize database: { e } " )
5862
59- yield
63+ # Initialize MCP server lifespan (required for session management)
64+ async with mcp_http_app .lifespan (app ):
65+ logger .info ("MCP server initialized" )
66+ yield
6067
6168 # Cleanup database connection
6269 logger .info ("Shutting down pyplots API..." )
@@ -126,7 +133,8 @@ async def add_cache_headers(request: Request, call_next):
126133
127134
128135# Mount MCP server for AI assistant integration
129- app .mount ("/mcp" , mcp_server .http_app ())
136+ # Note: mcp_http_app is created earlier with lifespan integration
137+ app .mount ("/mcp" , mcp_http_app )
130138
131139# Register routers
132140app .include_router (health_router )
You can’t perform that action at this time.
0 commit comments