mcp-use TypeScript API
    Preparing search index...

    Class BrowserOAuthClientProvider

    Browser-compatible OAuth client provider for MCP using localStorage.

    Implements

    • OAuthClientProvider
    Index
    onPopupWindow:
        | ((url: string, features: string, window: Window | null) => void)
        | undefined

    Callback invoked immediately before an authorization popup opens.

    preventAutoAuth?: boolean

    Whether initial connection waits for explicit authentication.

    serverUrl: string

    Protected MCP server URL associated with this provider.

    staticClientInfo?: {}

    Pre-registered public client information, when configured.

    • get callbackUrl(): string

      OAuth redirect URI.

      Returns string

    • get clientMetadata(): {}

      Metadata about this OAuth client.

      Returns {}

    • get clientMetadataUrl(): string | undefined

      External URL the server should use to fetch client metadata document

      Returns string | undefined

    • get clientName(): string

      Human-readable OAuth client name.

      Returns string

    • get clientUri(): string

      Public website describing the OAuth client.

      Returns string

    • get hasPendingFlow(): boolean

      Whether an authorization flow is awaiting completion.

      Returns boolean

    • get logoUri(): string

      Public OAuth client logo URL.

      Returns string

    • get redirectUrl(): string

      The URL to redirect the user agent to after authorization. Return undefined for non-interactive flows that don't require user interaction (e.g., client_credentials, jwt-bearer).

      Returns string

    • get scope(): string | undefined

      Space-delimited OAuth scopes requested by the client.

      Returns string | undefined

    • get serverUrlHash(): string

      Stable hash used to namespace storage for this server.

      Returns string

    • get storageKeyPrefix(): string

      Prefix used for persisted OAuth keys.

      Returns string

    • Removes OAuth state stored for this server.

      Returns number

      The number of storage entries removed.

    • Returns the configured or dynamically registered OAuth client information.

      Parameters

      • Optionalctx: OAuthClientInformationContext

        Optional registration context.

      Returns Promise<{} | undefined>

      OAuth client information, or undefined when not registered.

    • Loads the PKCE code verifier for the current session, necessary to validate the authorization result.

      Returns Promise<string>

    • Return previously saved OAuth discovery state, or undefined.

      Returns Promise<OAuthDiscoveryState | undefined>

    • Return the stored public OAuth client ID. Browser providers do not retain client secrets.

      Returns Promise<{ client_id: string } | null>

    • Returns a provider-scoped storage key.

      Parameters

      • keySuffix: string

        Suffix identifying the stored value.

      Returns string

      Namespaced storage key.

    • Retrieves the last URL passed to redirectToAuthorization. Useful for manual fallback.

      Returns string | null

    • Returns a fetch function, scoped to this provider, that routes OAuth metadata and non-browser OAuth endpoint requests through the configured oauthProxyUrl to bypass CORS. Authorization endpoints are navigated by the browser and all unrelated requests pass through unchanged.

      Unlike patching the global fetch, the returned function only affects the transport/auth calls it is explicitly handed to (via the SDK transport's fetch option or auth({ fetchFn })). Connecting one server "Via Proxy" therefore never alters fetch behavior for other servers, other connections, or the rest of the page.

      OAuth metadata is always fetched with cache: "no-store", including in direct mode. Authorization servers commonly vary CORS headers by Origin; bypassing the browser HTTP cache prevents a revalidated response cached for another localhost origin from poisoning discovery. When OAuth proxying is disabled or no oauthProxyUrl is configured, all requests still go directly to their original URLs.

      Parameters

      • OptionalbaseFetch: {
            (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
            (input: string | URL | Request, init?: RequestInit): Promise<Response>;
        }

        The fetch used for non-OAuth requests and for the underlying proxy calls. Defaults to the global fetch.

          • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
          • Parameters

            • input: URL | RequestInfo
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | URL | Request, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | URL | Request
            • Optionalinit: RequestInit

            Returns Promise<Response>

      Returns
          | {
              (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
              (input: string | URL | Request, init?: RequestInit): Promise<Response>;
          }
          | undefined

      • {
            (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
            (input: string | URL | Request, init?: RequestInit): Promise<Response>;
        }
          • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
          • Parameters

            • input: URL | RequestInfo
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | URL | Request, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | URL | Request
            • Optionalinit: RequestInit

            Returns Promise<Response>

      • undefined
    • Return the protected-resource URL selected during OAuth discovery.

      Returns Promise<string | null>

    • Return the token endpoint from the SDK's persisted discovery state. Returns null before a successful authorization discovery.

      Returns Promise<string | null>

    • If implemented, provides a way for the client to invalidate (e.g. delete) the specified credentials, in the case where the server has indicated that they are no longer valid. This avoids requiring the user to intervene manually.

      Parameters

      • scope: "tokens" | "all" | "client" | "verifier" | "discovery"

      Returns Promise<void>

    • Marks the current authorization flow as complete.

      Returns void

    • Generates and persists StoredState for an authorization request, and returns the sanitized URL with the state param appended. Does NOT open a popup or redirect — use redirectToAuthorization for that.

      Parameters

      • authorizationUrl: URL

      Returns Promise<string>

    • Redirects the user agent to the authorization URL, storing necessary state.

      Parameters

      • authorizationUrl: URL

        The fully constructed authorization URL from the SDK.

      Returns Promise<void>

    • Persists public OAuth client registration information.

      Static client configuration takes precedence, and browser providers discard any client secret returned for a public client.

      Parameters

      • clientInformation: {}

        Registration information to save.

      • Optionalctx: OAuthClientInformationContext

        Optional registration context.

      Returns Promise<void>

    • Saves a PKCE code verifier for the current session, before redirecting to the authorization flow.

      Parameters

      • codeVerifier: string

      Returns Promise<void>

    • Persist OAuth discovery state (SEP-2352). Delegated to the session store; implementing this silences the SDK's per-callback warning and enables the authorization-server mix-up defense on the callback leg.

      Parameters

      • state: OAuthDiscoveryState

      Returns Promise<void>

    • Stores new OAuth tokens for the current session, after a successful authorization.

      Parameters

      • tokens: {}
      • Optionalctx: OAuthClientInformationContext

        Carries the resolved authorization-server issuer. Providers that persist tokens per authorization server should store the entry keyed by ctx.issuer.

      Returns Promise<void>

    • Loads any existing OAuth tokens for the current session, or returns undefined if there are no saved tokens.

      Parameters

      • Optionalctx: OAuthClientInformationContext

        Carries the resolved authorization-server issuer. Providers that persist tokens per authorization server should return the entry keyed by ctx.issuer. Providers with a single token set may ignore it. When called with no ctx — the transport's per-request bearer-token read — return the most-recently-saved token set; do not return undefined for ctx === undefined.

      Returns Promise<{} | undefined>