fix: work around rmcp OAuth discovery bug for remote MCP servers#8583
Open
fix: work around rmcp OAuth discovery bug for remote MCP servers#8583
Conversation
…vers When a remote MCP server returns HTTP 200 with non-JSON content at its base URL, rmcp's resource metadata discovery fatally errors instead of falling through to .well-known/oauth-authorization-server discovery. This prevents the OAuth browser flow from ever opening. Add a fallback in oauth_flow that catches the discovery failure and retries by fetching .well-known/oauth-authorization-server directly. Also log the actual error when oauth_flow fails instead of silently swallowing it. Upstream fix: modelcontextprotocol/rust-sdk#810
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1637c3d154
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Follow the MCP spec discovery flow in the fallback path: 1. Fetch Protected Resource Metadata from .well-known/oauth-protected-resource (path-specific then root, per RFC 9728) 2. Extract the authorization server URL from authorization_servers 3. Discover Authorization Server Metadata from that URL (trying RFC 8414 and OpenID Connect well-known endpoints) This correctly handles cases where the authorization server is on a different host from the MCP server, and path-based deployments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the OAuth flow never opening a browser for remote MCP servers that require authentication (e.g. Attio). The root cause is an rmcp bug where resource metadata discovery fails fatally when the MCP server returns HTTP 200 with non-JSON content at its base URL, preventing fallback to
.well-known/oauth-authorization-serverdiscovery.This PR adds a fallback in
oauth_flowthat catches the discovery failure and retries by fetching.well-known/oauth-authorization-serverdirectly, using rmcp's publicAuthorizationManager/AuthorizationSessionAPIs. It also logs the actual error whenoauth_flowfails, instead of silently swallowing it.Testing
Manual testing with the Attio MCP server (
https://mcp.attio.com/mcp).Related Issues
Relates to #8453
Upstream PR: modelcontextprotocol/rust-sdk#810