fix: mypy type annotations for MCP auth middleware

This commit is contained in:
Viktor Barzin 2026-03-18 22:52:14 +00:00
parent 48df739c82
commit 1a275e976c
No known key found for this signature in database
GPG key ID: 0EB088298288D958

View file

@ -610,13 +610,14 @@ async def secret_get(key: str) -> str:
# Auth middleware for /mcp/* routes
class MCPAuthMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next): # type: ignore[override]
async def dispatch(self, request: Request, call_next: Any) -> Response:
if request.url.path.startswith("/mcp"):
auth = request.headers.get("authorization", "")
token = auth.removeprefix("Bearer ").strip()
if not _resolve_user_from_token(token):
return Response(content="Unauthorized", status_code=401)
return await call_next(request)
response: Response = await call_next(request)
return response
app.add_middleware(MCPAuthMiddleware)