Route MCP without shadowing site endpoints

This commit is contained in:
anor
2026-11-27 17:27:05 +10:00
parent 70ad8743d2
commit d26d20b82b
+21 -1
View File
@@ -5557,7 +5557,27 @@ async def _web_with_mcp_lifespan(app_instance):
app.router.lifespan_context = _web_with_mcp_lifespan
app.mount("/", _mcp_http_app)
class _MCPDispatch:
"""Pass only protocol/OAuth URLs to the SDK; preserve FastAPI route ordering."""
def __init__(self, next_app):
self.next_app = next_app
async def __call__(self, scope, receive, send):
path = scope.get("path", "")
if scope["type"] == "http" and (
path == "/mcp"
or path in {"/authorize", "/token", "/register", "/revoke"}
or path.startswith("/.well-known/oauth-")
):
await _mcp_http_app(scope, receive, send)
else:
await self.next_app(scope, receive, send)
app.add_middleware(_MCPDispatch)
if __name__ == "__main__":
import uvicorn