GuideClaude connectors
How to build a custom Claude connector with OAuth
A custom connector is a remote MCP server that people add to Claude by its URL. If your tools act on a user’s account, Claude signs the user in with OAuth. This guide walks through what your MCP server and your authorization server must do, step by step, citing the MCP specification and Anthropic’s documentation at each step.
Sources checked on 26 November 2026. Claude’s docs say its client follows the 2025-03-26, 2025-06-18 and 2025-11-25 MCP authorization specifications (Claude docs), so this guide cites the 2025-11-25 version, and notes where the latest one (2026-07-28) differs. Examples use placeholder domains (example.com).
The flow in one paragraph
Claude calls your MCP server, gets a 401, reads your Protected Resource Metadata to find your authorization server, reads that server’s metadata, gets a client ID, sends the user to sign in with PKCE and a resource parameter, exchanges the code for tokens, then calls your MCP server with Authorization: Bearer on every request (MCP spec, authorization flow).
Step 1. Return a 401 that points to your metadata
When Claude calls your MCP server without a token, answer
401 Unauthorizedwith aWWW-Authenticateheader whoseresource_metadataparameter points to your Protected Resource Metadata. The MCP spec lets you add ascopeparameter to say which scopes the request needs (MCP spec, discovery).HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource", scope="files:read"Claude needs the 401 status: it ignores a
WWW-Authenticateheader on a 200 response. Without aresource_metadatapointer, Claude falls back to probing/.well-known/oauth-protected-resource/<your-mcp-path>, then/.well-known/oauth-protected-resourceon your server’s origin (Claude docs, discovery).Step 2. Serve Protected Resource Metadata (RFC 9728)
MCP servers must implement OAuth 2.0 Protected Resource Metadata, and the document must list at least one authorization server in
authorization_servers(MCP spec, authorization server location). An illustrative document:{ "resource": "https://mcp.example.com/mcp", "authorization_servers": ["https://auth.example.com"], "scopes_supported": ["files:read"] }Claude’s client adds two rules:
resourcemust equal your MCP server URL exactly as the user enters it, path included; and Claude uses only the first entry ofauthorization_servers, with no fallback to later ones (Claude docs).Step 3. Publish authorization server metadata with PKCE
Your authorization server must expose RFC 8414 metadata or OpenID Connect Discovery 1.0 at its
/.well-known/paths (MCP spec, overview). The spec tells clients to refuse to proceed ifcode_challenge_methods_supportedis missing, so advertise it (MCP spec, authorization code protection):"code_challenge_methods_supported": ["S256"]Claude sends a PKCE
code_challengewithS256on every authorization request. The authorization server host must also be reachable from Anthropic’s published IP range: a firewall in front of your identity provider can break sign-in even when the MCP server itself is reachable (Claude docs, PKCE; network reference).Step 4. Let Claude get a client ID
Claude can identify itself in three ways (Claude docs, custom connectors):
- Client ID Metadata Document (CIMD). Claude normally uses it only when your authorization server metadata advertises both
"client_id_metadata_document_supported": trueand"none"intoken_endpoint_auth_methods_supported; otherwise it falls back to DCR. - Dynamic Client Registration (DCR, RFC 7591). Needs a
registration_endpoint. Claude registers a new client on every fresh connection, so busy servers can end up with many clients. Note that the latest MCP spec (2026-07-28) marks DCR as deprecated in favor of CIMD (MCP spec 2026-07-28, client registration). - Your own OAuth client. The person adding the connector enters a client ID (and a secret only if your server requires a confidential client).
- Client ID Metadata Document (CIMD). Claude normally uses it only when your authorization server metadata advertises both
Step 5. Allow Claude’s redirect URIs
For claude.ai, the desktop and mobile apps, register exactly this redirect URI (Claude docs, callback URLs):
https://claude.ai/api/mcp/auth_callbackClaude Code uses a loopback redirect on a port that changes per session, such as
http://localhost:3118/callback. Matchhttp://localhost/callbackandhttp://127.0.0.1/callbackwith the port ignored. On your consent screen, show the redirect URI’s hostname clearly, as the MCP spec requires (MCP spec, localhost redirect risks).Step 6. Bind tokens to your server
MCP clients must send the
resourceparameter (RFC 8707) with the canonical URI of your MCP server, in both the authorization and token requests (MCP spec, resource parameter). On your side:- Read the token from
Authorization: Bearer <token>on every request; never accept tokens in the query string (MCP spec, token requirements). - Accept only tokens issued for your server as the audience, and answer invalid or expired tokens with a 401 (MCP spec, token handling).
- Never pass the token you received through to an upstream API: if you call one, use a separate token issued for it (MCP spec, token privilege restriction).
- For a token with too few scopes, answer
403witherror="insufficient_scope"and the scopes the operation needs (MCP spec, insufficient scope).
- Read the token from
Step 7. Make the token endpoint Claude-proof
From Anthropic’s requirements (Claude docs, token endpoint):
- Accept
application/x-www-form-urlencodedon/tokenfor the code exchange and refreshes (DCR at/registeruses JSON). - Claude refreshes tokens on a 401 and up to five minutes before expiry. When a refresh token is no longer valid, return
invalid_grant. - Rotate refresh tokens for public clients (DCR and, normally, CIMD register Claude as one), and return the new refresh token in the same response.
- Answer discovery, registration and token requests within 10 seconds, and refresh requests within 30 seconds.
- Claude adds
offline_accesswhen your authorization server lists it inscopes_supported; the MCP spec says the MCP server itself should not ask for it (MCP spec 2026-07-28, refresh tokens).
- Accept
Step 8. Test it as a custom connector
Your server must be reachable over the public internet on port 443: Claude connects from Anthropic’s cloud, even from the desktop app (Claude Help Center). On an individual plan, open Customize > Connectors, choose Add, then Add custom connector, enter a name and your MCP server URL, keep the detected authentication settings, add it, then Connect and sign in. On Team and Enterprise plans, an Owner adds it in Organization settings > Connectors first (Claude docs, add a connector by URL). Menu names can change; the linked page is the reference.
A typical discovery failure: your MCP server receives the first request but your authorization server sees no traffic, and Claude shows “Couldn’t reach the MCP server”. It means there was no
resource_metadatapointer on the 401 and the well-known paths returned 404 (Claude docs).
Checklist
- 401 with
WWW-Authenticate: Bearer resource_metadata="…"on unauthenticated requests - Protected Resource Metadata:
resourceequals the MCP URL, your issuer first inauthorization_servers - Authorization server metadata with
code_challenge_methods_supported: ["S256"] - CIMD (with
"none"auth method) or a DCRregistration_endpoint - Redirect URIs:
https://claude.ai/api/mcp/auth_callbackand port-agnostic loopback - Audience check, no token passthrough, no tokens in URLs
- Form-encoded
/token,invalid_grant, refresh token rotation, fast responses - Tested end to end as a custom connector in Claude
Sources
- MCP specification 2025-11-25, Authorization
- MCP specification 2026-07-28 (latest), Authorization
- MCP specification source (GitHub)
- Claude docs: Authentication for connectors
- Claude docs: Build an MCP server for Claude
- Claude docs: Add a connector that isn’t in the directory
- Claude Help Center: Get started with custom connectors using remote MCP
The specifications and Claude’s client change often. If something here no longer matches the sources, the sources win: tell us at hello@tethlo.com and we will update the guide.