View the provider source on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/react/McpClientProvider.tsx
View the standalone hook source: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/react/useMcp.ts
View the shared React client types: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/react/types.ts
View the standalone hook source: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/react/useMcp.ts
View the shared React client types: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/react/types.ts
McpClientProvider for multi-server apps and useMcp() for a single HTTP MCP server.
All exports come from mcp-use/react:
McpClientProvider
McpClientProvider creates a React context for multiple MCP server connections. It loads initial servers, applies provider defaults, persists configuration when a storage provider is set, and exposes server state through useMcpClient() and useMcpServer().
Parameters
SignatureReact children rendered inside the provider.Initial server map. Servers in this map connect when the provider mounts.Default OAuth callback URL for servers that do not setcallbackUrl.Default proxy configuration for all servers. Per-serverproxyConfigoverrides these values.Whether direct connection failures caused by FastMCP or CORS should retry through a proxy.Client metadata and default advertised MCP capabilities for every managed server.Storage adapter used to load, save, and remove server configurations.Whentrue, logs MCP protocol messages in the browser for debugging.Called after a server is added.Called after a server is removed.Called when a managed server changes connection state.Called when any managed server requests sampling.Called when any managed server requests elicitation.
useMcpClient
useMcpClient() returns the multi-server context. It must run under McpClientProvider.
Returns
Throws ThrowsAll managed servers with connection state, methods, notifications, and pending request queues.Adds a server. Calls with an existing id are ignored.Removes a server. SetclearCredentials: trueto also clear persisted OAuth credentials.Updates display metadata without reconnecting.Updates connection-affecting options and reconnects the server.Returns a managed server by id.Whether configured storage has finished loading.
Error when called outside McpClientProvider.
Signature
useMcpServer
useMcpServer(id) returns one managed server by id. It must run under McpClientProvider.
Parameters
ReturnsServer id passed toaddServer()or themcpServersmap.
Throws ThrowsThe matching server, orundefinedwhen no server with that id is registered.
Error when called outside McpClientProvider.
Signature
useMcp
useMcp(options) connects to one HTTP MCP server from a React component. Use it directly for simple single-server apps or use McpClientProvider for multi-server apps.
Parameters
ReturnsConnection, authentication, callback, reconnection, and transport options.
SignatureConnection state, discovered tools/resources/prompts, protocol methods, auth metadata, logs, and the underlying browser client.
McpServerOptions
McpServerOptions configures one server managed by McpClientProvider. It extends UseMcpOptions but replaces low-level callbacks with provider-managed request queues.
Fields
HTTP MCP endpoint URL.Display name shown before server metadata loads.Whenfalse, the provider does not connect to the server. Defaults totrue.Headers sent with HTTP transport requests.Transport preference. Use"auto"for streamable HTTP with fallback.Initial connection timeout in milliseconds. Defaults to30000.Proxy settings for this server.Per-server automatic proxy fallback setting.Whentrue, the server enterspending_authuntilauthenticate()is called.Whentrue, OAuth uses full-page redirect instead of a popup.OAuth callback URL for this server.External OAuth provider for headless or custom runtimes.Pre-registered OAuth client credentials for servers without Dynamic Client Registration.Client metadata sent during MCP initialization and OAuth registration.Retry initial connection failures. A number sets the retry delay in milliseconds.autoReconnectboolean | number | { enabled?: boolean; initialDelay?: number; healthCheckInterval?: number | false; healthCheckTimeout?: number }Application-level reconnection and health check behavior.SDK transport-level retry settings.Transport wrapper for logging, monitoring, or custom behavior.Per-server app callback for sampling requests.Per-server app callback for elicitation requests.Per-server app callback for notifications.
McpServer
McpServer is the server object returned by useMcpServer() and listed in useMcpClient().servers. It includes all UseMcpResult fields plus provider-managed metadata and queues.
Fields and methods
Provider server id.Server URL.Display name supplied by the app.Current connection state.Discovered server tools.Discovered server resources.Discovered server resource templates.Discovered server prompts.serverInfo{ name: string; title?: string; version?: string; websiteUrl?: string; icons?: Array<{ src: string; mimeType?: string }>; icon?: string }Server metadata from initialization.Failure message whenstateis"failed".Calls a server tool.Reads a resource by URI.Refreshes the resource list.Refreshes the prompt list.Gets a prompt by name.Requests prompt or resource template completions.Refreshes the tool list.Refreshes the resource list.Refreshes the resource template list.Refreshes the prompt list.Refreshes tools, resources, resource templates, and prompts.Attempts to reconnect after failure.Disconnects from the server.Starts OAuth authentication.Clears OAuth storage for this server URL.Stored notifications from this server.Unread notification count.Marks one notification as read.Marks all notifications as read.Clears stored notifications.Pending sampling requests from this server.Approves a sampling request.Rejects a sampling request.Pending elicitation requests from this server.Approves an elicitation request.Rejects an elicitation request.Underlying browser client.
UseMcpOptions
UseMcpOptions configures one standalone React MCP connection. McpServerOptions reuses most of these fields.
Fields
HTTP MCP endpoint URL.Whenfalse, no connection is attempted. Defaults totrue.Proxy settings for this connection.Retries direct FastMCP or CORS failures through a proxy. Defaults totruefor standaloneuseMcp().OAuth callback URL. Defaults to/oauth/callbackon the current origin.OAuth localStorage key prefix. Defaults to"mcp:auth".HTTP request headers.Console log level.Retry initial connection failures. A number sets the retry delay in milliseconds.autoReconnectboolean | number | { enabled?: boolean; initialDelay?: number; healthCheckInterval?: number | false; healthCheckTimeout?: number }Application-level reconnection and health check behavior. Defaults to3000.SDK transport-level retry settings.Popup feature string for OAuth popup mode.Transport preference."sse"is deprecated but supported.Whentrue, wait forauthenticate()before opening OAuth.Use full-page OAuth redirect instead of a popup.Called just before the OAuth popup opens.Options passed to the underlying MCP SDK client.Initial connection timeout in milliseconds. Defaults to30000.SSE read timeout in milliseconds. Defaults to300000.Transport wrapper.Called when the server sends a notification.Handlessampling/createMessagerequests.Handleselicitation/createrequests.Client metadata sent during MCP initialization and OAuth registration.Custom fetch function for MCP HTTP requests.External OAuth provider.Pre-registered OAuth client settings.
StorageProvider
StorageProvider persists provider-managed server configuration. Implement this interface for localStorage, IndexedDB, AsyncStorage, or backend-backed storage.
Methods
Returns all stored server configurations.Replaces all stored server configurations.Adds or updates one server configuration.Removes one server configuration.Clears all server configurations.getServerMetadata(id: string) => Promise<CachedServerMetadata | undefined> | CachedServerMetadata | undefinedOptionally returns cached server metadata.Optionally stores cached server metadata.Optionally removes cached server metadata.
LocalStorageProvider
LocalStorageProvider stores server configs and metadata in browser localStorage.
Parameters
SignaturelocalStorage key used for server configurations. Metadata uses${storageKey}-metadata.
MemoryStorageProvider
MemoryStorageProvider stores server configs and metadata in memory. Data is lost on reload or provider unmount.
Signature
Related
- React Integration: guide to using the provider and hooks in a React app.
- Authentication: OAuth and bearer token setup.
- Completions: prompt and resource template completion examples.