n8n does MCP OAuth in its credential layer, and CIMD is off until an environment variable turns it on
Kind: nuance · Status: current · Last verified: 2026-11-27 · Clients: n8n · Revisions: 2025-11-25
The MCP nodes construct StreamableHTTPClientTransport and SSEClientTransport with a custom fetch and no authProvider. The SDK's OAuth code never runs. Authentication is whatever n8n credential the node uses: Bearer, Header, Multiple Headers, a generic OAuth2 credential, or the MCP OAuth2 credential.
The MCP OAuth2 credential extends n8n's generic OAuth2 credential. When the user clicks connect in the editor, oauth.service.ts in the cli package does the work:
- Reads protected resource metadata from the credential's server URL, path-inserted first, then the root. It does not read a
WWW-Authenticatechallenge from the MCP server. - Reads authorization server metadata from RFC 8414 and OIDC well-known URLs in order, and rejects a document whose
issuerdoes not match. - Prefers the protected resource's scopes, adding
offline_accesswhen the server supports it. - Uses CIMD when
N8N_OAUTH_CIMD_ENABLEDis true, the server advertisesclient_id_metadata_document_supported, S256 PKCE and public clients, and the metadata URL is HTTPS with a path. The default is false, so a default install registers by DCR withclient_name: n8n. - Sends
resourceon the authorization and token requests and checksisson the callback.
At run time the node reads the stored token. A 401 on any MCP request calls n8n's token refresh and retries once. A failed refresh surfaces as an auth error on the node. Nothing starts a new authorization from inside a workflow run.
The pnpm workspace patches pkce-challenge 5.0.0, a dependency of the SDK, to drop ~ from the verifier alphabet. n8n's own OAuth service imports that package. The MCP nodes do not reach the SDK's auth module, so the patch does not change SDK behaviour on the MCP path, and metadata.sdk.patched is false.
Sources
- McpOAuth2Api credential, useDynamicClientRegistration default true, commit
fb1aec9c,packages/@n8n/nodes-langchain/credentials/McpOAuth2Api.credentials.ts:McpOAuth2Api, 2026-11-27 - oauth.service.ts, protected resource discovery and resource resolution, commit
fb1aec9c,packages/cli/src/oauth/oauth.service.ts:OauthService.discoverAndResolveResource, 2026-11-27 - oauth.service.ts, registerClient (AS metadata, CIMD, DCR), commit
fb1aec9c,packages/cli/src/oauth/oauth.service.ts:OauthService, 2026-11-27 - auth.config.ts, N8N_OAUTH_CIMD_ENABLED, commit
fb1aec9c,packages/@n8n/config/src/configs/auth.config.ts:AuthConfig, 2026-11-27 - shared/utils.ts, auth headers and the 401 refresh, commit
fb1aec9c,packages/@n8n/nodes-langchain/nodes/mcp/shared/utils.ts, 2026-11-27 - pkce-challenge patch, commit
fb1aec9c,patches/pkce-challenge@5.0.0.patch, 2026-11-27