OAuth (automatic)
For HTTP servers without a bearer token, the client provisions an OAuth provider automatically. A server that protects the whole MCP endpoint starts OAuth during connection:oauth: false. Override options with an oauth object on the server config. Pass a custom authProvider to skip auto-provisioning.
Mixed auth
A mixed-auth server allows anonymous MCP connection and public operations, but requires OAuth for some tools, resources, or prompts. When the server publishes RFC 9728 protected-resource metadata, the client detects this after the anonymous connection succeeds:connection.authorization and connection.info.authorization
expose the same state, including the canonical
resource and advertised scopes when the metadata provides them. Detection is
best-effort and defaults to enabled for HTTP servers with an OAuth provider.
Call discoverAuthorization() when using MCPClient directly; React performs
the same discovery after publishing the ready connection. Set detectMixedAuth: false on the server configuration to skip it.
If you stay anonymous, a later wire-level OAuth challenge from a protected
operation starts the official SDK flow. Automatic flows retry the operation once
after authorization. Explicit browser flows surface the auth action so the host
can authenticate and retry. A tool result with isError: true or auth-like text
is not treated as an OAuth challenge.
React
onMcpAuthorization from @mcp-use/client/react on your callback route. See React integration.
Flow modes
Manual browser authorization
SetpreventAutoAuth: true on a BrowserOAuthClientProvider to prepare an
authorization URL without opening it automatically. Read that URL with
getLastAttemptedAuthUrl() and present it to the user in the same page
lifetime. The fallback URL is intentionally kept in memory only and is not
available after the provider or page is recreated; start a new authorization
attempt after a reload.
Pre-registered client
OAuth proxy (browser)
When upstream OAuth endpoints lack CORS:Bearer token
Server config fields
Node OAuth helpers
localStorage automatically.