# Connect MCP Clients Without A User With The Client Credentials Grant

Learn how to let background services call an MCP server with the MCP client credentials extension and FusionAuth Entities.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

> **PLAN:** This feature requires [at least a Starter plan](https://fusionauth.io/docs/concepts/plans-and-limits/plans-features.md#starter-features).

The MCP [OAuth Client Credentials extension](https://modelcontextprotocol.io/extensions/auth/oauth-client-credentials) (`io.modelcontextprotocol/oauth-client-credentials`) lets a service call an [MCP](https://fusionauth.io/docs/authorization/mcp-server-access.md) server with no user present, such as a scheduled job or a CI pipeline. FusionAuth supports the extension through the [Client Credentials grant](https://fusionauth.io/docs/authentication/oauth/client-credentials.md) between two [Entities](https://fusionauth.io/docs/concepts/types/entity-management.md). The MCP server is the target Entity, and each MCP client is a recipient Entity with a Grant to the MCP server.

FusionAuth supports client secrets only

The extension allows two ways to authenticate: a client secret, or a JWT signed with the client's private key (`private_key_jwt`). FusionAuth supports only the client secret. In the MCP TypeScript SDK, use `ClientCredentialsProvider`, not `PrivateKeyJwtProvider`.

## Prerequisites

*   FusionAuth with a Starter, Essentials, or Enterprise license. Entities require a paid plan.
*   A FusionAuth instance that MCP clients can reach over HTTPS, such as `https://auth.example.com`. The MCP TypeScript SDK refuses to send credentials to a token endpoint that doesn't use HTTPS.
*   An MCP server that validates FusionAuth access tokens, such as `https://mcp.example.com/mcp`. To build one, see [Control MCP Server Access](https://fusionauth.io/docs/authorization/mcp-server-access.md).

## How The Connection Works

When an MCP client connects to the MCP server, the client:

1.  Calls the MCP server, gets a `401`, and reads the server's protected resource metadata to find FusionAuth.
2.  Reads the FusionAuth discovery document to find the token endpoint.
3.  Sends the client Id and client secret of the recipient Entity to the token endpoint, with the `target-entity` scope from the server's metadata.
4.  Receives an access token whose **`aud`** claim contains the Id of the MCP server Entity, and sends the token on every MCP request.

```mermaid
sequenceDiagram
    participant Client as MCP Client
    participant FusionAuth
    participant Server as MCP Server
    Client ->> Server : MCP request without a token
    Server -->> Client : 401 with the protected resource metadata URL
    Client ->> FusionAuth : Read the discovery document
    Client ->> FusionAuth : POST /oauth2/token with grant_type=client_credentials
    FusionAuth -->> Client : Access token for the MCP server Entity
    Client ->> Server : MCP request with the access token
```

An MCP client gets an access token from FusionAuth with the Client Credentials grant, then calls the MCP server.

FusionAuth sets **`aud`** from the `target-entity` scope. FusionAuth ignores the `resource` parameter that MCP clients send with this grant, so the token doesn't contain the MCP server URL. FusionAuth also drops any requested scope that doesn't start with `target-entity:`. A token requested with only other scopes has no **`aud`** or **`permissions`** claim, and the MCP server must reject the token.

## Configure FusionAuth

1.  Find the Id of the Tenant for your Entities. Navigate to Tenants and copy the **Id** of the Tenant. This guide uses `<tenantId>` for that value.
    
2.  Set the Tenant's **Issuer** to the URL MCP clients use to find FusionAuth. Edit the Tenant, and on the General tab, set **Issuer** to `https://auth.example.com/<tenantId>`. FusionAuth serves the Tenant's discovery document at `/.well-known/openid-configuration/<tenantId>`, and MCP clients look there for an [authorization server](https://fusionauth.io/docs/authentication/oauth.md) URL with a path.
    
    Caution
    
    Changing the Issuer changes the **`iss`** claim of every token the Tenant issues. Applications that validate **`iss`** against the old value reject new tokens until you update the applications.
    
3.  Create an Entity Type for MCP servers. Navigate to Entity Management -> Entity Types and click Add . Add a permission for each kind of access your MCP server checks, such as `read` and `write`.
    
4.  Create an Entity for the MCP server with the new Entity Type. Navigate to Entity Management -> Entities and click add. Copy the **Id** of the Entity. This guide uses `<mcpServerEntityId>` for that value.
    
5.  Create an Entity for each MCP client. Copy the **Client Id** and **Client secret** of each client Entity, and store the secret in a secrets manager.
    
6.  Grant each client Entity the permissions the client needs on the MCP server Entity. Manage the MCP server Entity, and add a Grant for the client Entity. To add Grants with the API instead, see [Configure Entities](https://fusionauth.io/docs/authentication/oauth/client-credentials.md#configure-entities).
    
7.  Check that the client Entity can get a token:
    
    ```shell-session
    $ curl -u '<clientId>:<clientSecret>' \
      -d 'grant_type=client_credentials' \
      -d 'scope=target-entity:<mcpServerEntityId>' \
      https://auth.example.com/oauth2/token/<tenantId>
    ```
    
    FusionAuth returns an access token whose **`aud`** claim contains `<mcpServerEntityId>`. The **`permissions`** claim lists the permissions from the Grant.
    

## Configure The MCP Server

1.  Set `authorization_servers` in the MCP server's protected resource metadata to `https://auth.example.com/<tenantId>`.
    
2.  Set `scopes_supported` in the protected resource metadata to `["target-entity:<mcpServerEntityId>"]`. The MCP TypeScript SDK requests the scopes in `scopes_supported` before the scope set on the client. A scope with no permissions after the Entity Id requests every permission from the Grant. A scope that names several permissions fails when the client Entity lacks any one of them.
    
3.  Validate each access token. Check the signature and the expiration, as [Control MCP Server Access](https://fusionauth.io/docs/authorization/mcp-server-access.md#step-2-implement-token-validation) does with the [JWT Validate API](https://fusionauth.io/docs/apis/jwt/validate-a-jwt.md). Then check the following claims:
    
    *   **`iss`** is `https://auth.example.com/<tenantId>`.
    *   **`aud`** contains `<mcpServerEntityId>`.
    *   **`permissions`** contains the permission each tool requires, under the `<mcpServerEntityId>` key, such as `{"<mcpServerEntityId>": ["read"]}`.
    
    To check the signature locally with the keys at `/.well-known/jwks.json`, sign the tokens with an RSA or EC key. FusionAuth doesn't publish HMAC keys in the JWKS. Set the key in the **Access token signing key** of the Entity Type, or of the Tenant.
    
4.  Advertise the extension in the server's `server/discover` response. The extension recommends this step, but clients connect without the step:
    
    ```json
    {
      "capabilities": {
        "extensions": {
          "io.modelcontextprotocol/oauth-client-credentials": {}
        }
      }
    }
    ```
    

## Connect An MCP Client

The MCP TypeScript SDK handles discovery, the token request, and token renewal. Pass the client Id and client secret of the client Entity to `ClientCredentialsProvider`, and set `expectedIssuer` to the Tenant's Issuer:

```typescript
import {
  Client,
  ClientCredentialsProvider,
  StreamableHTTPClientTransport,
} from '@modelcontextprotocol/client';

const provider = new ClientCredentialsProvider({
  clientId: process.env.FUSIONAUTH_CLIENT_ID,
  clientSecret: process.env.FUSIONAUTH_CLIENT_SECRET,
  expectedIssuer: 'https://auth.example.com/<tenantId>',
});

const client = new Client({ name: 'nightly-report', version: '1.0.0' }, { capabilities: {} });
const transport = new StreamableHTTPClientTransport(new URL('https://mcp.example.com/mcp'), {
  authProvider: provider,
});

await client.connect(transport);
const tools = await client.listTools();
console.log(tools.tools.map((tool) => tool.name));
```

`expectedIssuer` stops the client from sending the secret to any other authorization server that the MCP server's metadata names. Run the client. When the connection works, the client prints the names of the MCP server's tools.

A client secret works until you change the secret. To change a secret, see [Client Secret Rotation](https://fusionauth.io/docs/security/tokens-and-keys/client-secret-rotation.md).

## Troubleshooting

| Problem | Cause and fix |
| --- | --- |
| The token has no **`aud`** or **`permissions`** claim. | The client requested no `target-entity` scope. Set `scopes_supported` on the MCP server to `["target-entity:<mcpServerEntityId>"]`. |
| FusionAuth returns `invalid_scope` with `does not have a grant to the target entity`. | The client Entity has no Grant on the MCP server Entity. Add the Grant. |
| FusionAuth returns `invalid_scope` with `The permission names [...] are invalid`. | The scope names a permission that the Grant doesn't include. Add the permission to the Grant, or remove the permission from the scope. |
| The SDK throws an issuer mismatch error. | `expectedIssuer`, `authorization_servers`, and the Tenant's **Issuer** must all be the same URL. |

Related

[Authentication OAuth Client Credentials Grant Learn how to get an access token for machine-to-machine requests with the OAuth Client Credentials grant. oauthclient credentials grantmachine to machine](https://fusionauth.io/docs/authentication/oauth/client-credentials.md)

[Authentication Connect claude.ai And chatgpt.com To A FusionAuth-Protected MCP Server Learn how to connect claude.ai and chatgpt.com to an MCP server protected by FusionAuth using Client ID Metadata Documents. mcp servermodel context protocoloauth](https://fusionauth.io/docs/authentication/oauth/mcp-clients-claude-chatgpt.md)

[Authorization Control MCP Server Access Learn how to protect Model Context Protocol (MCP) servers with OAuth authentication using FusionAuth. mcp servermodel context protocolai security](https://fusionauth.io/docs/authorization/mcp-server-access.md)

[APIs Entity API Learn about the APIs for creating, retrieving, updating and deleting entities, as well as searching them. machine to machinem2m](https://fusionauth.io/docs/apis/entities/entities.md)
---

## Other pages in OAuth

> For the full index of this section, see [Authentication](https://fusionauth.io/docs/llms-authentication.txt).

- [Add FusionAuth Login to an App You Build](https://fusionauth.io/docs/authentication/oauth/add-login-to-your-app.md): Learn how to add FusionAuth login to a web, mobile, or single-page app you build with an OpenID Connect library and the OAuth Authorization Code grant.
- [OAuth Authorization Code Grant](https://fusionauth.io/docs/authentication/oauth/authorization-code.md): Learn how to log users in with the OAuth Authorization Code grant and PKCE.
- [CIMD Registration Caching And Lifecycle](https://fusionauth.io/docs/authentication/oauth/cimd-registration-lifecycle.md): Learn how long FusionAuth caches a Client ID Metadata Document, what happens when it expires, and how a CIMD client registration is refreshed or removed.
- [OAuth Client Credentials Grant](https://fusionauth.io/docs/authentication/oauth/client-credentials.md): Learn how to get an access token for machine-to-machine requests with the OAuth Client Credentials grant.
- [OAuth Client Registration | Static and CIMD](https://fusionauth.io/docs/authentication/oauth/client-registration.md): Learn how FusionAuth registers OAuth clients, either ahead of time as Applications or just-in-time from a Client ID Metadata Document.
- [OAuth Device Authorization Grant](https://fusionauth.io/docs/authentication/oauth/device.md): Learn how to log users in on TVs and other input-constrained devices with the OAuth Device Authorization grant.
- [Use DPoP In A Browser App](https://fusionauth.io/docs/authentication/oauth/dpop/browser-app.md): Learn how to bind tokens to the browser with DPoP using the FusionAuth React, Angular, or Vue SDK.
- [Demonstrating Proof-of-Possession (DPoP)](https://fusionauth.io/docs/authentication/oauth/dpop.md): Learn how DPoP binds FusionAuth access and refresh tokens to a key pair that only your client holds.
- [Validate DPoP Requests In Your API](https://fusionauth.io/docs/authentication/oauth/dpop/validate-requests.md): Learn how to check DPoP proofs and DPoP-bound FusionAuth access tokens in your API.
- [Host A Client ID Metadata Document (CIMD)](https://fusionauth.io/docs/authentication/oauth/host-cimd-document.md): Publish a Client ID Metadata Document so your OAuth client can log in to FusionAuth without being registered ahead of time.
- [OAuth](https://fusionauth.io/docs/authentication/oauth.md): Learn about the OAuth 2.0 and OpenID Connect grants FusionAuth supports for login and single sign-on.
- [OAuth Issuer Validation](https://fusionauth.io/docs/authentication/oauth/issuer-validation.md): Learn how to validate the authorization response issuer parameter (RFC 9207) to prevent mix-up attacks.
- [Legacy OAuth Implicit and Password Grants](https://fusionauth.io/docs/authentication/oauth/legacy-grants.md): Learn how the legacy OAuth Implicit and Password grants work in FusionAuth, for existing integrations.
- [Connect claude.ai And chatgpt.com To A FusionAuth-Protected MCP Server](https://fusionauth.io/docs/authentication/oauth/mcp-clients-claude-chatgpt.md): Learn how to connect claude.ai and chatgpt.com to an MCP server protected by FusionAuth using Client ID Metadata Documents.
- [Modes](https://fusionauth.io/docs/authentication/oauth/modes.md): Learn about the eight common ways apps use OAuth and OpenID Connect.
- [OIDC Prompt](https://fusionauth.io/docs/authentication/oauth/prompt.md): Learn about OpenID Connect prompt and example use cases.
- [OAuth Refresh Token Grant](https://fusionauth.io/docs/authentication/oauth/refresh-token.md): Learn how to exchange a refresh token for a new access token with the OAuth Refresh Token grant.
- [OAuth Response Modes](https://fusionauth.io/docs/authentication/oauth/response-modes.md): Learn about OAuth 2.0 response modes (query, fragment, form_post) and when to use each one.
- [Manage Software Tokens](https://fusionauth.io/docs/authentication/oauth/tokens.md): Learn about OAuth2 and OpenID Connect Tokens and how they are used.
- [URL Validation](https://fusionauth.io/docs/authentication/oauth/url-validation.md): Learn about OAuth URL validation policies in FusionAuth.
