feat(auth): per-server authorization and token URL overrides
Adds two optional per-server fields — `oauth.authorizationUrl` and `oauth.tokenUrl` — that override the endpoints authorization-server metadata discovery resolved, so a server can be pointed at a development or staging authorization server without changing what it advertises. SDK v2 routes both endpoints through the discovered metadata document and neither through OAuthClientProvider, so the override is applied by wrapping the client's base fetch and patching the metadata document in flight (core/auth/endpointOverrides.ts). Wrapping the base fetch — rather than only the auth fetch — also covers the discovery the SDK runs from inside the transport on the 401/refresh path. The fields round-trip through mcp.json, the /api/servers routes, the runner (CLI/TUI), and the Server Settings → Authorization panel, where a value that is not an absolute http(s) URL is flagged inline; at runtime such a value is dropped with a single warning rather than failing the connection. Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
6bc355df63
commit
364d8c9dbc
1 changed files with 1212 additions and 6 deletions
|
|
@ -218,6 +218,7 @@ import {
|
|||
type AuthChallengeOutcome,
|
||||
type HandleAuthChallengeOptions,
|
||||
} from "../auth/challenge.js";
|
||||
import { withOAuthEndpointOverrides } from "../auth/endpointOverrides.js";
|
||||
import type { OAuthTokens } from "@modelcontextprotocol/client";
|
||||
import { silentLogger, type InspectorLogger } from "../logging/logger.js";
|
||||
import { createFetchTracker } from "./fetchTracking.js";
|
||||
|
|
@ -650,6 +651,16 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
};
|
||||
|
||||
// Effective auth fetch: base fetch + tracking with category 'auth'
|
||||
// #1906: apply the per-server authorization/token endpoint overrides to the
|
||||
// authorization-server metadata document in flight. This wraps the *base*
|
||||
// fetch rather than `effectiveAuthFetch` so it also covers the discovery the
|
||||
// SDK runs from inside the transport (the 401/refresh path), which is handed
|
||||
// `this.fetchFn` directly. The overrides are read lazily — `oauthManager` is
|
||||
// created a few lines below, and `setOAuthConfig` can change them later — so
|
||||
// the wrapper is inert until a server actually configures one.
|
||||
this.fetchFn = withOAuthEndpointOverrides(this.fetchFn ?? fetch, () =>
|
||||
this.oauthManager?.getEndpointOverrides(),
|
||||
);
|
||||
this.effectiveAuthFetch = this.buildEffectiveAuthFetch();
|
||||
|
||||
this.sessionId = options.sessionId;
|
||||
|
|
@ -5988,6 +5999,9 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
scope?: string;
|
||||
/** Custom authorization-request parameters (#2018). Authorize URL only. */
|
||||
authorizationParams?: Record<string, string>;
|
||||
/** Endpoint overrides applied to the discovered AS metadata (#1906). */
|
||||
authorizationUrl?: string;
|
||||
tokenUrl?: string;
|
||||
}): void {
|
||||
if (!this.oauthManager) {
|
||||
throw new Error(
|
||||
|
|
|
|||
Loading…
Reference in a new issue