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.
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().
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
TheMCPClient configuration uses
oauth.staticClientInfo.client_id:
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: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 aBrowserOAuthClientProvider 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
Authorization header also disables automatic OAuth: