From 4e18e792c5efe9be3561fb19e059b480d6a41365 Mon Sep 17 00:00:00 2001 From: saidsurucu Date: Tue, 22 Jul 2025 12:01:09 +0300 Subject: [PATCH] Fix MCP app creation: use exact v0.1.6 approach - Use mcp_server.http_app(path='/') like v0.1.6 - Use redirect_to_slash function name like v0.1.6 - This should fix 'Not Found' error when accessing /mcp/ endpoint --- asgi_app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/asgi_app.py b/asgi_app.py index 0d74b8d..ecbb113 100755 --- a/asgi_app.py +++ b/asgi_app.py @@ -97,8 +97,8 @@ else: # Create MCP app with Bearer authentication mcp_server = create_app(auth=bearer_auth) -# Create MCP Starlette sub-application -mcp_app = mcp_server.http_app() +# Create MCP Starlette sub-application with root path - mount will add /mcp prefix +mcp_app = mcp_server.http_app(path="/") logger.info(f"MCP Starlette app created - type: {type(mcp_app)}, has routes: {hasattr(mcp_app, 'routes')}") # Debug FastMCP routes @@ -209,9 +209,9 @@ async def health_check(): "auth_enabled": os.getenv("ENABLE_AUTH", "false").lower() == "true" } -# Manual redirect endpoint for /mcp -> /mcp/ (support all HTTP methods) +# Add explicit redirect for /mcp to /mcp/ with method preservation @app.api_route("/mcp", methods=["GET", "POST", "HEAD", "OPTIONS"]) -async def redirect_mcp_to_mcp_slash(): +async def redirect_to_slash(request: Request): """Redirect /mcp to /mcp/ preserving HTTP method with 308""" from fastapi.responses import RedirectResponse return RedirectResponse(url="/mcp/", status_code=308)