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.
claude_desktop_config.json{
"mcpServers": {
"cloudflare": {
"command": "npx",
"args": [
"-y",
"@cloudflare/mcp-server-cloudflare"
],
"env": {
"CLOUDFLARE_API_TOKEN": "cf_xxxxxxxxxxxx",
"CLOUDFLARE_ACCOUNT_ID": ""
}
}
}
}Generate & Test Cloudflare Workers MCP Server Config
One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.
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:
- ▸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.
- ▸Context Fragmentation: When debugging distributed microservices, engineers must manually query edge KV stores, inspect edge logs, and correlate responses against application business logic.
- ▸Privilege Over-Granting: Traditional operations scripts often reuse wide Global API Keys, violating least-privilege security mandates across multi-tenant developer organizations.
+-----------------------------------------------------------------------------------+
| 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.
| Component | Minimum Version | Recommended | Notes |
|---|---|---|---|
| Node.js | 18.18.0+ | 20.x LTS or 22.x | Runtime for npx execution |
| Cloudflare Account | Free or Paid Plan | Enterprise / Pro | Active zone and account ID required |
| Claude Desktop | 0.7.0+ | Latest | Native desktop client |
| Cursor IDE | 0.42.0+ | Latest | Full agentic programming support |
| OpenAI Codex CLI | 0.1.0+ | Latest | Command-line workflow harness |
Generating a Scoped Cloudflare API Token
Never provide your agent with a Global API Key. Create a scoped API Token instead:
- ▸Log in to the Cloudflare Dashboard and navigate to My Profile -> API Tokens.
- ▸Click Create Token -> Create Custom Token.
- ▸Configure the following permissions based on your workflow requirements:
- ▸
Account->Workers Scripts->Edit - ▸
Account->Workers KV Storage->Edit - ▸
Account->Workers R2 Storage->ReadorEdit - ▸
Zone->DNS->Edit
- ▸
- ▸Set Account Resources and Zone Resources to include only your designated development account and domains.
- ▸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:
{
"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:
{
"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:
[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:
{
"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:
{
"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:
{
"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:
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_valueand immediately fails a subsequent verification step becauseget_kv_valuereturnsnullor 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:
- ▸Zone Whitelisting: Scope API tokens exclusively to non-production staging zones during automated experimentation.
- ▸Audit Logging: Enable Cloudflare Audit Logs to monitor all API token actions and detect unexpected record modifications.
- ▸Verified Registry Dependency: Always pull the official package from npm under the verified
@cloudflareorganization scope.
Weekly Protocol Diffs & Verified Drops
New server guides, benchmarks, and security audits. No spam. Unsubscribe anytime.
Zero marketing spam. 1-click unsubscribe anytime.
Build your full agent toolstack in the Visual Generator
Combine Cloudflare with databases, search APIs, and memory graphs in a single configuration file.
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.
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.
Related Guides
Cloud Infrastructure Auditor MCP Guide
Run automated cloud configuration security audits. Identify leaky S3 buckets, open security group ports, and loose IAM profiles directly from your IDE.
Cloud ServicesKubernetes and Helm MCP Server Guide
Connect your Kubernetes clusters and Helm releases to AI agents via MCP. Run safe container diagnostics, view cluster logs, and perform rollbacks.
Cloud ServicesNotion MCP Server Setup for Codex & Claude | Search, Create, Update Pages
Integrate Notion with OpenAI Codex & Claude. Query databases, create pages, update content via MCP. Includes Notion API token setup, config.toml example, and tool reference (search_pages, create_page, update_page).