fix(mcp oauth): Use server_url directly instead of base_url - #9375
fix(mcp oauth): Use server_url directly instead of base_url#9375anguslees wants to merge 1 commit into
Conversation
This fix was required for me to connect to our corporate glean instance. url=https://domain.glean.com/mcp/default I'm no expert in this, but I think this is correct from my read of the issue discussed in modelcontextprotocol/python-sdk#1407 Notes: ```script $ curl https://domain.glean.com/.well-known/oauth-protected-resource/mcp/default {"resource":"https://domain.glean.com/mcp/default","resource_name":"Glean","authorization_servers":["https://domain.glean.com/oauth"]} ``` Without this patch, I get: ```script $ hermes mcp test glean Testing 'glean'... Transport: HTTP → https://domain.glean.com/mcp/default Auth: OAuth 2.1 PKCE ✗ Connection failed (9072ms): Protected resource https://domain.glean.com/mcp/default does not match expected https://domain.glean.com ``` .. with matching logs: ``` 2026-04-14 13:34:05,449 ERROR mcp.client.auth.oauth2: OAuth flow error Traceback (most recent call last): File "/home/user/.hermes/hermes-agent/venv/lib/python3.11/site-packages/mcp/client/auth/oauth2.py", line 533, in async_auth_flow await self._validate_resource_match(prm) File "/home/user/.hermes/hermes-agent/venv/lib/python3.11/site-packages/mcp/client/auth/oauth2.py", line 277, in _validate_resource_match raise OAuthFlowError(f"Protected resource {prm_resource} does not match expected {default_resource}") mcp.client.auth.exceptions.OAuthFlowError: Protected resource https://domain.glean.com/mcp/default does not match expected https://domain.glean.com ```
|
The relevant code changed again, but the fix is the same. We need to pass the original server_url to the oauth client, not strip the path. I can keep rebasing this easily enough, but can someone/something respond in any way here first, so I know I'm not wasting my time? (I see the rate of outstanding PRs is growing extremely fast, so I suspect the "real" authors are just ignoring all of them - I would do that too tbh.) |
|
Thanks for this fix, @anguslees — the root cause diagnosis and error trace were spot-on and likely helped land the upstream fix faster. This is an automated hermes-sweeper review. The same bug was fixed by PR #16031 ("fix(mcp-oauth): preserve server_url path for protected-resource validation"), which merged on 2026-04-26 at commit
The fix is live on |
What does this PR do?
Use full MCP server_url (including path) when performing OIDC authentication.
This fix was required for me to connect to our corporate glean instance. url=https://domain.glean.com/mcp/default
Without this patch, I get:
.. with matching logs:
Related Issue
I'm no expert in this, but I think this is correct from my read of the issue discussed in modelcontextprotocol/python-sdk#1407
Notes:
Type of Change
How to Test
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs