-
Notifications
You must be signed in to change notification settings - Fork 1.3k
401 Unauthorized #611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can confirm same impact. Just upgraded to 1.7.0, and unit tests in our app started to fail, where they didn't before. We don't yet rely on new OAuth capability of MCP server SDK. I made a disgusting workaround in my project: from mcp.server.auth.middleware.bearer_auth import RequireAuthMiddleware
from starlette.routing import Mount, Route
# Note:
# - mcp_server is an instance of FastMCP initialized elsewhere
# - app on the last line is a Starlette app that has other unrelated routes
# in addition to the routes managed by mcp_server
for r in mcp_server.sse_app().routes:
# Workaround for https://github.com/modelcontextprotocol/python-sdk/issues/611
# in which we unwrap SSE handlers from the RequireAuthMiddleware.
match r:
case Route():
if isinstance(r.app, RequireAuthMiddleware):
r.endpoint = r.app.app
r.app = r.app.app
case Mount():
if isinstance(r.app, RequireAuthMiddleware):
r.app = r.app.app
app.router.routes.append(r) |
paxan
added a commit
to paxan/mcp
that referenced
this issue
May 2, 2025
Github-Issue: modelcontextprotocol#611 Reported-by: johnandersen777
I made a draft of a fix: main...paxan:mcp:paxan/require-auth-if-configured Still thinking how to test. Currently |
3 tasks
related to #613 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Connecting from OpenAI SDK gives
401 Unauthorized
, pretty sure #255 is related from 1.7.0 release. This worked with1.6.0
To Reproduce
openai_agent_mcp.py
mcp_server_files.py
Expected behavior
Screenshots
The text was updated successfully, but these errors were encountered: