Cloudflare MCP: Code Mode and the Domain Servers
Cloudflare MCP is Cloudflare’s set of remote MCP servers for AI coding agents. The recommended Code Mode server at https://mcp.cloudflare.com/mcp covers the whole Cloudflare API with three tools (search, execute, docs) in about 1,100 tokens of context (README). Domain servers, such as Observability and Workers Bindings, add typed tools for one area. Both accept OAuth or an API token.
This page is for developers and tech leads who ship on Cloudflare Workers. You deploy a Worker on Friday, error rates rise on Saturday, and you spend an hour switching between the Workers dashboard, the D1 console, and the docs to learn which route broke. With the right Cloudflare server connected, the agent answers that question in one prompt and shows you the query it ran.
New to MCP? Start with MCP servers and MCP best practices, then come back for the Cloudflare specifics.
What you get from Cloudflare MCP on this page
Section titled “What you get from Cloudflare MCP on this page”- A decision table for Code Mode versus the domain servers, and the current list of domain server URLs.
- Install commands for Claude Code, Codex, and Cursor, through the
cloudflareplugin or as a plain MCP entry. - A rule for choosing OAuth or an API token, and a way to keep the token out of your config files.
- A copy-paste prompt that ranks Worker errors from the last hour by route.
- A D1 migration workflow (plan, build, verify, ship, observe) with the gates that prove it worked.
- The traps that break older setups:
/ssereturning410 Gone, truncated results, and the wrong npm package.
Which Cloudflare MCP server should you connect?
Section titled “Which Cloudflare MCP server should you connect?”Cloudflare publishes two kinds of servers. The Code Mode server lives in the cloudflare/mcp repository. The domain servers live in cloudflare/mcp-server-cloudflare. Both READMEs were read on 2026-09-26.
| You want to… | Connect | Why |
|---|---|---|
| Reach any Cloudflare product (Workers, KV, R2, D1, DNS, Access, and more) from one server | Code Mode, https://mcp.cloudflare.com/mcp | Three tools cover the whole API, so context cost stays flat |
| Debug Workers logs and metrics with purpose-built queries | Observability, https://observability.mcp.cloudflare.com/mcp | Typed tools for events, metrics, and field discovery |
| Manage KV, R2, D1, and Hyperdrive with named tools | Workers Bindings, https://bindings.mcp.cloudflare.com/mcp | One tool per action, such as d1_database_query |
| Look up current Cloudflare docs only | Documentation, https://docs.mcp.cloudflare.com/mcp | No account access at all |
Start with Code Mode. Add a domain server only when you keep asking the agent for the same product area and want typed tools for it.
The domain servers, as listed in the mcp-server-cloudflare README on 2026-09-26:
| Server | URL | Use it for |
|---|---|---|
| Documentation | https://docs.mcp.cloudflare.com/mcp | Current reference docs |
| Workers Bindings | https://bindings.mcp.cloudflare.com/mcp | Workers, KV, R2, D1, and Hyperdrive |
| Workers Builds | https://builds.mcp.cloudflare.com/mcp | Workers Builds history and insights |
| Observability | https://observability.mcp.cloudflare.com/mcp | Workers logs and analytics |
| Container | https://containers.mcp.cloudflare.com/mcp | A sandbox development environment |
| Browser Run | https://browser.mcp.cloudflare.com/mcp | Fetch pages, convert them to Markdown, take screenshots |
| Logpush | https://logs.mcp.cloudflare.com/mcp | Logpush job health |
| AI Gateway | https://ai-gateway.mcp.cloudflare.com/mcp | AI Gateway logs, prompts, and responses |
| AutoRAG | https://autorag.mcp.cloudflare.com/mcp | AutoRAG instances |
| DNS Analytics | https://dns-analytics.mcp.cloudflare.com/mcp | DNS performance and debugging |
| Digital Experience Monitoring | https://dex.mcp.cloudflare.com/mcp | Application health for your organization |
| Cloudflare One CASB | https://casb.mcp.cloudflare.com/mcp | SaaS security misconfigurations |
| Radar | https://radar.mcp.cloudflare.com/mcp | Internet traffic insights |
| Cloudflare Blog | https://blog.mcp.cloudflare.com/mcp | Blog search |
There is no separate KV, R2, or D1 server (README checked 2026-09-26). Those resources come through Code Mode or Workers Bindings. The README also lists a minimal Demo Day server, which is a sample, not a tool you need.
How does Code Mode fit the whole Cloudflare API into about 1,100 tokens?
Section titled “How does Code Mode fit the whole Cloudflare API into about 1,100 tokens?”Code Mode keeps the OpenAPI spec on the server. Instead of one tool per endpoint, the agent gets three tools:
| Tool | What the agent does with it |
|---|---|
search | Writes JavaScript that queries spec.paths to find the right endpoints |
execute | Writes JavaScript that calls cloudflare.request() against the endpoints it found |
docs | Searches Cloudflare’s developer documentation |
Cloudflare’s own measurement in the cloudflare/mcp README (read 2026-09-26) puts the three Code Mode tools at about 1,100 tokens. The same API as native MCP tools with only required parameters costs 244,047 tokens, and with full schemas it costs 1,170,523. Only the result of the code reaches the agent, not the spec.
Two URL parameters change that behaviour:
- Result cap. Each tool result is capped at about 6,000 tokens by default. Long lists keep their first items, long strings are clipped, and every cut is marked
--- TRUNCATED ---. Add?truncateToolResult=falseonly when your client bounds results itself. Without the cap, a broad query can fill the context window on its own. - Code Mode off.
?codemode=falseregisters one tool per endpoint (about 2,500 tools). Cloudflare recommends it only when you compose the server with another Code Mode system. Thedocstool stays in both modes.
For the wider technique, including context-mode and CLI-plus-skill routes, see how to reduce MCP token cost.
How do you connect Cloudflare MCP to Claude Code, Codex, and Cursor?
Section titled “How do you connect Cloudflare MCP to Claude Code, Codex, and Cursor?”The simplest route is the cloudflare plugin from the cloudflare/skills repository. The plugin bundles the Code Mode server with 14 skills, including wrangler and workers-best-practices. It deliberately bundles only the Code Mode server, so you add domain servers yourself.
Install the plugin in a Claude Code session:
/plugin marketplace add cloudflare/skills/plugin install cloudflare@cloudflareThe same plugin is also listed as cloudflare@claude-plugins-official. Install it from one marketplace only.
To add servers without the plugin, run this in your terminal:
claude mcp add --transport http cloudflare https://mcp.cloudflare.com/mcpclaude mcp add --transport http cf-observability https://observability.mcp.cloudflare.com/mcpThen run /mcp in a session and sign in to each server through the browser.
Install the plugin from your terminal:
codex plugin marketplace add cloudflare/skillscodex plugin add cloudflare@cloudflarecloudflare@openai-curated in OpenAI’s curated marketplace wires the same Code Mode URL. Start a new Codex session after installing.
To add servers without the plugin:
codex mcp add cloudflare --url https://mcp.cloudflare.com/mcpcodex mcp add cf-observability --url https://observability.mcp.cloudflare.com/mcpcodex mcp login cloudflarecodex mcp login cf-observabilityCloudflare’s README says to install the plugin from the Cursor Marketplace. To add the servers yourself, put this in .cursor/mcp.json:
{ "mcpServers": { "cloudflare": { "url": "https://mcp.cloudflare.com/mcp" }, "cf-observability": { "url": "https://observability.mcp.cloudflare.com/mcp" } }}The Cursor lines come from Cloudflare’s README, not from a test: cursor.com was not reachable when this page was checked.
The first call to each server opens a Cloudflare sign-in page. There you choose the account and the permissions the server gets.
Should you use OAuth or an API token?
Section titled “Should you use OAuth or an API token?”| Situation | Use | Why |
|---|---|---|
| Your own laptop, interactive work | OAuth | You pick permissions at sign-in and never handle a secret |
| CI, scheduled jobs, headless agents | API token as a bearer token | No browser; scope the token to exactly what the job needs |
| Token restricted by Client IP Address Filtering | Neither works yet | Cloudflare’s README says these tokens are not supported |
For an account token, include Account Resources : Read so the server can detect your account ID. Keep the token out of the command line and out of committed files. Read it from an environment variable with a name of your own:
Add this to .mcp.json at the repository root (project scope):
{ "mcpServers": { "cloudflare": { "type": "http", "url": "https://mcp.cloudflare.com/mcp", "headers": { "Authorization": "Bearer ${CF_MCP_TOKEN}" } } }}Claude Code expands ${VAR} in .mcp.json headers. Use a variable name you own, such as CF_MCP_TOKEN.
codex mcp add cloudflare --url https://mcp.cloudflare.com/mcp --bearer-token-env-var CF_MCP_TOKENCursor’s header and variable syntax was not verifiable when this page was checked. Use OAuth in Cursor, and use Claude Code or Codex for token-based CI jobs.
Example: which route threw the most Worker errors in the last hour?
Section titled “Example: which route threw the most Worker errors in the last hour?”Connect the Observability server (or Code Mode) and paste this prompt. Replace api-worker with your Worker’s name.
With the Observability server, the agent typically calls observability_keys to find the field names in your logs, then query_worker_observability to group events. With Code Mode, it first runs search to find the observability endpoint, then execute. Either way you get a short table and a reproducible query.
To trust the answer without auditing every tool call, check two things. The request total should match the Workers dashboard for the same hour. The request IDs the agent quotes should open real log lines. If the totals disagree, the agent grouped on a field that is missing from part of your traffic. Ask it to rerun with observability_values on that field first.
Workflow: ship a D1 migration with Cloudflare skills and the observability server
Section titled “Workflow: ship a D1 migration with Cloudflare skills and the observability server”This loop uses the cloudflare plugin’s wrangler skill to build the change, local gates to verify it, and the Observability server to confirm production after deploy. The agent never touches production data: a human or CI runs the remote steps.
-
Plan. Write the behaviour in two or three sentences, for example “store sessions in D1 so they survive a deploy”. Add the acceptance check: an integration test that writes and reads a session through the Worker.
-
Build. Paste the build prompt below. The
wranglerskill loads on its own, because the request matches its trigger (Workers, D1, deploys). -
Verify locally. The agent runs
npx wrangler d1 migrations apply <DATABASE> --local, your tests, andnpx wrangler deploy --dry-run. All three must pass before a human looks at the diff. If you test with@cloudflare/vitest-pool-workers, the test runs against a real local D1 binding instead of a mock. -
Review. Ask the agent to review the migration and the Wrangler config with the
workers-best-practicesskill. Read the migration SQL yourself. It is the one file whose mistake you cannot roll back with a redeploy. -
Ship. A human or your CI pipeline runs
npx wrangler d1 migrations apply <DATABASE> --remote, then deploys. Keep deploys in CI when the team already has a pipeline. -
Observe. 30 minutes after the deploy, paste the observe prompt below. Compare the error rate on the touched routes with the 30 minutes before the deploy.
-
Roll back if needed.
npx wrangler rollbackrestores the previous Worker version. It does not undo a D1 migration, so ship a forward migration to fix a schema mistake.
<DATABASE> is the database name or binding from your Wrangler config.
<DEPLOY_TIME> is the deploy timestamp from your CI log or npx wrangler deployments list.
The sign-off is not a line-by-line review. It is the evidence chain: the local migration applied, tests passed, the dry run built, a human read the SQL, and the production comparison stayed flat. The developer who merges owns the ship decision. The tech lead owns the threshold (here, 1 percentage point) that triggers a rollback.
How much context does Cloudflare MCP cost?
Section titled “How much context does Cloudflare MCP cost?”Measure it in your own session instead of trusting any published number:
- In Claude Code, run
/contextbefore and after you connect a server and compare the MCP tools line. - Run
claude plugin details cloudflare@cloudflareto see the plugin’s component inventory and projected token cost. - In Codex, run
codex mcp listandcodex mcp remove <NAME>for any server this project does not need.
The Code Mode server stays small whatever the API grows to. Each domain server adds its own tool schemas, and the Observability server can chain many calls with large results. Connect domain servers per project, not globally.
How popular is Cloudflare MCP?
Section titled “How popular is Cloudflare MCP?”As of 2026-09-26 (GitHub API and marketplace files): cloudflare/mcp has 883 stars, cloudflare/mcp-server-cloudflare about 4.3k, and cloudflare/skills about 2.9k. The Code Mode server is in the Official MCP Registry as com.cloudflare.mcp/mcp. The plugin is in both claude-plugins-official and openai-curated. skills.sh lists roughly 825.6K installs for cloudflare/skills (secondary: search snippet seen 2026-09-26, not read directly).
What breaks when you use Cloudflare MCP?
Section titled “What breaks when you use Cloudflare MCP?”The sign-in hangs or never returns. A VPN, a proxy, or a browser extension blocks the OAuth callback to your machine. Retry in a clean browser profile. In Claude Code, claude mcp add --callback-port <PORT> fixes the callback port when your network only allows specific ports.
The agent sees the wrong Workers or no resources. The server is signed in to a different account, or the permissions you picked are too narrow. Sign out of the server (/mcp in Claude Code, codex mcp logout <NAME> in Codex), sign in again, and choose the right account and scopes.
Results end in --- TRUNCATED ---. The 6,000-token cap cut a broad query. Ask for a narrower window, a filter, or an aggregate instead of raw events. Turn off the cap only if your client bounds results itself.
“Claude’s response was interrupted”. Cloudflare’s README says this usually means the context limit was hit, most often on the Observability server with many chained calls. Split the question into smaller queries, and ask for aggregates first.
410 Gone on connect. The client still uses the legacy SSE transport against /sse. Change the URL to /mcp, or set the client’s transport to HTTP.
401 or 403 with a token. The token lacks a permission, uses Client IP Address Filtering, or is an account token without Account Resources : Read. Create a new token with the scopes the job needs.
A tool fails on a feature you do not pay for. Some features require a paid Workers plan. The error comes from the Cloudflare API, not from the MCP server.
The agent tries to change production. Code Mode’s execute can call any endpoint your permissions allow. In Claude Code, add the tool to the ask list in .claude/settings.json. The name depends on how you connected the server (checked in Claude Code 2.1.285): mcp__cloudflare__execute for a server you added by hand as cloudflare, and mcp__plugin_cloudflare_cloudflare__execute for the cloudflare plugin. If in doubt, run /mcp and copy the exact tool name it shows. In every tool, use read-only scopes for diagnosis. See MCP security for the full set of controls.
For client-side connection errors that are not specific to Cloudflare, see MCP connection issues.