Skip to content
Image Cloudflare Docs

Authenticate MCP server to self-hosted apps

Cloudflare Access can delegate access from any self-hosted application to an Access for SaaS MCP server via OAuth. The OAuth access token authorizes the MCP server to make requests to your self-hosted applications on behalf of the user, using the user's specific permissions and scopes.

For example, your organization may wish to deploy an MCP server that helps employees interact with internal applications. You can configure Access policies to ensure that only authorized users can access those applications, either directly or by using an MCP client.

flowchart LR
accTitle: Link MCP servers and self-hosted applications in Access
    subgraph SaaS["Access for SaaS <br> OIDC app"]
        mcp["MCP server <br> for internal apps"]
    end

    subgraph "Access self-hosted app"
        app1[Admin dashboard]
    end

    subgraph "Access self-hosted app"
        app2[Company wiki]
    end

		User --> client["MCP client"]
    client --> mcp
    mcp -- Access token --> app1
		mcp -- Access token --> app2
		idp[Identity provider] <--> SaaS

This guide covers how to use the Cloudflare API to link a self-hosted application to a remote MCP server. The core of this feature is the Linked App Token rule type, which allows an Access policy on one application to accept OAuth access tokens generated for another.

Prerequisites

1. Secure the MCP server with Access for SaaS

The first step is to add the MCP server to Cloudflare Access as an OIDC-based SaaS application. For step-by-step instructions on how to add an MCP server, refer to Secure MCP servers with Access for SaaS.

2. Create an Access policy with a Linked App Token

  1. Create a new Access policy.

  2. Set the policy Action to Service Auth.

  3. For Selector, select Linked App Token.

  4. For Value, select the SaaS application created in step 1. For example,

    ActionRule typeSelectorValue
    Service AuthIncludeLinked App Tokenmcp-server-cf-access

This policy will allow requests if they present a valid OAuth access token that was issued for the specified SaaS application.

3. Update the self-hosted application

You can add the Linked App Token policy to any self-hosted application in your Zero Trust account. Other app types (such as SaaS applications) are not currently supported.

4. Configure the MCP server

With the policy in place, every API request to the self-hosted application must now include a valid access_token from Cloudflare Access. You will need to configure the MCP server to forward the access_token in an HTTP request header:

Authorization: Bearer ACCESS_TOKEN

The end-to-end authorization flow is as follows:

  1. The MCP server authenticates against the Access for SaaS app via OAuth.
  2. Upon success, the MCP server receives an access_token.
  3. The MCP server makes an API request to the self-hosted application with the token in the request headers.
  4. Cloudflare Access intercepts the request to the self-hosted app, inspects the token, and validates it against the linked_app_token rule in the policy.
  5. If the token is valid and was issued for the linked SaaS app, the request is allowed. Otherwise, it is blocked.

Known limitations

The MCP OAuth feature only works with self-hosted applications that rely on the Cloudflare Access JWT to authenticate and identify the user. If the application implements its own layer of authentication after Cloudflare Access, then this feature is at best a partial solution. Requests that are successfully authenticated by Access may still be blocked by the application itself, resulting in an HTTP 401 or 403 error.