The mcp-use client supports multiple authentication methods for secure connections to MCP servers, including OAuth 2.1 with automatic token management, bearer token authentication, and custom authentication providers.Documentation Index
Fetch the complete documentation index at: https://docs.mcp-use.com/llms.txt
Use this file to discover all available pages before exploring further.
Supported Authentication Methods
- OAuth 2.1: Complete OAuth flow with automatic Dynamic Client Registration (DCR)
- Bearer Tokens: API key and token-based authentication
- Custom Headers: Flexible authentication header support
OAuth Authentication
OAuth provides secure, token-based authentication with automatic token refresh and user consent flows.Custom OAuth Provider (Headless/Testing)
If you run in non-browser environments (tests, headless runners, custom redirects), you can inject your own OAuth provider.When
authProvider is provided, useMcp uses that provider directly instead of creating the default browser OAuth provider internally.Bearer Token Authentication
For servers requiring API keys or bearer tokens:Node.js Client Authentication
For server-side Node.js applications, useMCPClient with bearer tokens or custom headers. OAuth flows are browser-only and not available in Node.js environments.
Bearer Token Authentication
The simplest way to authenticate with API-based MCP servers:Custom Headers
For servers requiring custom authentication headers or additional metadata:Configuration File
Load authentication settings from a JSON configuration file:CLI Authentication
The mcp-use CLI client supports bearer token authentication for connecting to secured MCP servers:~/.mcp-use/cli-sessions.json for future sessions.
For complete CLI documentation including stdio connections, session
management, and interactive mode, see the CLI Client
Guide.
OAuth Flow Modes
mcp-use supports two OAuth flow modes for client applications:Popup Flow (Default)
Opens OAuth authorization in a popup window. Best for desktop and web applications. Advantages:- User stays on the same page
- Better UX for web applications
- No navigation interruption
Redirect Flow
Redirects the current window to the OAuth provider, then back to your app. Advantages:- Works in all browsers (popup blockers won’t interfere)
- Better for mobile browsers
- More reliable across different environments
- Create a callback page in your app:
- Configure your callback URL to match this route:
Manual Authentication Control
By default, mcp-use requires explicit user action to trigger OAuth authentication. When a server requires authentication, the connection enterspending_auth state and you must call the authenticate() method:
preventAutoAuth: false:
OAuth Flow Process
When OAuth authentication is required:Configuration Options
Node.js Client Configuration Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | Yes | MCP server endpoint URL |
authToken | string | No | Bearer token for authentication (added to Authorization header) |
auth_token | string | No | Alternative snake_case form of authToken (for Python config compatibility) |
headers | object | No | Custom HTTP headers including authentication headers |
Configuration Compatibility: Both
authToken (camelCase) and auth_token
(snake_case) are accepted for token-based authentication. Use authToken for
TypeScript conventions; auth_token is supported for compatibility with
Python-style configurations.OAuth Configuration Parameters (Browser Only)
OAuth options are passed touseMcp (and to addServer on McpClientProvider) at the top level for transport/callback settings, plus a nested oauth object for pre-registered client credentials.
| Parameter | Type | Required | Description |
|---|---|---|---|
callbackUrl | string | No | OAuth redirect URL (defaults to /oauth/callback on the current origin) |
useRedirectFlow | boolean | No | Use full-page redirect instead of popup (default: false) |
preventAutoAuth | boolean | No | Wait for authenticate() instead of auto-triggering OAuth (default: true) |
oauth.clientId | string | No* | Pre-registered OAuth client ID. When set, the SDK skips Dynamic Client Registration. |
oauth.clientSecret | string | No | Pre-registered OAuth client secret for confidential clients without PKCE. Requires clientId. |
oauth.scope | string | No | OAuth scopes string included in the authorize request |
Pre-registered Client Credentials
Some MCP servers strip theregistration_endpoint from their auth-server metadata, which means Dynamic Client Registration is unavailable. For these servers, register a client with the provider yourself and pass the credentials through oauth:
clientSecret is also set, the SDK auto-switches token-endpoint authentication from none to client_secret_basic or client_secret_post (whichever the auth server advertises in token_endpoint_auth_methods_supported). Drop clientSecret for public clients using PKCE.
Example Servers that support OAuth
OAuth with DCR Support
- Linear:
https://mcp.linear.app/mcp
OAuth with Manual Registration
- GitHub:
https://api.githubcopilot.com/mcp/
Bearer Token
- Most API-based MCP servers