Skip to main content
HTTP connections support automatic OAuth, pre-registered public clients, bearer tokens, custom headers, and custom authentication providers.

Automatic OAuth with MCPClient

MCPClient creates an OAuth provider for an HTTP server unless the server configuration already supplies an authProvider, authToken, oauth: false, or an Authorization header.
In Node.js, the default provider opens a browser and waits for its loopback callback. In the browser build, the default provider opens a popup; set useRedirectFlow: true inside the server’s oauth options to use a full-page redirect. Pass a custom authProvider when your application owns the authorization flow.

React: explicit authentication

React connection APIs use an explicit authorization step by default. preventAutoAuth defaults to true, so an unauthorized connection enters pending_auth until the user calls authenticate().
Set preventAutoAuth: false on useMcp or a McpClientProvider server configuration to start authorization automatically. Popup mode is the default; set the top-level React option useRedirectFlow: true for a full-page redirect. On your callback route, import onMcpAuthorization from @mcp-use/client/react. See React integration.

Pre-registered clients

The MCPClient configuration uses oauth.staticClientInfo.client_id:
React uses a different, UI-oriented shape:
Browser OAuth clients are public PKCE clients. Do not put a client_secret in browser configuration; BrowserOAuthClientProvider rejects one in staticClientInfo.

OAuth proxy in the browser

Use an OAuth proxy when the authorization server’s metadata, token, or registration endpoints do not support browser CORS:
For the browser MCPClient, oauth.oauthProxyUrl configures the proxy and oauth.proxyOAuthRequests controls whether OAuth HTTP requests use it. The latter defaults to true when the browser provider is created. React routes its OAuth requests through the configured oauthProxyUrl; it does not expose proxyOAuthRequests as a useMcp option.

Manual browser authorization

Construct a BrowserOAuthClientProvider with preventAutoAuth: true and pass it to the browser client when you need to present the authorization URL yourself:
getLastAttemptedAuthUrl() returns the URL for the current provider instance. It is kept in memory only, so start a new authorization attempt after a page reload. The auto-provisioned browser provider also accepts oauth.preventAutoAuth, but an explicit provider gives your application access to the prepared URL.

Bearer tokens

An explicit Authorization header also disables automatic OAuth:

MCPClient server fields

Node OAuth helpers

Use these exports for headless scripts, custom storage, or an authorization flow you manage directly.