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)
| Parameter | Type | Required | Description |
|---|---|---|---|
client_id | string | No* | OAuth client ID (required if not using DCR) |
client_secret | string | No | OAuth client secret (required if not using DCR) |
scope | string | No | OAuth scopes to request |
callback_port | integer | No | Port for OAuth callback (default: 8080) |
oauth_provider | object | No | OAuth provider metadata |
Port Configuration
- Default Port: 8080
- Custom Ports: Any available port (e.g., 8081, 8082, 3000)
- Port Conflicts: mcp-use will check if the port is available before starting OAuth flow
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