from __future__ import annotations from contextlib import asynccontextmanager import logging from starlette.applications import Starlette from starlette.routing import Mount from app.config import get_settings from app.mcp import mcp settings = get_settings() logger = logging.getLogger("personal-agent.mcp") @asynccontextmanager async def lifespan(_: Starlette): effective_mode = settings.auth_mode if settings.mcp_auth_mode == "inherit" else settings.mcp_auth_mode logger.info( "MCP authentication mode=%s (base AUTH_MODE=%s)", effective_mode, settings.auth_mode, ) async with mcp.session_manager.run(): yield app = Starlette( routes=[ Mount("/mcp", app=mcp.streamable_http_app()), ], lifespan=lifespan, )