mcp-use TypeScript API
    Preparing search index...

    Class NodeOAuthClientProvider

    Node/CLI OAuth client provider for MCP. Owns a localhost loopback callback server, opens the user's browser, and resolves the authorization code via getAuthorizationCode() — designed for the orchestrator pattern in useMcp.ts:1121-1145.

    Use the static create() factory; the constructor is internal because port reservation is async.

    Implements

    • OAuthClientProvider
    Index
    port: number

    Reserved localhost callback port.

    serverUrl: string

    Protected MCP server URL associated with this provider.

    • get callbackPort(): number

      Local callback port, useful for status output and tests.

      Returns number

    • get clientMetadata(): {}

      OAuth client metadata presented during registration.

      Returns {}

    • get clientMetadataUrl(): string | undefined

      OAuth Client ID Metadata Document URL, when configured.

      Returns string | undefined

    • get hasPendingFlow(): boolean

      True if redirectToAuthorization() has been called and we're awaiting a callback (loopback bound, browser opened). Lets orchestrators detect when the SDK transport has already kicked off the flow on a 401, so they can skip straight to getAuthorizationCode() instead of calling auth() again (which would throw "already in progress").

      Returns boolean

    • get redirectUrl(): string

      Loopback redirect URL registered for this provider.

      Returns string

    • get serverUrlHash(): string

      Stable hash of the protected server URL used to namespace storage.

      Returns string

    • get storageKeyPrefix(): string

      Prefix used for persisted OAuth session keys.

      Returns string

    • Loads saved OAuth client registration information.

      Parameters

      • Optionalctx: OAuthClientInformationContext

        Optional registration context.

      Returns Promise<{} | undefined>

      Saved registration information, or undefined.

    • Loads the saved PKCE code verifier.

      Returns Promise<string>

      The saved verifier.

    • Returns previously saved OAuth discovery state.

      Returns Promise<OAuthDiscoveryState | undefined>

      Saved discovery state, or undefined.

    • Resolves with the authorization code captured by the loopback callback.

      Returns Promise<string>

      The authorization code received by the loopback callback.

      This compatibility method omits the RFC 9207 issuer. OAuth flow orchestrators should use getAuthorizationResponse when available. Must be called after redirectToAuthorization(). Returns the same promise whether the callback has fired or not — callers may subscribe before or after.

    • Invalidates selected persisted OAuth credentials.

      Parameters

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

        Credential group to remove.

      Returns Promise<void>

    • Bind the loopback server, set up the pending-code deferred, and ask the platform to open the user's browser. Does NOT await the code; the orchestrator awaits via getAuthorizationCode().

      Parameters

      • authorizationUrl: URL

        Authorization URL generated by the SDK.

      Returns Promise<void>

      A promise that resolves once the loopback listener is ready and the browser-open attempt completes.

    • Persists OAuth client registration information.

      Parameters

      • info: {}

        Client information to save.

      • Optionalctx: OAuthClientInformationContext

        Optional registration context.

      Returns Promise<void>

    • Persists a PKCE code verifier.

      Parameters

      • codeVerifier: string

        Verifier to save.

      Returns Promise<void>

    • Persists OAuth discovery state.

      Parameters

      • state: OAuthDiscoveryState

        Discovery state to save.

      Returns Promise<void>

    • Persists OAuth tokens.

      Parameters

      • tokens: {}

        Tokens to save.

      • Optionalctx: OAuthClientInformationContext

        Optional client registration context.

      Returns Promise<void>

    • Loads saved OAuth tokens.

      Parameters

      • Optionalctx: OAuthClientInformationContext

        Optional client registration context.

      Returns Promise<{} | undefined>

      Saved tokens, or undefined when none exist.

    • Creates a Node OAuth provider and reserves a localhost callback port.

      Parameters

      • serverUrl: string

        Protected MCP server URL.

      • options: NodeOAuthOptions = {}

        OAuth metadata, storage, loopback, and browser options.

      Returns Promise<NodeOAuthClientProvider>

      A provider ready to participate in the SDK OAuth flow.