fix(client/sse): extract protected resource from eventsource 401 #675
+19
−7
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.
Previously the SSE connection would always default to the
/.well-known/oauth-protected-resource
URI, ignoring theresource_metadata
portion of thewww-authenticate
returned in a 401.Extract the metadata from the initial 401, so RS servers with custom protected resource URIs (as in RFC9728, section 3.1)) continue to work as expected.
Motivation and Context
www.mcp.run
hosts multiple MCP server resources. We intend to serve/.well-known/oauth-protected-resource/*
for each protected resource, directing connecting clients to the appropriate resource data usingwww-authenticate
. We do this so that we can return theresource
attribute matching the server resource accessed. This works as expected with the HTTP streaming transport, but fails with the current SSE server.The SSE server currently does not intercept the
www-authenticate
header to extract theresource_metadata
URI. As a result, it requests the top-level protected resource documentwhose
resource
attribute does not match the resource being accessed by the client. This causes the client to fail.This change aligns the SSE
www-authenticate
behavior with the HTTP streaming transport.How Has This Been Tested?
I've tested these changes against our development server.
Breaking Changes
This should be largely non-breaking -- users that provide their own
fetch
implementation will continue to see it called, but they may see additional headers (viathis._commonHeaders()
.)Types of changes
Checklist