Skip to content

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 cloudflare plugin 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: /sse returning 410 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…ConnectWhy
Reach any Cloudflare product (Workers, KV, R2, D1, DNS, Access, and more) from one serverCode Mode, https://mcp.cloudflare.com/mcpThree tools cover the whole API, so context cost stays flat
Debug Workers logs and metrics with purpose-built queriesObservability, https://observability.mcp.cloudflare.com/mcpTyped tools for events, metrics, and field discovery
Manage KV, R2, D1, and Hyperdrive with named toolsWorkers Bindings, https://bindings.mcp.cloudflare.com/mcpOne tool per action, such as d1_database_query
Look up current Cloudflare docs onlyDocumentation, https://docs.mcp.cloudflare.com/mcpNo 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:

ServerURLUse it for
Documentationhttps://docs.mcp.cloudflare.com/mcpCurrent reference docs
Workers Bindingshttps://bindings.mcp.cloudflare.com/mcpWorkers, KV, R2, D1, and Hyperdrive
Workers Buildshttps://builds.mcp.cloudflare.com/mcpWorkers Builds history and insights
Observabilityhttps://observability.mcp.cloudflare.com/mcpWorkers logs and analytics
Containerhttps://containers.mcp.cloudflare.com/mcpA sandbox development environment
Browser Runhttps://browser.mcp.cloudflare.com/mcpFetch pages, convert them to Markdown, take screenshots
Logpushhttps://logs.mcp.cloudflare.com/mcpLogpush job health
AI Gatewayhttps://ai-gateway.mcp.cloudflare.com/mcpAI Gateway logs, prompts, and responses
AutoRAGhttps://autorag.mcp.cloudflare.com/mcpAutoRAG instances
DNS Analyticshttps://dns-analytics.mcp.cloudflare.com/mcpDNS performance and debugging
Digital Experience Monitoringhttps://dex.mcp.cloudflare.com/mcpApplication health for your organization
Cloudflare One CASBhttps://casb.mcp.cloudflare.com/mcpSaaS security misconfigurations
Radarhttps://radar.mcp.cloudflare.com/mcpInternet traffic insights
Cloudflare Bloghttps://blog.mcp.cloudflare.com/mcpBlog 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:

ToolWhat the agent does with it
searchWrites JavaScript that queries spec.paths to find the right endpoints
executeWrites JavaScript that calls cloudflare.request() against the endpoints it found
docsSearches 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=false only when your client bounds results itself. Without the cap, a broad query can fill the context window on its own.
  • Code Mode off. ?codemode=false registers one tool per endpoint (about 2,500 tools). Cloudflare recommends it only when you compose the server with another Code Mode system. The docs tool 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@cloudflare

The 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:

Terminal window
claude mcp add --transport http cloudflare https://mcp.cloudflare.com/mcp
claude mcp add --transport http cf-observability https://observability.mcp.cloudflare.com/mcp

Then run /mcp in a session and sign in to each server through the browser.

The first call to each server opens a Cloudflare sign-in page. There you choose the account and the permissions the server gets.

SituationUseWhy
Your own laptop, interactive workOAuthYou pick permissions at sign-in and never handle a secret
CI, scheduled jobs, headless agentsAPI token as a bearer tokenNo browser; scope the token to exactly what the job needs
Token restricted by Client IP Address FilteringNeither works yetCloudflare’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.

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.

  1. 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.

  2. Build. Paste the build prompt below. The wrangler skill loads on its own, because the request matches its trigger (Workers, D1, deploys).

  3. Verify locally. The agent runs npx wrangler d1 migrations apply <DATABASE> --local, your tests, and npx 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.

  4. Review. Ask the agent to review the migration and the Wrangler config with the workers-best-practices skill. Read the migration SQL yourself. It is the one file whose mistake you cannot roll back with a redeploy.

  5. 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.

  6. 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.

  7. Roll back if needed. npx wrangler rollback restores 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 /context before and after you connect a server and compare the MCP tools line.
  • Run claude plugin details cloudflare@cloudflare to see the plugin’s component inventory and projected token cost.
  • In Codex, run codex mcp list and codex 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.

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).

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.