Fix resource metadata discovery URL construction to comply with MCP spec for subpath deployments#1110
Open
AnkeshThakur wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Fix resource metadata discovery URL construction to comply with MCP spec for subpath deployments#1110AnkeshThakur wants to merge 1 commit intomodelcontextprotocol:mainfrom
AnkeshThakur wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…pec for subpath deployments Per RFC 9728 §3 and the MCP spec (https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#protected-resource-metadata-discovery-requirements), the .well-known/oauth-protected-resource URL is formed by inserting the well-known prefix at the origin root and appending the resource path after it: https://example.com/public/mcp → https://example.com/.well-known/oauth-protected-resource/public/mcp The previous code used `new URL("/.well-known/oauth-protected-resource", serverUrl)` which always resolves to the host root, ignoring the resource path entirely. This broke metadata discovery for any subpath-deployed MCP server (issue modelcontextprotocol#1008). Changes: - Add `getResourceMetadataDiscoveryUrl()` in oauthUtils.ts that prepends /.well-known/oauth-protected-resource at the origin and appends the resource pathname (trailing slash stripped), matching the MCP SDK implementation - Replace all three inline well-known URL constructions in OAuthFlowProgress.tsx with the new utility via a memoized `resourceMetadataDiscoveryUrl` variable - Add 6 unit tests covering: single-segment path, subpath, deep path, trailing slash, no path, and URL object input Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
getResourceMetadataDiscoveryUrl()utility inoauthUtils.tsthat correctly constructs the protected resource metadata discovery URL per RFC 9728 §3 and the MCP specnew URL("/.well-known/oauth-protected-resource", serverUrl)usages inOAuthFlowProgress.tsxwith the new utility via a memoizedresourceMetadataDiscoveryUrlvariableProblem
The previous code used:
This always resolves to the host root, ignoring the resource endpoint path entirely. For subpath-deployed MCP servers (e.g.
https://host/public/mcp), the metadata URL was incorrectly constructed ashttps://host/.well-known/oauth-protected-resourceinstead ofhttps://host/.well-known/oauth-protected-resource/public/mcp.Fixes #1008.
Spec Compliance
Per RFC 9728 §3 and the MCP spec §authorization#protected-resource-metadata-discovery-requirements, the well-known URL is formed by inserting
/.well-known/oauth-protected-resourceat the origin root and appending the full resource path after it:https://host/public/mcphttps://host/.well-known/oauth-protected-resource/public/mcphttps://host/resourcehttps://host/.well-known/oauth-protected-resource/resourcehttps://host(no path)https://host/.well-known/oauth-protected-resourceThis matches the MCP SDK's own implementation:
new URL(`/.well-known/oauth-protected-resource${rsPath}`, u).Test plan
npm testinclient/)🤖 Generated with Claude Code