Skip to main content
Import from @mcp-use/client/react:
Use McpClientProvider for multi-server apps. Use standalone useMcp only for a single server.

Provider setup

Connection states

OAuth does not auto-start by default (preventAutoAuth: true). Show a sign-in button when state === "pending_auth".

OAuth callback

Create a route (default: /oauth/callback):
Override with defaultCallbackUrl on the provider or callbackUrl per server.

Proxy fallback

When direct browser connections fail (CORS / FastMCP), retry through a proxy:
MCP traffic and OAuth use separate proxy URLs so resource identity stays the upstream MCP URL.

Persistence

Built-in providers persist only non-secret connection settings. Supply bearer tokens, request headers, and proxy headers again at runtime after a reload. Browser OAuth tokens remain persistent by default and are encrypted with AES-256-GCM using a non-extractable origin key stored in IndexedDB.

Standalone useMcp

For one server without the provider:

Types

  • McpServerConfig — server options passed to addServer (replaces deprecated McpServerOptions).
  • displayName — your label for the server in UI.
  • serverInfo.name — name returned by the server at init.
Sampling, elicitation, and notifications are queued on each McpServer (pendingSamplingRequests, pendingElicitationRequests, notifications). See Sampling and Elicitation.

Reference

React client API reference — provider props, hook return values, and storage types.