Implement Protected Resource Metadata Discovery (RFC 9728) for MCP Authorization Compliance #193
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
This PR adds support for OAuth 2.0 Protected Resource Metadata discovery (RFC 9728) to properly discover authorization servers that are hosted on different domains than the MCP server. This is required for MCP Authorization Server Discovery compliance and enables interoperability with MCP servers like Supabase where the auth server (
https://api.supabase.com) differs from the MCP server (https://mcp.supabase.com).Problem
Previously,
mcp-remoteassumed the MCP server URL was the same as the authorization server URL. This broke authentication for servers like Supabase that return:Changes
New Module: Protected Resource Metadata
protected-resource-metadata.tsmodule implementing RFC 9728parseWWWAuthenticateHeader()- Extractsresource_metadata,scope,error, anderror_descriptionfrom 401 responsesbuildProtectedResourceMetadataUrls()- Constructs well-known URLs with proper fallback orderdiscoverProtectedResourceMetadata()- Full discovery flow with header priority, then path-specific, then root well-knowngetAuthorizationServerUrl()- Extracts first authorization server from metadataOAuth Server Discovery Flow
discoverOAuthServerInfo()function inutils.tsimplementing the MCP spec discovery flow:WWW-Authenticateheaderresource_metadataURL from header (if present)authorization_serversto find the actual OAuth serverEnhanced Scope Resolution
Updated
NodeOAuthClientProviderwith new scope priority order:WWW-Authenticateheader (new!)scopes_supportedfrom Protected Resource Metadata (new!)scopes_supportedfrom Authorization Server Metadataopenid email profile)Client & Proxy Integration
client.tsandproxy.tsnow calldiscoverOAuthServerInfo()on startupNodeOAuthClientProviderBenefits
scopes_supportedfrom PRM for proper authorizationTesting
Test with Supabase MCP Server
Closes #192