Cloud Services·
advanced
·12 min read·Apr 4, 2026·Updated Oct 10, 2026
By Rad Tome·Lead AI Systems Architect·How we verify this

Cloudflare MCP Server Edge Infrastructure Guide

Deploy serverless Workers, query KV namespaces, manage R2 object storage, and configure DNS records using the official Cloudflare MCP server.

cloudflarecloudflare workersedge computingdns managementkv storer2 storagemodel context protocoldevops
Config Target: claude_desktop_config.json
{
  "mcpServers": {
    "cloudflare": {
      "command": "npx",
      "args": [
        "-y",
        "@cloudflare/mcp-server-cloudflare"
      ],
      "env": {
        "CLOUDFLARE_API_TOKEN": "cf_xxxxxxxxxxxx",
        "CLOUDFLARE_ACCOUNT_ID": ""
      }
    }
  }
}
Interactive Tool
1-Click Export

Generate & Test Cloudflare Workers MCP Server Config

One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.

Open in Generator

Cloudflare MCP Server Edge Infrastructure Guide

Edge computing networks allow organizations to execute serverless logic, cache high-velocity data, and route global internet traffic within milliseconds of end users. As modern cloud architectures transition from monolithic origin servers toward distributed edge primitives, configuring and orchestrating these environments across dozens of domains can become a tedious administrative burden.

The official Cloudflare Model Context Protocol (MCP) server establishes a direct, programmatic bridge between local artificial intelligence hosts and Cloudflare's global edge infrastructure. Operating through standard JSON-RPC 2.0 message transports, the server allows AI assistants in Claude Desktop, Cursor, and OpenAI Codex CLI to deploy serverless Cloudflare Workers, inspect key-value records in Workers KV, query R2 object storage buckets, and manage authoritative DNS records with conversational precision.


1. Problem Statement and Architecture

Modern cloud operations require continuous context switching between command-line deployment tooling (wrangler), browser dashboards, and source code editors:

  1. ▸Repetitive DNS and Edge Provisioning: Creating preview environments, pointing subdomains to Netlify or Vercel deployments, and managing DKIM or SPF records frequently introduces typos and configuration drift.
  2. ▸Context Fragmentation: When debugging distributed microservices, engineers must manually query edge KV stores, inspect edge logs, and correlate responses against application business logic.
  3. ▸Privilege Over-Granting: Traditional operations scripts often reuse wide Global API Keys, violating least-privilege security mandates across multi-tenant developer organizations.
code
+-----------------------------------------------------------------------------------+
|                              Client Architecture                                  |
|                                                                                   |
|  +--------------------+        JSON-RPC 2.0 (stdio)        +-------------------+  |
|  |  Claude / Cursor   | <================================> | mcp-server-cf     |  |
|  +--------------------+                                    +---------+---------+  |
+----------------------------------------------------------------------|------------+
                                                                       | HTTPS REST API
                                                                       | Scoped Bearer Token
                                                                       v
                                                             +-------------------+
                                                             | Cloudflare Edge   |
                                                             | (Workers / KV /   |
                                                             |  R2 / DNS Engine) |
                                                             +-------------------+

The @cloudflare/mcp-server-cloudflare daemon runs locally on the engineer's machine. When the AI agent decides to execute an edge action, the server transforms the JSON-RPC request into an authenticated HTTPS call against the Cloudflare v4 REST API, enforcing account-scoped security boundaries.


2. Prerequisites and Environment Matrix

Running the Cloudflare MCP server requires Node.js 18 or later and a scoped Cloudflare API Token.

ComponentMinimum VersionRecommendedNotes
Node.js18.18.0+20.x LTS or 22.xRuntime for npx execution
Cloudflare AccountFree or Paid PlanEnterprise / ProActive zone and account ID required
Claude Desktop0.7.0+LatestNative desktop client
Cursor IDE0.42.0+LatestFull agentic programming support
OpenAI Codex CLI0.1.0+LatestCommand-line workflow harness

