fix: attempt to query resource-specific protected resource metadata before root PRM #1142
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.
Currently, the resource-specific protected resource metadata endpoint is not queried to discover RFC 9728 metadata, which is incorrect per the specification.
Given an MCP server at
https://example.com/mcp
, the PRM must be located athttps://example.com/.well-known/oauth-protected-resource/mcp
. However, no matter what path the MCP server is hosted on, the SDK currently attempts to discover PRM at the root, e.g.https://example.com/.well-known/oauth-protected-resource
. This breaks compatibility with any MCP server with authorization hosted outside of the root, unless the MCP server is double-hosting metadata to account for this.This PR attempts to handle both cases (giving consideration to the existing behavior potentially being expected now) by querying the most specific resource path first, and then falling back to the existing behavior in the event that PRM is hosted at the root path instead. This is the same behavior used in the TS SDK.
Note that this fallback behavior is not actually spec-compliant, I've only implemented it this way to account for the possibility that some MCP servers are non-compliant to match the client SDK.
Motivation and Context
Fixes compatibility with spec-compliant MCP servers.
How Has This Been Tested?
Unit tests. TODO: spot check against example server (putting implementation out now for early feedback)
Breaking Changes
None.
Types of changes
Checklist
Additional context
#1052