feat(core): configure MCP OAuth authorization server metadata - #49126
Merged
Merged
Conversation
Add oauth.auth_server_metadata_url for remote MCP servers that do not publish protected resource metadata naming their authorization server. When set, the document is loaded directly and seeds discovery state for both interactive authorization and connect-time token refresh, so the SDK does not fall back to treating the resource host as the issuer. Closes #44790
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #44790
Type of change
What does this PR do?
Adds
oauth.auth_server_metadata_urlto remote MCP server config. Some MCP servers do not publish RFC 9728 protected resource metadata that names their authorization server; without it, discovery falls back to treating the resource host as the issuer and builds an authorization URL that does not exist.When the field is set,
McpOAuth.configuredDiscoveryloads that OAuth 2.0 (RFC 8414) or OpenID Connect discovery document, validates it with the SDK schemas, and seedsOAuthDiscoveryStatewith the document'sissuerand the configured MCP URL as the protected resource. This is used in two places:authorize()uses it instead ofdiscoverOAuthServerInfofor the interactive login.provider().discoveryState()loads it lazily, so connect-time token refresh also reaches the right token endpoint.Servers without the field behave exactly as before.
How did you verify your code works?
packages/core/test/mcp-oauth.test.ts: the resource server returns 404 for every path, the configured metadata document lives on a separate issuer host. Asserts the authorization URL lands on the issuer, carries the configured MCP URL asresource, and that a connect-time provider refreshes through the configured issuer's token endpoint.bun test test/mcp-oauth.test.tsinpackages/core: 17/17.bun run checkfrom the repo root: 35/35 tasks.packages/protocol/openapi.jsonandpackages/clienttypes.Checklist