Generating a Scoped Cloudflare API Token

Never provide your agent with a Global API Key. Create a scoped API Token instead:

  1. ▸Log in to the Cloudflare Dashboard and navigate to My Profile -> API Tokens.
  2. ▸Click Create Token -> Create Custom Token.
  3. ▸Configure the following permissions based on your workflow requirements:
    • ▸Account -> Workers Scripts -> Edit
    • ▸Account -> Workers KV Storage -> Edit
    • ▸Account -> Workers R2 Storage -> Read or Edit
    • ▸Zone -> DNS -> Edit
  4. ▸Set Account Resources and Zone Resources to include only your designated development account and domains.
  5. ▸Copy the generated secret token string.

3. Multi-Host Configuration Snippets

The server accepts your credentials through environment variables. Below are verified configurations for leading developer environments.

Claude Desktop

Edit your claude_desktop_config.json:

json
{
  "mcpServers": {
    "cloudflare": {
      "command": "npx",
      "args": ["-y", "@cloudflare/mcp-server-cloudflare"],
      "env": {
        "CLOUDFLARE_API_TOKEN": "YOUR_SCOPED_API_TOKEN",
        "CLOUDFLARE_ACCOUNT_ID": "YOUR_HEX_ACCOUNT_ID"
      }
    }
  }
}

Cursor IDE

In .cursor/mcp.json or your global workspace settings:

json
{
  "mcpServers": {
    "cloudflare": {
      "command": "npx",
      "args": ["-y", "@cloudflare/mcp-server-cloudflare"],
      "env": {
        "CLOUDFLARE_API_TOKEN": "YOUR_SCOPED_API_TOKEN",
        "CLOUDFLARE_ACCOUNT_ID": "YOUR_HEX_ACCOUNT_ID"
      }
    }
  }
}

OpenAI Codex CLI

In ~/.codex/config.toml:

toml
[mcp_servers.cloudflare]
command = "npx"
args = ["-y", "@cloudflare/mcp-server-cloudflare"]
env = { CLOUDFLARE_API_TOKEN = "YOUR_SCOPED_API_TOKEN", CLOUDFLARE_ACCOUNT_ID = "YOUR_HEX_ACCOUNT_ID" }

4. Step-by-Step Tool Discovery and Invocation

Upon handshake, the server advertises tools spanning edge script deployment, data querying, and DNS operations:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "list_zones",
        "description": "List all active Cloudflare DNS zones in the account.",
        "inputSchema": { "type": "object", "properties": {} }
      },
      {
        "name": "create_dns_record",
        "description": "Create a new DNS record in a specified zone.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "zone_id": { "type": "string", "description": "Hexadecimal zone ID" },
            "type": { "type": "string", "enum": ["A", "AAAA", "CNAME", "TXT", "MX"] },
            "name": { "type": "string", "description": "Host subdomain name" },
            "content": { "type": "string", "description": "Target IP or DNS name" },
            "proxied": { "type": "boolean", "default": true }
          },
          "required": ["zone_id", "type", "name", "content"]
        }
      },
      {
        "name": "get_kv_value",
        "description": "Read a string or JSON value from a Workers KV namespace.",
        "inputSchema": {
          "type": "object",
          "properties": {
            "namespace_id": { "type": "string" },
            "key": { "type": "string" }
          },
          "required": ["namespace_id", "key"]
        }
      }
    ]
  }
}

Tool Invocation Wire Frame

When prompted: "Create a proxied CNAME record pointing api.example.com to gateway.internal.net", the host issues:

json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "create_dns_record",
    "arguments": {
      "zone_id": "023e105f4ecef8ad9ca31a8372d0c353",
      "type": "CNAME",
      "name": "api.example.com",
      "content": "gateway.internal.net",
      "proxied": true
    }
  }
}

The daemon contacts the Cloudflare DNS API and returns the confirmed configuration:

