Fix authentication middleware to allow OPTIONS requests
CORS preflight requests (OPTIONS) don't include Authorization headers by browser design. The middleware was blocking these requests with 401. Solution: - Skip authentication check for OPTIONS requests - OPTIONS requests are handled by CORS middleware only - Actual requests (GET, POST) still require authentication This fixes the "401 Unauthorized" error on OPTIONS /mcp when using MCP Inspector or other browser-based clients with authentication enabled.
This commit is contained in:
parent
d0945d99a3
commit
fe71704bf8
1 changed files with 5 additions and 0 deletions
|
|
@ -54,6 +54,11 @@ class AuthenticationMiddleware(BaseHTTPMiddleware):
|
|||
if request.url.path == "/health":
|
||||
return await call_next(request)
|
||||
|
||||
# Skip authentication for OPTIONS requests (CORS preflight)
|
||||
# OPTIONS requests don't include Authorization headers by design
|
||||
if request.method == "OPTIONS":
|
||||
return await call_next(request)
|
||||
|
||||
# Check for Authorization header
|
||||
auth_header = request.headers.get("Authorization")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue