Skip to content

fix: include transport path in Protected Resource Metadata resource URL#2189

Open
Br1an67 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Br1an67:fix/issue-1264-resource-metadata-url
Open

fix: include transport path in Protected Resource Metadata resource URL#2189
Br1an67 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Br1an67:fix/issue-1264-resource-metadata-url

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Summary

Fixes #1264

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.

This caused VS Code Copilot (and other compliant clients) to reject the server with:

Protected Resource Metadata resource "http://localhost:8000/" does not match MCP server resolved resource "http://localhost:8000/mcp"

Changes

  • src/mcp/server/lowlevel/server.py: Append streamable_http_path to resource_server_url when 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

uv run pytest tests/server/auth/test_protected_resource.py -x  # 14 passed
uv run pytest tests/server/mcpserver/auth/ -x  # 42 passed
uv run ruff check src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py  # All passed

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Protected Resource Metadata resource erroneous when setting up authentication on server

1 participant