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" )
46+ # Create MCP HTTP apps (needed for lifespan integration)
47+ # Streamable HTTP (modern, recommended) - used by newer clients
48+ mcp_http_app = mcp_server .http_app (path = "/" )
49+ # SSE transport (legacy, wider compatibility) - used by mcp-remote, older clients
50+ mcp_sse_app = mcp_server .http_app (path = "/" , transport = "sse" )
4851
4952
5053@asynccontextmanager
@@ -60,10 +63,11 @@ async def lifespan(app: FastAPI):
6063 except Exception as e :
6164 logger .error (f"Failed to initialize database: { e } " )
6265
63- # Initialize MCP server lifespan (required for session management)
66+ # Initialize MCP server lifespans (required for session management)
6467 async with mcp_http_app .lifespan (app ):
65- logger .info ("MCP server initialized" )
66- yield
68+ async with mcp_sse_app .lifespan (app ):
69+ logger .info ("MCP server initialized (HTTP + SSE)" )
70+ yield
6771
6872 # Cleanup database connection
6973 logger .info ("Shutting down pyplots API..." )
@@ -132,9 +136,10 @@ async def add_cache_headers(request: Request, call_next):
132136 return response
133137
134138
135- # Mount MCP server for AI assistant integration
136- # Note: mcp_http_app is created earlier with lifespan integration
137- app .mount ("/mcp" , mcp_http_app )
139+ # Mount MCP servers for AI assistant integration
140+ # Note: Apps are created earlier with lifespan integration
141+ app .mount ("/mcp" , mcp_http_app ) # Streamable HTTP at /mcp
142+ app .mount ("/sse" , mcp_sse_app ) # SSE transport at /sse
138143
139144# Register routers
140145app .include_router (health_router )
0 commit comments