You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(auth): apply endpoint overrides when the AS publishes no metadata - #2691
The Authorization/Token URL overrides (#1906) were applied by patching the authorization-server metadata document in flight. When the server publishes no metadata (e.g. a gateway fronting Entra ID), discovery returned nothing, the SDK fell back to /authorize and /token on the MCP server's origin, and the overrides were silently ignored.
Fix
withOAuthEndpointOverrides (core/auth/endpointOverrides.ts) now answers the final discovery candidate — when it fails with a status the SDK walks past (4xx / 502), the request is a GET, and an override is configured — with a minimal RFC 8414 document: the configured endpoint(s), and the SDK's own /authorize, /token, /register fallbacks for anything left blank. issuer is the AS URL being discovered, so issuer validation and callback binding see what they would have with no document. Earlier candidates are never pre-empted, and a 5xx is left for the SDK to surface.
The last candidate is always an openid-configuration URL, which the SDK validates as an OIDC document; rather than fabricate jwks_uri, the synthesized RFC 8414 document reaches the SDK through the existing withRfc8414OidcCompat wrapper (already composed outermost in InspectorClient). That wrapper now carries the synthesized marker through instead of warning that the server returned it.
The response is stamped x-inspector-oauth-metadata-synthesized so the Network tab doesn't present it as the server's answer.
Docs: docs/mcp-server-configuration.md replaces the note stating the old limitation.
Tests
clients/web/src/test/core/auth/endpointOverrides.test.ts: final-candidate detection pinned against the SDK's buildDiscoveryUrls; synthesis contents; 404/502 vs 500; earlier candidate, non-GET, unconfigured all left alone; compat pass-through; and the issue's reproduction end to end through the SDK's discoverAuthorizationServerMetadata + startAuthorization for root and path-hosted servers, asserting the authorization URL is the override.
…#2562)
When authorization-server discovery found no metadata document, the SDK
fell back to /authorize and /token on the server's origin and the
configured Authorization/Token URL overrides had nothing to patch, so a
gateway fronting an external AS (Entra ID) could not be authorized.
withOAuthEndpointOverrides now answers a failed final discovery
candidate with a minimal RFC 8414 document carrying the overrides (and
the SDK's own /authorize, /token, /register fallbacks for anything not
overridden), issuer set to the AS URL being discovered. The compat
wrapper hands it to discovery without attributing it to the server, and
the response carries x-inspector-oauth-metadata-synthesized.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
Response headers are server-controlled, so the compat wrapper now
recognizes a synthesized document through a module-owned WeakSet; the
x-inspector header is only an outward label.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
Copilot round 1: 1 finding, fixed in b907417 (identify synthesized metadata by object identity via a WeakSet, not by the server-controllable header; spoof test added). Replied in-thread. local:gate green. Requesting round 2.
…e match (#2562)
An authorization server whose own path ends in
/.well-known/openid-configuration made every discovery candidate end
with that suffix, so synthesis fired on the first one with a wrong
issuer. The earlier candidates always start with a well-known segment,
so exclude those.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
Copilot round 2: 1 finding (final-candidate suffix ambiguous for an issuer whose path ends in /.well-known/openid-configuration), fixed in 9bb8d75 and pinned against buildDiscoveryUrls. Replied in-thread. local:gate green. Requesting round 3.
URL shape plus GET also matches an SSE/streamable GET to an MCP endpoint
whose URL ends in the OIDC well-known path, whose OAuth 401 would have
been replaced. SDK discovery always sends Accept: application/json and
those transports ask for text/event-stream, so require the former.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
Copilot round 3: 1 finding (a GET to an MCP endpoint ending in the OIDC well-known path could have its 401 replaced), fixed in 0a6724e by requiring discovery's Accept: application/json. Replied in-thread. local:gate green. Requesting round 4.
The SDK appends text/event-stream to a user-configured Accept, so a
streamable-HTTP GET can carry application/json too. Parse media types
and exclude any request asking for an event stream.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
Copilot round 4: 1 finding (a mixed application/json, text/event-stream Accept could pass the discovery guard), fixed in 56b8104 by parsing media types and excluding event-stream. Replied in-thread. local:gate green. Requesting round 5.
Align discovery retry condition with SDK to preserve overrides
core/auth/endpointOverrides.ts:315
This does not actually mirror the SDK's discovery condition: @modelcontextprotocol/[email protected] continues for every non-OK status below 500 (including a redirect that a custom fetch did not follow, and status 0), plus 502. On such a final candidate this wrapper returns the response unchanged, so discovery still yields no metadata and the configured overrides are ignored. Match the SDK predicate here and add a non-followed redirect regression case.
The SDK walks past every non-OK status below 500 (including a
non-followed redirect or opaque status 0) plus 502, not just 4xx.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
Copilot round 5: no inline findings; the "Previously missed" note (the discovery-continue predicate covered only 4xx + 502, while the SDK walks past every non-OK status below 500 + 502) was correct and is fixed in b29eb6c, with a non-followed-redirect regression test. (The same narrower predicate in oidcDiscoveryCompat.ts predates this PR and is left as is.) local:gate green. Requesting round 6.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Reconstructing the issuer from a normalized candidate can trigger SDK issuer mismatches for valid non-canonical authorization-server URLs.
0 open findings
Previously missed (1)
In code that hasn't changed since last review
Preserve original issuer to avoid normalized URL mismatch
core/auth/endpointOverrides.ts:359
This reconstructs issuer from the normalized discovery URL, which loses spelling that the SDK still validates exactly against the original authorization-server string. For example, protected-resource metadata may name https://GATEWAY.example.com/api or https://gateway.example.com:443/api; buildDiscoveryUrls requests the normalized lowercase/default-port-free candidate, this returns https://gateway.example.com/api, and @modelcontextprotocol/[email protected] then throws IssuerMismatchError instead of applying the overrides. Preserve or normalize the original authorization-server identifier at the point discovery is invoked rather than recovering it from the candidate URL, and cover a non-canonical but valid URL in the end-to-end test.
Copilot round 6: 0 open findings. The "Previously missed" note (issuer reconstructed from a normalized candidate URL could mismatch a non-canonically spelled AS named in protected-resource metadata, e.g. upper-case host or explicit :443) is declined as out of scope: #2562 is a server exposing no OAuth metadata, where the SDK derives the AS URL as new URL("/", serverUrl), which is already canonical, so the reconstructed issuer matches. The declined case needs PRM naming a non-canonical AS that then serves no metadata, and handling it would mean threading discovery context through the fetch wrappers. In that case the outcome is the SDK's own IssuerMismatchError, not a wrong redirect.
Review loop closed: the round held only an out-of-scope finding (pr-flow 7c exit). Rounds 1 to 5 each fixed one in-scope finding, with local:gate green after each.
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
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.
Closes #2562
Problem
The Authorization/Token URL overrides (#1906) were applied by patching the authorization-server metadata document in flight. When the server publishes no metadata (e.g. a gateway fronting Entra ID), discovery returned nothing, the SDK fell back to
/authorizeand/tokenon the MCP server's origin, and the overrides were silently ignored.Fix
withOAuthEndpointOverrides(core/auth/endpointOverrides.ts) now answers the final discovery candidate — when it fails with a status the SDK walks past (4xx / 502), the request is a GET, and an override is configured — with a minimal RFC 8414 document: the configured endpoint(s), and the SDK's own/authorize,/token,/registerfallbacks for anything left blank.issueris the AS URL being discovered, so issuer validation and callback binding see what they would have with no document. Earlier candidates are never pre-empted, and a 5xx is left for the SDK to surface.openid-configurationURL, which the SDK validates as an OIDC document; rather than fabricatejwks_uri, the synthesized RFC 8414 document reaches the SDK through the existingwithRfc8414OidcCompatwrapper (already composed outermost inInspectorClient). That wrapper now carries the synthesized marker through instead of warning that the server returned it.x-inspector-oauth-metadata-synthesizedso the Network tab doesn't present it as the server's answer.docs/mcp-server-configuration.mdreplaces the note stating the old limitation.Tests
clients/web/src/test/core/auth/endpointOverrides.test.ts: final-candidate detection pinned against the SDK'sbuildDiscoveryUrls; synthesis contents; 404/502 vs 500; earlier candidate, non-GET, unconfigured all left alone; compat pass-through; and the issue's reproduction end to end through the SDK'sdiscoverAuthorizationServerMetadata+startAuthorizationfor root and path-hosted servers, asserting the authorization URL is the override.npm run local:gategreen. No UI change.🤖 Generated with Claude Code