RFC 9728 resource is used instead of base url when possible#962
RFC 9728 resource is used instead of base url when possible#962fkonecny wants to merge 1 commit into
Conversation
|
@filip-konecny-tfs Can you take a look at the red checks? Once resolved we can move forward |
0ad8259 to
1e3ae88
Compare
1e3ae88 to
8b48170
Compare
|
@alexhancock I did squash the commits and shortened the message so I can pass the lint message checks. Which erased the history of checks (sorry). The public API check is confusing me as it refers things which I did not initiate, at least I think. The semver check is confusing me, should I be the one bumping it? I can if you wish to do so. P.S. @filip-konecny-tfs is my work account which I should not use for this type of activities :-). |
| expected_path.starts_with(actual_path) | ||
| && expected.query().is_none() | ||
| && actual.query().is_none() |
There was a problem hiding this comment.
Here, expected is base_url, and actual is the provider-declared resource. This means it accepts any declared path where the base_url path starts with that path. For example, if base_url is https://mcp.example.com/mcp-tools and the metadata declares https://mcp.example.com/mcp, then "/mcp-tools".starts_with("/mcp") is true.
| let Some(resource_url) = Url::parse(resource).ok() else { | ||
| return Err(AuthError::MetadataError( | ||
| "Protected resource metadata resource field is not a valid URL".to_string(), | ||
| )); | ||
| }; |
There was a problem hiding this comment.
nit
| let Some(resource_url) = Url::parse(resource).ok() else { | |
| return Err(AuthError::MetadataError( | |
| "Protected resource metadata resource field is not a valid URL".to_string(), | |
| )); | |
| }; | |
| let Ok(resource_url) = Url::parse(resource) else { | |
| return Err(AuthError::MetadataError( | |
| "Protected resource metadata resource field is not a valid URL".to_string(), | |
| )); | |
| }; |
Motivation and Context
Library initiates OAuth2 workflow with predefined resource as the base url to abide RFC 8707. This violates a possibility where MCP belongs under umbrella of exposed functionalities. RFC 8707 permits it in its second paragraph.
There was already implemented resource discovery from OAuth2 resource metadata document defined by RFC 9728 in PR 937 which can access the exposed resource.
Use resource defined by OAuth2 resource metadata document so the creator of MCP and its provider can control what resource are tokens requested for.
How Has This Been Tested?
2 tests were added:
PR 937 already handles situations where document has missing resource.
Breaking Changes
Breaking change: changes default behavior where base url is utilized always for resource and use defined resource by provider when available.
Types of changes
Checklist
Additional context