mcp-use TypeScript API
    Preparing search index...

    Interface McpClientProviderProps

    Props for McpClientProvider

    interface McpClientProviderProps {
        children: ReactNode;
        clientInfo?: {
            capabilities?: Record<string, unknown>;
            description?: string;
            icons?: { mimeType?: string; sizes?: string[]; src: string }[];
            name: string;
            title?: string;
            version: string;
            websiteUrl?: string;
        };
        defaultAutoProxyFallback?: | boolean
        | { enabled?: boolean; proxyAddress?: string };
        defaultCallbackUrl?: string;
        defaultOAuthProxyUrl?: string;
        defaultProxyConfig?: {
            headers?: Record<string, string>;
            proxyAddress?: string;
        };
        defaultServerConfig?: Partial<McpServerConfig>;
        enableRpcLogging?: boolean;
        mcpServers?: Record<string, McpServerConfig>;
        onElicitationRequest?: (
            request: PendingElicitationRequest,
            serverId: string,
            serverName: string,
            approve: (requestId: string, result: { [key: string]: unknown }) => void,
            reject: (requestId: string, error?: string) => void,
        ) => void;
        onSamplingRequest?: (
            request: PendingSamplingRequest,
            serverId: string,
            serverName: string,
            approve: (
                requestId: string,
                result: { [key: string]: unknown } | { [key: string]: unknown },
            ) => void,
            reject: (requestId: string, error?: string) => void,
        ) => void;
        onServerAdded?: (id: string, server: McpServer) => void;
        onServerRemoved?: (id: string) => void;
        onServerStateChange?: (
            id: string,
            state:
                | "discovering"
                | "pending_auth"
                | "authenticating"
                | "ready"
                | "failed",
        ) => void;
        storageProvider?: StorageProvider;
    }
    Index
    children: ReactNode

    React subtree that can access the MCP client context.

    clientInfo?: {
        capabilities?: Record<string, unknown>;
        description?: string;
        icons?: { mimeType?: string; sizes?: string[]; src: string }[];
        name: string;
        title?: string;
        version: string;
        websiteUrl?: string;
    }

    Client info for all servers (used for OAuth registration and server capabilities). Can be overridden per-server in addServer() options.

    The optional capabilities field sets default MCP capabilities advertised to every server managed by this provider (e.g. MCP Apps / SEP-1865 extensions). It is merged with per-server clientOptions.capabilities (per-server takes precedence) and is stripped from the actual MCP clientInfo wire field.

    Type Declaration

    • Optionalcapabilities?: Record<string, unknown>

      Default capabilities advertised to all servers managed by this provider. Per-server clientOptions.capabilities are merged on top, with per-server values taking precedence. Stripped from the MCP clientInfo wire field.

      capabilities: {
      views: true,
      // or explicitly:
      extensions: {
      "io.modelcontextprotocol/ui": { mimeTypes: ["text/html;profile=mcp-app"] },
      },
      }
    • Optionaldescription?: string

      Client description

    • Optionalicons?: { mimeType?: string; sizes?: string[]; src: string }[]

      Client icons (first icon used as logo_uri for OAuth)

    • name: string

      Client name displayed on OAuth consent pages (required)

    • Optionaltitle?: string

      Client title/display name

    • version: string

      Client version (required)

    • OptionalwebsiteUrl?: string

      Client website URL (used as client_uri for OAuth)

    defaultAutoProxyFallback?:
        | boolean
        | { enabled?: boolean; proxyAddress?: string }

    Enable automatic proxy fallback for all servers by default When enabled, if a direct connection fails with FastMCP or CORS errors, automatically retries using proxy configuration

    Type Declaration

    • boolean
    • { enabled?: boolean; proxyAddress?: string }
      • Optionalenabled?: boolean

        Whether automatic proxy fallback is enabled.

      • OptionalproxyAddress?: string

        Proxy endpoint used after direct connection fails.

    false
    
    defaultCallbackUrl?: string

    Default OAuth callback URL for all servers. Can be overridden per-server via the callbackUrl option in addServer(). Useful when the app is mounted at a sub-path (e.g. /inspector) so the OAuth redirect lands on the correct route without requiring a server-side redirect shim.

    defaultOAuthProxyUrl?: string

    Default same-origin OAuth BFF URL for browser OAuth requests.

    defaultProxyConfig?: { headers?: Record<string, string>; proxyAddress?: string }

    Default proxy configuration for all servers Can be overridden per-server in addServer() options

    Type Declaration

    • Optionalheaders?: Record<string, string>

      Default headers sent to the MCP proxy.

    • OptionalproxyAddress?: string

      Default MCP proxy endpoint.

    defaultServerConfig?: Partial<McpServerConfig>

    Default connection options merged under each server's options (per-server wins). Useful for app-wide auth UX such as preventAutoAuth or useRedirectFlow.

    enableRpcLogging?: boolean

    Enable RPC logging for debugging (browser only) Logs all MCP protocol messages to console

    mcpServers?: Record<string, McpServerConfig>

    Initial servers configuration (like Python MCPClient.from_dict) Servers defined here will be auto-connected on mount

    onElicitationRequest?: (
        request: PendingElicitationRequest,
        serverId: string,
        serverName: string,
        approve: (requestId: string, result: { [key: string]: unknown }) => void,
        reject: (requestId: string, error?: string) => void,
    ) => void

    Callback when an elicitation request is received from any server

    Type Declaration

      • (
            request: PendingElicitationRequest,
            serverId: string,
            serverName: string,
            approve: (requestId: string, result: { [key: string]: unknown }) => void,
            reject: (requestId: string, error?: string) => void,
        ): void
      • Parameters

        • request: PendingElicitationRequest

          The elicitation request details

        • serverId: string

          The ID of the server that sent the request

        • serverName: string

          The name of the server

        • approve: (requestId: string, result: { [key: string]: unknown }) => void

          Function to approve the request

        • reject: (requestId: string, error?: string) => void

          Function to reject the request

        Returns void

    onSamplingRequest?: (
        request: PendingSamplingRequest,
        serverId: string,
        serverName: string,
        approve: (
            requestId: string,
            result: { [key: string]: unknown } | { [key: string]: unknown },
        ) => void,
        reject: (requestId: string, error?: string) => void,
    ) => void

    Callback when a sampling request is received from any server

    Type Declaration

      • (
            request: PendingSamplingRequest,
            serverId: string,
            serverName: string,
            approve: (
                requestId: string,
                result: { [key: string]: unknown } | { [key: string]: unknown },
            ) => void,
            reject: (requestId: string, error?: string) => void,
        ): void
      • Parameters

        • request: PendingSamplingRequest

          The sampling request details

        • serverId: string

          The ID of the server that sent the request

        • serverName: string

          The name of the server

        • approve: (
              requestId: string,
              result: { [key: string]: unknown } | { [key: string]: unknown },
          ) => void

          Function to approve the request

        • reject: (requestId: string, error?: string) => void

          Function to reject the request

        Returns void

    onServerAdded?: (id: string, server: McpServer) => void

    Callback when a server is added

    onServerRemoved?: (id: string) => void

    Callback when a server is removed

    onServerStateChange?: (
        id: string,
        state:
            | "discovering"
            | "pending_auth"
            | "authenticating"
            | "ready"
            | "failed",
    ) => void

    Callback when a server's state changes

    storageProvider?: StorageProvider

    Storage provider for persisting server configurations When provided, automatically loads servers on mount and saves on changes