fix(mcp): use scopes from protected resource metadata (RFC 9728)#2212
Conversation
When discovering OAuth configuration for MCP servers, the scopes_supported field from Protected Resource Metadata was being ignored. According to RFC 9728, Protected Resource Metadata defines scopes specific to that resource, which should take precedence over Authorization Server Metadata scopes. This fix ensures that scopes from Protected Resource Metadata are used when available, while maintaining backward compatibility by falling back to Authorization Server Metadata scopes. Fixes OAuth authorization links missing scope parameter for ModelScope MCP server. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
📋 Review SummaryThis PR fixes an important OAuth compliance issue where 🔍 General Feedback
🎯 Specific Feedback🔵 Low
✅ Highlights
|
The tests used fixed wait times (200ms) that were too close to the auto-advance timeout (150ms). In CI environments (especially Windows with Node 20), timing can be less predictable due to event loop scheduling differences, causing race conditions. Changes: - Increased wait(200) to wait(300) for auto-advance tests - Increased wait() to wait(100) for navigation tests in custom input state test Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Problem
When discovering OAuth configuration for MCP servers, the
scopes_supportedfield from Protected Resource Metadata was being ignored. According to RFC 9728, Protected Resource Metadata defines scopes specific to that resource, which should take precedence over Authorization Server Metadata scopes.This caused OAuth authorization links to be generated without the
scopeparameter when connecting to MCP servers like ModelScope, wherescopes_supportedis defined in Protected Resource Metadata but not in Authorization Server Metadata.Root Cause
The
discoverOAuthConfigmethod only extracted scopes from Authorization Server Metadata viametadataToOAuthConfig(), ignoring thescopes_supportedfield in Protected Resource Metadata.Example - ModelScope Configuration:
Protected Resource Metadata (
/.well-known/oauth-protected-resource):{ "scopes_supported": ["openid", "profile", "list-operational-mcp", "manage-mcp-deployment"] }Authorization Server Metadata (
/.well-known/oauth-authorization-server):{ // No scopes_supported field }Solution
scopes_supportedfield toOAuthProtectedResourceMetadatainterfacediscoverOAuthConfigto use scopes from Protected Resource Metadata when availablediscoverOAuthFromWWWAuthenticatewith the same fixScope Priority Logic:
Screenshots
Before Fix
OAuth authorization link missing
scopeparameter.After Fix
OAuth authorization link now includes
scopeparameter with correct scopes.Changes
packages/core/src/mcp/oauth-utils.ts: Addedscopes_supportedto interface and scope merging logicpackages/core/src/mcp/oauth-utils.test.ts: Added 2 test cases for the fixTesting
should use scopes from protected resource metadata when availableshould prefer protected resource scopes over auth server scopesReferences