> ## Documentation Index
> Fetch the complete documentation index at: https://modelcontextprotocol.io/llms.txt
> Use this file to discover all available pages before exploring further.

# OAuth Client Credentials

> Machine-to-machine authentication for MCP using the OAuth 2.0 client credentials flow

The OAuth Client Credentials extension (`io.modelcontextprotocol/oauth-client-credentials`) adds support for the [OAuth 2.0 client credentials flow](https://datatracker.ietf.org/doc/html/rfc6749#section-4.4) to MCP. This enables automated systems to connect to MCP servers without interactive user authorization.

> [card] [Specification](https://github.com/modelcontextprotocol/ext-auth/blob/main/specification/stable/oauth-client-credentials/2026-07-28/oauth-client-credentials.mdx)
>
> Full technical specification for the OAuth Client Credentials extension.

## What it is

The standard MCP authorization flow requires a user to interactively approve access — a browser opens, the user logs in, and grants permission. That works well for humans, but breaks down when there's no user present.

The OAuth Client Credentials extension solves this by letting a client authenticate using application-level credentials (a client ID and secret, or a signed JWT assertion) rather than delegated user credentials. The client proves its identity directly to the authorization server, which issues an access token without requiring a browser redirect or user interaction.

## When to use it

Use OAuth Client Credentials when:

* **Background services** need to call MCP tools on a schedule or in response to events, without a user present
* **CI/CD pipelines** invoke MCP servers as part of automated build, test, or deployment workflows
* **Server-to-server integrations** connect two backend systems where there's no end user involved
* **Daemon processes** or long-running workers need persistent access to MCP resources

If your integration has a human user who should explicitly authorize access, use the standard MCP authorization flow instead.

## How it works

The extension supports two credential formats:

### JWT Bearer Assertions (recommended)

Defined in [RFC 7523](https://datatracker.ietf.org/doc/html/rfc7523), JWT Bearer Assertions let the client sign a token with its private key and present it as proof of identity. The authorization server validates the signature using the client's registered public key.

```mermaid theme={null}
sequenceDiagram
    participant Client
    participant AS as Authorization Server
    participant MCP as MCP Server

    Client->>AS: POST /token<br/>grant_type=client_credentials<br/>client_assertion_type=urn:ietf:params:<br/>oauth:client-assertion-type:jwt-bearer<br/>client_assertion=<signed JWT><br/>resource=<MCP server URI>
    AS-->>Client: access_token
    Client->>MCP: MCP request (Bearer token)
```

The JWT assertion typically includes:

* `iss`: Client ID (the issuer)
* `sub`: Client ID (subject being authenticated)
* `aud`: Authorization server issuer identifier (the `issuer` value from its metadata), as the only value. [RFC 10070](https://www.rfc-editor.org/rfc/rfc10070.html) disallows the token endpoint URL, which RFC 7523 permitted
* `exp`: Expiration time
* `iat`: Issued-at time

### Client Secrets

For simpler deployments, the extension also supports the standard client credentials flow using a `client_id` and `client_secret`. The client sends its credentials directly to the authorization server's token endpoint and receives an access token in return.

```mermaid theme={null}
sequenceDiagram
    participant Client
    participant AS as Authorization Server
    participant MCP as MCP Server

    Client->>AS: POST /token<br/>grant_type=client_credentials<br/>client_id + client_secret<br/>resource=<MCP server URI>
    AS-->>Client: access_token
    Client->>MCP: MCP request (Bearer token)
```

> [!WARNING]
>
> Client secrets are **long-lived credentials** that grant access without user interaction. If a secret is leaked, an attacker can silently authenticate as your application until the secret is rotated. To reduce risk:
>
> * Store secrets in a secrets manager, never in source code or environment files checked into version control.
> * Rotate secrets on a regular schedule and immediately after any suspected compromise.
> * Scope credentials to the minimum permissions required.
> * Prefer JWT assertions when possible — they are short-lived and do not require transmitting the signing key.

## Implementation guide

### For MCP clients

To use the OAuth Client Credentials extension, your client must:

**1. Declare support**

Include the extension in its per-request capabilities:

```jsonc theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "...",
  "params": {
    // Other fields...
    "_meta": {
      // Other fields...
      "io.modelcontextprotocol/clientCapabilities": {
        "extensions": {
          "io.modelcontextprotocol/oauth-client-credentials": {},
        },
      },
    },
  },
}
```

**2. Obtain an access token**

Request a token from the authorization server using the client credentials grant before connecting to the MCP server.

**3. Include the token**

Pass the token in the `Authorization` header of HTTP requests to the MCP server:

```
Authorization: Bearer <access_token>
```

**4. Handle token refresh**

Client credentials tokens typically have shorter lifetimes than user-delegated tokens. Implement token refresh logic to obtain a new token before expiry.

### For MCP servers

To accept client credentials tokens, your server must:

**1. Validate the token**

On each request, verify the JWT signature and claims against your authorization server's public keys (usually via a JWKS endpoint).

**2. Check scopes**

Ensure the token includes the required scopes for the requested operation.

**3. Advertise support**

Optionally (but recommended for discoverability), include the extension in the `server/discover` response:

```jsonc theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    // Other fields...
    "capabilities": {
      "extensions": {
        "io.modelcontextprotocol/oauth-client-credentials": {},
      },
    },
  },
}
```

## SDK examples

The official MCP SDKs provide built-in support for client credentials authentication. Both handle token acquisition and refresh automatically.

**1. Install the SDK**

> [tab] TypeScript
>
> ```bash theme={null}
> npm install @modelcontextprotocol/client
> ```

> [tab] Python
>
> ```bash theme={null}
> pip install mcp
> ```

**2. Create a provider and connect**

Each sample pins the issuer of the authorization server that provisioned the credentials, so the client refuses to send them to any other authorization server the MCP server might advertise.

Choose the credential format that matches your setup:

#### Using a client secret

> [tab] TypeScript
>
> ```typescript theme={null}
> import {
>   Client,
>   ClientCredentialsProvider,
>   StreamableHTTPClientTransport,
> } from "@modelcontextprotocol/client";
>
> const provider = new ClientCredentialsProvider({
>   clientId: "my-service",
>   clientSecret: "s3cr3t",
>   expectedIssuer: "https://auth.example.com",
> });
>
> const client = new Client(
>   { name: "my-service", version: "1.0.0" },
>   { capabilities: {} },
> );
>
> const transport = new StreamableHTTPClientTransport(
>   new URL("https://mcp.example.com/mcp"),
>   { authProvider: provider },
> );
>
> await client.connect(transport);
>
> // Use the client
> const tools = await client.listTools();
> console.log(
>   "Available tools:",
>   tools.tools.map((t) => t.name),
> );
>
> await transport.close();
> ```

> [tab] Python
>
> ```python theme={null}
> import asyncio
>
> import httpx2
>
> from mcp import Client
> from mcp.client.auth.extensions.client_credentials import (
>     ClientCredentialsOAuthProvider,
> )
> from mcp.client.streamable_http import streamable_http_client
> from mcp.shared.auth import OAuthClientInformationFull, OAuthToken
>
>
> class InMemoryTokenStorage:
>     def __init__(self) -> None:
>         self.tokens: OAuthToken | None = None
>         self.client_info: OAuthClientInformationFull | None = None
>
>     async def get_tokens(self) -> OAuthToken | None:
>         return self.tokens
>
>     async def set_tokens(self, tokens: OAuthToken) -> None:
>         self.tokens = tokens
>
>     async def get_client_info(self) -> OAuthClientInformationFull | None:
>         return self.client_info
>
>     async def set_client_info(self, client_info: OAuthClientInformationFull) -> None:
>         self.client_info = client_info
>
>
> provider = ClientCredentialsOAuthProvider(
>     server_url="https://mcp.example.com/mcp",
>     storage=InMemoryTokenStorage(),
>     client_id="my-service",
>     client_secret="s3cr3t",
>     scope="read write",
>     issuer="https://auth.example.com",
> )
>
>
> async def main() -> None:
>     async with httpx2.AsyncClient(auth=provider) as http_client:
>         transport = streamable_http_client(
>             "https://mcp.example.com/mcp",
>             http_client=http_client,
>         )
>         async with Client(transport) as client:
>             # Use the client
>             tools = await client.list_tools()
>             print("Available tools:", [t.name for t in tools.tools])
>
>
> if __name__ == "__main__":
>     asyncio.run(main())
> ```

#### Using a JWT private key

> [tab] TypeScript
>
> ```typescript theme={null}
> import {
>   Client,
>   PrivateKeyJwtProvider,
>   StreamableHTTPClientTransport,
> } from "@modelcontextprotocol/client";
>
> const provider = new PrivateKeyJwtProvider({
>   clientId: "my-service",
>   privateKey: process.env.CLIENT_PRIVATE_KEY_PEM,
>   algorithm: "RS256",
>   expectedIssuer: "https://auth.example.com",
> });
>
> const client = new Client(
>   { name: "my-service", version: "1.0.0" },
>   { capabilities: {} },
> );
>
> const transport = new StreamableHTTPClientTransport(
>   new URL("https://mcp.example.com/mcp"),
>   { authProvider: provider },
> );
>
> await client.connect(transport);
>
> // Use the client
> const tools = await client.listTools();
> console.log(
>   "Available tools:",
>   tools.tools.map((t) => t.name),
> );
>
> await transport.close();
> ```

> [tab] Python
>
> ```python theme={null}
> import asyncio
> from pathlib import Path
>
> import httpx2
>
> from mcp import Client
> from mcp.client.auth.extensions.client_credentials import (
>     PrivateKeyJWTOAuthProvider,
>     SignedJWTParameters,
> )
> from mcp.client.streamable_http import streamable_http_client
> from mcp.shared.auth import OAuthClientInformationFull, OAuthToken
>
>
> class InMemoryTokenStorage:
>     def __init__(self) -> None:
>         self.tokens: OAuthToken | None = None
>         self.client_info: OAuthClientInformationFull | None = None
>
>     async def get_tokens(self) -> OAuthToken | None:
>         return self.tokens
>
>     async def set_tokens(self, tokens: OAuthToken) -> None:
>         self.tokens = tokens
>
>     async def get_client_info(self) -> OAuthClientInformationFull | None:
>         return self.client_info
>
>     async def set_client_info(self, client_info: OAuthClientInformationFull) -> None:
>         self.client_info = client_info
>
>
> # Create a signed JWT assertion provider from key parameters
> jwt_params = SignedJWTParameters(
>     issuer="my-service",
>     subject="my-service",
>     signing_key=Path("private_key.pem").read_text(),
>     signing_algorithm="RS256",
>     lifetime_seconds=300,
> )
>
> provider = PrivateKeyJWTOAuthProvider(
>     server_url="https://mcp.example.com/mcp",
>     storage=InMemoryTokenStorage(),
>     client_id="my-service",
>     assertion_provider=jwt_params.create_assertion_provider(),
>     scope="read write",
>     issuer="https://auth.example.com",
> )
>
>
> async def main() -> None:
>     async with httpx2.AsyncClient(auth=provider) as http_client:
>         transport = streamable_http_client(
>             "https://mcp.example.com/mcp",
>             http_client=http_client,
>         )
>         async with Client(transport) as client:
>             # Use the client
>             tools = await client.list_tools()
>             print("Available tools:", [t.name for t in tools.tools])
>
>
> if __name__ == "__main__":
>     asyncio.run(main())
> ```

## Client support

> [!NOTE]
>
> Support for this extension varies by client. Extensions are opt-in and never active by default.

Check the [client matrix](https://modelcontextprotocol.io/extensions/client-matrix.md) for current implementation status across MCP clients.

## Related resources

> [card] [ext-auth repository](https://github.com/modelcontextprotocol/ext-auth)
>
> Source code and reference implementations

> [card] [Full specification](https://github.com/modelcontextprotocol/ext-auth/blob/main/specification/stable/oauth-client-credentials/2026-07-28/oauth-client-credentials.mdx)
>
> Technical specification with normative requirements

> [card] [RFC 6749 — Client Credentials Grant](https://datatracker.ietf.org/doc/html/rfc6749#section-4.4)
>
> The underlying OAuth 2.0 specification

> [card] [RFC 7523 — JWT Bearer Assertions](https://datatracker.ietf.org/doc/html/rfc7523)
>
> JWT assertion format specification


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.