json
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Successfully created DNS record:\nID: 372e67954025e0ba6aaa6d586b9e0b59\nType: CNAME\nName: api.example.com\nContent: gateway.internal.net\nProxied: true\nTTL: Auto"
      }
    ],
    "isError": false
  }
}

5. Common Errors and Production Troubleshooting

1. Error 10000: Authentication Error

  • ▸Symptom: All tool invocations return HTTP 403 with Cloudflare error code 10000.
  • ▸Root Cause: The API token is invalid, expired, or lacks permission for the specified Account ID or Zone ID.
  • ▸Solution: Verify the token status using curl in your terminal:
bash
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
     -H "Authorization: Bearer YOUR_SCOPED_API_TOKEN"

If the verification fails, re-generate the token and verify that the account membership has not changed.

2. Workers KV Eventual Consistency Race Conditions

  • ▸Symptom: An agent writes a key via put_kv_value and immediately fails a subsequent verification step because get_kv_value returns null or old data.
  • ▸Root Cause: Workers KV utilizes a globally distributed, eventually consistent caching architecture. Propagating updates across hundreds of edge data centers can take up to 60 seconds.
  • ▸Solution: Instruct your assistant that KV operations are eventually consistent and do not represent immediate transactional state. For strong immediate consistency, configure Cloudflare D1 (Serverless SQL) or Hyperdrive.

3. R2 Large File Payload Truncation

  • ▸Symptom: Fetching an object from R2 causes the MCP host to crash with buffer allocation errors.
  • ▸Root Cause: Large binary blobs or extensive database dumps exceed the in-memory JSON-RPC message buffer limits of the stdio transport.
  • ▸Solution: Restrict agent R2 queries to text assets, configuration payloads, and metadata objects, or have the agent generate short-lived pre-signed URLs instead of streaming binary blobs.

6. External Citations and Security Guardrails

Managing live DNS records and edge compute through autonomous agents demands strict safeguards:

  1. ▸Zone Whitelisting: Scope API tokens exclusively to non-production staging zones during automated experimentation.
  2. ▸Audit Logging: Enable Cloudflare Audit Logs to monitor all API token actions and detect unexpected record modifications.
  3. ▸Verified Registry Dependency: Always pull the official package from npm under the verified @cloudflare organization scope.
Technical Changelog

Weekly Protocol Diffs & Verified Drops

New server guides, benchmarks, and security audits. No spam. Unsubscribe anytime.

Zero marketing spam. 1-click unsubscribe anytime.

Ready to Deploy?

Build your full agent toolstack in the Visual Generator

Combine Cloudflare with databases, search APIs, and memory graphs in a single configuration file.

Customize in Generator
Developer Verification & Feedback
0 reports

Did this setup guide work with your AI host?

Help test this configuration across Claude, Cursor, and Codex CLI. Be the first to report:

Cloudflare MCP Server Edge Infrastructure Guide FAQ

What is the Cloudflare MCP Server Edge Infrastructure Guide?

Deploy serverless Workers, query KV namespaces, manage R2 object storage, and configure DNS records using the official Cloudflare MCP server.

How do I configure Cloudflare MCP Server Edge Infrastructure Guide in Claude Desktop or Cursor?

You can copy the configuration JSON from our guide or launch the interactive MCP Codex Config Generator at https://mcp-codex.com/generator to export valid configs in 1 click.

Can I use Cloudflare MCP Server Edge Infrastructure Guide with the OpenAI Codex CLI?

Yes, OpenAI Codex CLI supports Model Context Protocol. You can add it directly to ~/.codex/config.toml or pass arguments to codex mcp add.

RT

Written by Rad Tome

Lead AI Systems Architect & Maintainer, MCP Codex

@RadTome

Specializing in Model Context Protocol (MCP) integrations, autonomous AI agent orchestration, and distributed developer toolchains. Researches and benchmarks production MCP client-server architectures across OpenAI Codex, Claude, and Cursor.

Editorial Integrity: Package names are checked against the npm registry and repositories against the GitHub API. Where a package could not be verified, the guide says so instead of giving you a command to run.

Related Guides