How to Use the Cloudflare MCP Server for Edge Infrastructure
Manage Cloudflare Workers, KV stores, R2 buckets, and DNS settings through your AI agent using the Cloudflare MCP server.
Use the Cloudflare MCP Server for Edge Infrastructure
The Cloudflare MCP server acts as an administrative bridge between your AI agent and your edge infrastructure. It allows the agent to deploy serverless Workers, edit KV storage values, manage R2 blob storage, and configure DNS records across your Cloudflare zones.
Prerequisites
- ▸A Cloudflare account with active domains/zones.
- ▸A Cloudflare API Token with appropriate permissions.
- ▸Node.js 18+ installed locally.
Creating a Scoped API Token
Never give your agent a Global API Key. Create a scoped token:
- ▸Go to Cloudflare Dashboard → My Profile → API Tokens.
- ▸Click Create Token → Custom Token.
- ▸Grant the following
Editpermissions depending on your needs:- ▸Workers Scripts
- ▸Workers KV Storage
- ▸Workers R2 Storage
- ▸Zone DNS
- ▸Restrict the token to specific Account Resources or Zones if possible.
- ▸Copy the generated token.
Configuration Setup
{
"mcpServers": {
"cloudflare": {
"command": "npx",
"args": ["-y", "@cloudflare/mcp-server-cloudflare"],
"env": {
"CLOUDFLARE_API_TOKEN": "your_api_token_here",
"CLOUDFLARE_ACCOUNT_ID": "your_account_id_here"
}
}
}
}Available Tools
Your agent will be equipped with dozens of management tools, categorized below:
Workers
- ▸
list_workers/get_worker/create_worker/delete_worker
KV Store
- ▸
list_kv_namespaces/list_kv_keys/get_kv_value/put_kv_value
R2 Storage
- ▸
list_r2_buckets/list_r2_objects/get_r2_object/put_r2_object
DNS
- ▸
list_zones/list_dns_records/create_dns_record/update_dns_record
Example Workflows
- ▸Worker Deployment: "Create a new Cloudflare Worker that intercepts traffic to
/old-apiand returns a 301 redirect to/new-api. Deploy it to my account." - ▸KV Data Management: "List all keys in the 'user-preferences' KV namespace and show me the JSON values for the 'admin-theme' key."
- ▸DNS Management: "Add a CNAME record pointing
blog.mywebsite.comtomywebsite.netlify.app."
Best Practices & Troubleshooting
- ▸KV Propagation Delays: Cloudflare KV is eventually consistent. If your agent uses
put_kv_valueand immediately usesget_kv_valueto verify it, it might receive stale data. Instruct the agent to account for up to 60 seconds of global propagation delay. - ▸R2 Payload Limits: Reading a massive multi-gigabyte video file from R2 using
get_r2_objectwill crash the MCP JSON-RPC connection. Instruct the agent to only fetch text-based objects (like JSON or CSVs) or use pre-signed URLs. - ▸Unauthorized (Code 10000): Ensure your
CLOUDFLARE_ACCOUNT_IDenvironment variable is correct. You can find your Account ID in the URL of the Cloudflare dashboard.
Using with OpenAI Codex
To use this MCP server with the OpenAI Codex CLI, you can add it to your configuration using the codex mcp add command:
codex mcp add --name cloudflare --command "npx @modelcontextprotocol/server-cloudflare"(Note: Depending on the server, you may need to append arguments or use --env flags for environment variables as described in the configuration section above)
Related Guides
How to Set Up the Notion MCP Server for Workspace Integration
Connect your Notion workspace to AI agents. Search pages, read databases, create content, and manage your Notion knowledge base through MCP.
Cloud ServicesHow to Use the Google Drive MCP Server for Document Access
Connect Google Drive to your AI agent for searching, reading, and managing documents, spreadsheets, and files stored in your Drive.
Cloud ServicesManaging Kubernetes & Helm Administration Directly from Your AI Host
Connect your Kubernetes clusters and Helm releases to AI agents via MCP. Run safe container diagnostics, view cluster logs, and perform rollbacks.