fix: include transport path in Protected Resource Metadata resource URL#2189
fix: include transport path in Protected Resource Metadata resource URL#2189Br1an67 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
The resource field in /.well-known/oauth-protected-resource was set to the base resource_server_url (e.g. http://localhost:8000/) instead of the actual protected endpoint URL (e.g. http://localhost:8000/mcp). Per RFC 9728, the resource identifier must match the URL that clients use to access the protected resource. Append the transport path (streamable_http_path or sse_path) to the resource_server_url in both lowlevel/server.py and mcpserver/server.py.
|
Thanks for the PR and for digging into this — the underlying VS Code error is real and the issue has bitten multiple people. However, the approach here introduces a regression for servers that are already configured correctly, so I'm going to close this in favor of a docs-focused fix. Why appending
|
Summary
Fixes #1264
The
resourcefield in/.well-known/oauth-protected-resourcewas set to the baseresource_server_url(e.g.,http://localhost:8000/) instead of the actual protected endpoint URL (e.g.,http://localhost:8000/mcp). Per RFC 9728, the resource identifier must match the URL that clients use to access the protected resource.This caused VS Code Copilot (and other compliant clients) to reject the server with:
Changes
src/mcp/server/lowlevel/server.py: Appendstreamable_http_pathtoresource_server_urlwhen constructing the resource URL for both the protected resource metadata endpoint and the WWW-Authenticate header.src/mcp/server/mcpserver/server.py: Same fix for the SSE transport path.Test