> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server/cloudflare.md).

# Cloudflare MCP server

Install the Cloudflare agentic integration and its MCP server so agents behind the P0 AI Gateway can request Cloudflare permission groups on your account and its zones.

The **Cloudflare** agentic integration lets agents behind the AI Gateway, part of [P0 Runtime Access for AI](https://docs.p0.dev/readme/agentic-control-plane.md), request time-bound Cloudflare permission groups, such as `DNS Write` on one zone. For each agent, P0's connector keeps one account API token with only the approved groups, and stores it in your secret manager. The gateway calls Cloudflare's hosted MCP server, `https://mcp.cloudflare.com/mcp`, with that token, and Cloudflare allows only what the groups allow. When the agent's last grant ends, P0 deletes the token.

This is a different integration from [Cloudflare](https://docs.p0.dev/integrations/resource-integrations/cloudflare.md), which gives people access to Cloudflare, and from the Cloudflare entries of [SaaS MCP servers](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server/saas.md), where each user connects with their own Cloudflare login. The agentic integration appears as **Cloudflare (AI)** on the **Integrations** page.

{% hint style="info" %}
The Cloudflare agentic integration is in beta. Functionality and configuration may change.
{% endhint %}

Setup has four parts, in this order:

1. Install the Cloudflare account in P0, which deploys P0's connector in AWS or Google Cloud.
2. Create an install token in Cloudflare and store it for the connector.
3. Add the Cloudflare MCP server to your gateway.
4. Write the policies that decide which agents get which permission groups.

## Prerequisites

* A registered [Gateway](https://docs.p0.dev/agentic-access/agentic-gateway/gateway.md) component, with the gateway deployed in your environment. The gateway must be able to reach `https://mcp.cloudflare.com` and your secret manager.
* One of these, with permission to apply Terraform where it's installed. P0's connector runs there, and agents' Cloudflare tokens are stored there.
  * On AWS:
    * The [AWS Secrets Manager](https://docs.p0.dev/integrations/resource-integrations/aws-secrets-manager.md) integration installed on an AWS account. The connector runs there on AWS Lambda. Applying its Terraform also needs Docker and the AWS CLI, signed in to that account, to copy P0's connector image into your Amazon ECR.
    * [AWS OIDC](https://docs.p0.dev/agentic-access/credential-sources/aws-oidc.md) installed for that same account. The gateway uses it to read each agent's token.
  * On Google Cloud:
    * The [Google Cloud](https://docs.p0.dev/integrations/resource-integrations/google-cloud.md) integration installed for your Google Cloud organization.
    * The [Google Secret Manager](https://docs.p0.dev/integrations/resource-integrations/google-secret-manager.md) integration installed on the Google Cloud project where the connector will run. The connector runs there on Cloud Run.
    * [GCP Workload Identity Federation](https://docs.p0.dev/agentic-access/credential-sources/gcp-wif.md) installed for that same project. The gateway uses it to read each agent's token.
* A Super Administrator of the Cloudflare account, who creates the install token.

## Install the account in P0

1. Navigate to **Integrations** on [p0.app](https://p0.app), select **Cloudflare (AI)**, and choose the **Credential provisioning** component.
2. Click **Add Account**, and enter an identifier for it, such as `acme-prod`. Agents and policies use this name for the account. Use letters, digits, and hyphens, up to 64 characters.
3. Fill in the account details, then click **Next**:
   * **Account ID**: the 32-character account ID, from the account's home page in the Cloudflare dashboard.
   * **Secret manager provider**: choose where the connector will run:
     * **AWS Secrets Manager**: choose the installation for the AWS account, and enter the region that stores the secrets.
     * **Google Secret Manager**: choose the installation for the project.
4. P0 generates a Terraform configuration. Copy it into your Terraform project and `apply` it.

   On AWS, the configuration creates:

   * An Amazon ECR repository with a copy of P0's connector image, and a Lambda function, `p0-connector-cloudflare-ai-aws`, that runs it with its own IAM role.
   * A secret for the install token, `p0/install/cloudflare/<identifier>/install-token`, which only the connector can read.
   * Permission for the connector to create and manage the secrets that hold agents' tokens. Their names start with `p0/access-token/cloudflare/<identifier>/`, and the connector can touch no other secret.
   * A policy on P0's IAM role in the account that lets P0 invoke the function.

   On Google Cloud, it creates:

   * A Cloud Run service, `p0-connector-cloudflare-ai`, that runs P0's connector under its own service account, `p0-cloudflare`.
   * A secret for the install token, `p0_install_cloudflare_<identifier>_install-token`, which only the connector can read.
   * Permission for the connector to create and manage the secrets that hold agents' tokens. Their names start with `p0_access-token_cloudflare_<identifier>_`, and the connector can touch no other secret.
   * Bindings that let P0's Google Cloud service account call the connector and read its URL. The connector accepts calls from that service account only.
   * The Cloud Run, Secret Manager, IAM, and Resource Manager APIs, turned on in the project.

{% hint style="warning" %}
Install each Cloudflare account in its own AWS account or Google Cloud project. The Terraform for a second Cloudflare account in the same account or project conflicts with the first.
{% endhint %}

## Set up Cloudflare

1. **Create the install token.** As a Super Administrator, create an account API token on the account, under **Manage Account** > **Account API Tokens**. Give it only these permission groups:

   * **Account API Tokens Edit**, on the account.
   * **Zone Read**, on all zones of the account.

   See [Create tokens](https://developers.cloudflare.com/fundamentals/api/get-started/account-owned-tokens/).

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>The connector uses the install token to create agents' tokens, so the install token can give an agent any permission in the account except token management. Protect it like a Super Administrator credential.</p></div>
2. **Store the install token.** Set `CLOUDFLARE_INSTALL_TOKEN` to the token, and run the command P0 shows. On AWS:

   ```bash
   printf '%s' "$CLOUDFLARE_INSTALL_TOKEN" | aws secretsmanager put-secret-value \
     --secret-id p0/install/cloudflare/<identifier>/install-token \
     --region <secrets-region> --secret-string file:///dev/stdin
   ```

   On Google Cloud:

   ```bash
   printf '%s' "$CLOUDFLARE_INSTALL_TOKEN" | gcloud secrets versions add \
     p0_install_cloudflare_<identifier>_install-token \
     --project=<project-id> --data-file=-
   ```

   P0 never sees the install token: only your connector reads it.
3. **Click Next.** P0 checks that the connector is deployed, and that the install token is active on the account and holds both permission groups. A new connector can take a minute to start. If the check fails, wait a minute and click **Next** again. If the install token holds other permission groups, P0 names them. Remove them from the install token in Cloudflare.
4. Review the summary and click **Finish**. The account now appears with the state **Installed**.

To rotate the install token, roll it in Cloudflare, and store the new value with the same command. Agents' tokens keep working, and the connector uses the new install token at once.

## Add the Cloudflare MCP server

You can add the Cloudflare MCP server once at least one account is installed.

1. Follow the shared steps in [MCP server](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server.md#add-an-mcp-server) to name the server and choose its gateway. On the configuration screen, set the following fields, then click **Finish**:
   * **Credential source**: choose **Vaulted credential**.
   * **Definition**: choose **P0**, then select **Cloudflare**.
2. The server now appears with the state **Installed**.

One Cloudflare MCP server serves every account you install. Each grant names the account it is for.

## How agents request access

An agent requests access with the server's `access` tool. It names the account by its P0 identifier, one or more Cloudflare permission groups, and optionally a zone:

* Without a zone, the agent requests account permission groups, such as `Workers Scripts Write`.
* With a zone, it requests zone permission groups, such as `DNS Write`. The zone is a zone name in the account, such as `example.com`, or `*` for all zones, including zones added later.

For groups on several zones, the agent makes one request per zone. Every Cloudflare request needs a duration.

The agent's `list` tool shows the installed accounts, their zones, and the permission groups that an agent can request. See [API token permissions](https://developers.cloudflare.com/fundamentals/api/reference/permissions/) for what each group allows.

Access usually works within 5 seconds of approval. Agents see four tools: `docs`, `search`, `execute`, and `whoami`. The `execute` tool makes every Cloudflare API call, so the permission groups decide what a call can do. Cloudflare refuses a call that the groups don't cover.

Agents can't request these permission groups:

* Groups that let an agent take over the account:
  * Account API Tokens Write
  * Account Settings Write
  * SCIM Provisioning
  * SSO Connector Write
  * OAuth Client Write
  * Billing Write
  * Zero Trust: Seats Write
  * Access: Organizations, Identity Providers, and Groups Write, with Access: Organizations Write, Access: Identity Providers Write, and Access: Groups Write
  * Access: Apps and Policies Write, on the account and on a zone
  * Access: Service Tokens Write
  * Access: SCIM Population Write
* The groups of Intel, Page Rules, Registrar, and Turnstile, which don't accept account API tokens.
* Groups that apply to one resource, such as one R2 bucket or one Worker script, rather than to the account or a zone.

Super Bot Fight Mode and Zero Trust Client Platform don't accept account API tokens either. Cloudflare refuses their calls.

Each agent has one token per account, which holds the groups of all its open grants on that account. The tokens appear under **Account API Tokens**, with names that start with `P0`. Don't edit or delete them: P0 creates, changes, and deletes them as grants start, change, and end.

These tokens count toward Cloudflare's limit of 500 API tokens per account, with your own tokens. At the limit, a new grant fails with "This Cloudflare account has reached its limit of 500 API tokens. Delete unused tokens and retry." Delete tokens you no longer use, and have the agent request access again.

After access ends, Cloudflare's MCP server can still accept a new session for some time, but every Cloudflare API call in it fails.

See [Requesting access](https://docs.p0.dev/agentic-access/using-the-gateway/requesting-access.md) for how agents submit and use requests.

{% hint style="info" %}
P0 controls only the access that it grants. A member of your Cloudflare account who connects to `mcp.cloudflare.com` with their own login or API token doesn't go through P0. Limit that with member roles and with who can create API tokens. In Cloudflare's audit log, direct use shows with actor type `user` and context `oauth`. P0's grants show with actor type `account`.
{% endhint %}

## Write policies for Cloudflare

Match Cloudflare requests in an agentic access policy ([Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md)) with `service: cloudflare-ai` and `accessType: permission`. Three filters narrow them:

* `account`: the account, keyed on `name`, the identifier you gave the account in P0.
* `zone`: the zone, keyed on `name`. A request on all zones has the zone `*`, so match it with `^\*$`. A request without a zone has an empty zone.
* `policy`: the permission group, keyed on `name`, such as `DNS Read`. A rule covers a request only if it matches every group in it.

Patterns are regular expressions, so a rule can match one group (`^DNS Read$`), or every read group (`^.* Read$`).

For example, auto-approve read access to DNS and analytics for one agent, but only on the `example.com` zone of the `acme-prod` account:

```yaml
- requestor:
    type: agentic
    actor:
      type: agent-client
      clientId: reporting-agent
    subject:
      type: any
  resource:
    type: integration
    service: cloudflare-ai
    accessType: permission
    filters:
      account:
        effect: keep
        key: name
        pattern: ^acme-prod$
      zone:
        effect: keep
        key: name
        pattern: ^example\.com$
      policy:
        effect: keep
        key: name
        pattern: ^(DNS|Analytics) Read$
  approval:
    - type: persistent
      maxDuration: { time: 1, unit: h }
```

{% hint style="warning" %}
P0 removes the agent's access when the grant ends, but not what the agent made with it. A Worker, a Pages project, or a Tunnel stays until you delete it. Route the write groups of those products to a human approver.
{% endhint %}

## Remove the integration

1. **End or revoke every active grant**, so that P0 deletes each agent's token and its secret.

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>A grant that is still open when you delete the account leaves its token in Cloudflare and its secret in your secret manager.</p></div>
2. **Remove the Cloudflare MCP server** from your gateway.
3. **Delete the account** from the **Cloudflare (AI)** integration in P0.
4. **Remove the Cloudflare resources** from your Terraform configuration: the connector, the install token's secret, and the connector's roles and bindings. Then run `terraform apply`.
5. **Delete what P0 created in Cloudflare.** Under **Manage Account** > **Account API Tokens**, delete any tokens whose names start with `P0`, then the install token.

## Next steps

* Define the [Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md) that decide which agents and users can request Cloudflare access.
