Skip to content

Commit 01a6666

Browse files
authored
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.
1 parent 3e56d52 commit 01a6666

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

crates/rmcp/src/transport/auth.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,12 +1609,13 @@ impl AuthorizationManager {
16091609
return Ok(None);
16101610
}
16111611

1612-
let metadata = response
1613-
.json::<ResourceServerMetadata>()
1614-
.await
1615-
.map_err(|e| {
1616-
AuthError::MetadataError(format!("Failed to parse resource metadata: {}", e))
1617-
})?;
1612+
let metadata = match response.json::<ResourceServerMetadata>().await {
1613+
Ok(metadata) => metadata,
1614+
Err(e) => {
1615+
debug!("failed to parse resource metadata as JSON: {}", e);
1616+
return Ok(None);
1617+
}
1618+
};
16181619
Ok(Some(metadata))
16191620
}
16201621

0 commit comments

Comments
 (0)