Skip to content

fix(client/sse): extract protected resource from eventsource 401 #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

chrisdickinson
Copy link
Contributor

Previously the SSE connection would always default to the /.well-known/oauth-protected-resource URI, ignoring the resource_metadata portion of the www-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 using www-authenticate. We do this so that we can return the resource 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 the resource_metadata URI. As a result, it requests the top-level protected resource document
whose 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 (via this._commonHeaders().)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed
Previously the SSE connection would always default to the
`/.well-known/oauth-protected-resource` URI, ignoring the `resource_metadata`
portion of the `www-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][1]))
continue to work as expected.

[1]: https://datatracker.ietf.org/doc/html/rfc9728#section-3.1
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ihrpr ihrpr merged commit 0506add into modelcontextprotocol:main Jun 20, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants