fix: treat resource metadata JSON parse failure as soft error#810
Open
jh-block wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: treat resource metadata JSON parse failure as soft error#810jh-block wants to merge 1 commit intomodelcontextprotocol:mainfrom
jh-block wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
In fetch_resource_metadata_from_url, a JSON parse failure on the response body caused a fatal AuthError::MetadataError, preventing discover_metadata() from falling through to direct .well-known/oauth-authorization-server discovery (Strategy B). MCP servers that return HTTP 200 with non-JSON content (e.g. HTML) at their base URL caused the OAuth flow to abort entirely, even when the server had a valid .well-known/oauth-authorization-server endpoint. Return Ok(None) on parse failure, consistent with how HTTP errors are already handled in the same function.
Author
|
Note that an alternative here would be to not try to parse this response as metadata at all, since fetching the MCP server URL itself and treating it as the metadata isn't part of the discovery flow in the spec. But I am assuming this variation from the spec is intentional for some reason (compatibility with non-compliant servers maybe?) so kept this change minimal. |
jh-block
added a commit
to aaif-goose/goose
that referenced
this pull request
Apr 16, 2026
…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
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
fetch_resource_metadata_from_urlreturns a fatalAuthError::MetadataErrorwhen the resource metadata response body cannot be parsed as JSON. This preventsdiscover_metadata()from falling through to direct.well-known/oauth-authorization-serverdiscovery (Strategy B).Problem
MCP servers that return HTTP 200 with non-JSON content (e.g. HTML) at their base URL cause the resource metadata probe to "succeed" at the HTTP level (200 = "this is the metadata URL"), but then the JSON deserialization fails fatally. The OAuth flow aborts entirely even though the server has a valid
.well-known/oauth-authorization-serverendpoint.Users see "Auth required" with no OAuth browser flow ever opening.
Fix
Treat JSON parse errors as a soft failure — return
Ok(None)with adebug!log — consistent with how HTTP errors (non-200 status codes) are already handled in the same function. This allowsdiscover_metadata()to continue and attempt direct authorization server metadata discovery.Test plan
cargo check -p rmcp --features auth.well-known/oauth-authorization-serverdiscovery instead of aborting