From 01a6666429273ce221db290cf06b22ea53f50a50 Mon Sep 17 00:00:00 2001 From: jh-block Date: Thu, 16 Apr 2026 18:16:19 +0200 Subject: [PATCH] fix: treat resource metadata JSON parse failure as soft error (#810) 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. --- crates/rmcp/src/transport/auth.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/rmcp/src/transport/auth.rs b/crates/rmcp/src/transport/auth.rs index 34674df..3aa3e91 100644 --- a/crates/rmcp/src/transport/auth.rs +++ b/crates/rmcp/src/transport/auth.rs @@ -1609,12 +1609,13 @@ impl AuthorizationManager { return Ok(None); } - let metadata = response - .json::() - .await - .map_err(|e| { - AuthError::MetadataError(format!("Failed to parse resource metadata: {}", e)) - })?; + let metadata = match response.json::().await { + Ok(metadata) => metadata, + Err(e) => { + debug!("failed to parse resource metadata as JSON: {}", e); + return Ok(None); + } + }; Ok(Some(metadata)) }