fix: preserve exact resource URI from protected resource metadata - #1991
fix: preserve exact resource URI from protected resource metadata#1991Christian-Sidak wants to merge 1 commit into
Conversation
…alization When protected resource metadata contains a pathless URI like "https://example.com", the SDK was normalizing it to "https://example.com/" via URL.href. This broke OAuth with providers like Microsoft Entra ID that require the resource parameter to exactly match the scopes' audience. Change selectResourceURL to return the original metadata string directly instead of wrapping it in new URL(), and update all serialization sites to use String() instead of .href so URL objects are still handled correctly. Fixes modelcontextprotocol#1968 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 60993b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
|
Friendly bump -- let me know if anything needs changing. |
1 similar comment
|
Friendly bump -- let me know if anything needs changing. |
|
Additional bump. Thanks |
|
Friendly bump -- let me know if anything needs changing. |
2 similar comments
|
Friendly bump -- let me know if anything needs changing. |
|
Friendly bump -- let me know if anything needs changing. |
|
Endorsing this from a production deployment. We run an MCP gateway/registry that fronts many MCP servers behind a single Microsoft Entra tenant (agentic-community/mcp-gateway-registry), and we hit exactly the #1968 bug: our PRM advertises a pathless I reviewed the diff and it resolves our case correctly:
One production detail that makes the pathless case matter beyond a single server: because a bare-origin resource is currently unusable on Entra, a gateway is forced to register one The added regression test (pathless PRM resource -> no trailing slash) and the flipped assertion match the intended behavior. +1 to merging. Related downstream reports for cross-reference: the same cc @omrishiv |
|
Thanks @aarora79 -- great to have production confirmation. The single-origin-per-gateway use case (vs. one |
|
Hi @felixweinberger @pcarleton, would appreciate your attention on this one. |
|
+1 |
|
+1 - this is an actual production issue. We can't connect to Azure DevOps via MCP until this is fixed. Would love to use MCP for useful things. |
Summary
selectResourceURL()was returningnew URL(resourceMetadata.resource), which normalizes pathless URIs likehttps://example.comtohttps://example.com/viaURL.href.href, further cementing the trailing slashselectResourceURL()to return the original metadata string directly (preserving the exact value), and updated all serialization to useString(resource)instead ofresource.hrefselectResourceURLand theresourceparameter instartAuthorization,executeTokenRequest,exchangeAuthorization,refreshAuthorization, andfetchTokenfromURLtoURL | stringto accommodate both metadata strings and customvalidateResourceURLURL objectsTest plan
preserves pathless resource URI from PRM without adding trailing slashnew URL("https://example.com").href === "https://example.com/"(the bug), and that returning the string directly preserves"https://example.com"Fixes #1968