Cloudflare MCP Server & CLI

A free, open source Cloudflare MCP server and CLI that lets Claude Code, Codex, Cursor and other AI agents manage your DNS records, clear the cache and change domain settings.

Navid Moazzezby Navid Moazzez·Updated Oct 5, 2026·14 min read·
Your computer
  1. 1

    Add it with a single command in a terminal.

    Put your own API token in place of the example.

    claude mcp add cloudflare \
    -e CLOUDFLARE_API_TOKEN=YOUR_API_TOKEN \
    -- npx -y @thenavidm/cloudflare-mcp-cli@latest
  2. 2

    In Claude Code, type /mcp. Cloudflare should show as connected.

    /mcp

Needs Node 22 or newer and a Cloudflare API token. Make one in two minutes.

It's free and open source. If it saves you time, star it on GitHub, so more people find it.

Rate this tool

This free Cloudflare MCP server and CLI gives your AI real access to your Cloudflare account: domains, DNS records, cache, domain settings, rulesets and analytics. It reads and changes DNS records, clears the cache, reads and changes domain settings and rulesets, lists your Workers and runs analytics queries.

It's one install with two ways in. Claude, Codex, Cursor or any other MCP app calls its 29 tools for you, and the same tools work as a CLI that agents like Claude Code, Codex and OpenCode run, or that you type yourself.

In this guide, I'll show you:

  • What the Cloudflare MCP server & CLI is, and what you can ask it
  • How to install it and check that it works
  • When to use the MCP server, and when the CLI
  • Every tool, and how to keep your account safe

Every tool on this page comes from the server itself, and every cost was measured in Claude Code.

key_takeaways.mdTL;DR

Key takeaways

It gives Claude, Codex, Cursor and any other MCP app 29 tools for Cloudflare: your domains, DNS records, cache, domain settings, rulesets, Workers list and analytics.
It works with an API token you limit to the domains and permissions you choose, never your Global API Key.
Every DNS change, cache purge, setting change and ruleset change waits for your approval.
The same tools run as a CLI, which costs your AI nothing until it runs.

What is the Cloudflare MCP server & CLI?

The Cloudflare MCP server & CLI is a free, open source program that lets AI agents manage your Cloudflare domains for you, in two ways. The MCP server is what an AI app like Claude, Codex or Cursor connects to, through MCP (Model Context Protocol), the open standard AI apps use to call outside tools.

You ask in plain language. Your AI picks the right tool, and the server makes the call to Cloudflare's own API.

The CLI is the same program as commands. cloudflare-cli list-dns-records runs the same code your AI runs when you ask for a domain's DNS records, whether an agent like Claude Code runs it or you do.

In an AI OS, the layer that connects your AI to your context, your data and your tools, a server like this is how your AI reaches Cloudflare. I explain how the parts fit together in how to build an AI operating system, and here's how I use AI myself.

What can you ask it?

Once it's set up, you ask the way you'd ask an assistant. These are real prompts it handles:

Try asking
List the DNS records for example.com, and tell me which ones are proxied.
Add the TXT record Google Search Console gave me for example.com.
Point blog.example.com at my new server's IP, without the proxy.
Clear the cache for my homepage and my pricing page.
Which SSL mode is example.com using?
How many requests did example.com get in the last 24 hours?

The second one shows why this is useful. Your AI adds the exact record Google asks for, and you approve it before it goes live, without hunting for the right screen in the dashboard.

It works well next to my WordPress MCP server and Google Search Console MCP server, so your AI can update the WordPress sites behind your domains and see how those sites do in Google in the same chat. Every server I've made is on my MCP servers page.

For the rest of your site, my free domain checker and SPF record generator help too. I compare building your own site on Cloudflare with the alternatives in the best website builders.

How to install the Cloudflare MCP server

Pick your app in the box at the top of this page. Each one is a single command or a pasted block, and they all run through npx, so there's nothing to install first.

Windsurf, Zed and Cline take the same server, though they don't have a tab in the box yet. Follow the box's Cursor tab, and put its block here instead:

AppWhere the block goes
WindsurfIn the Cascade panel, open the Actions menu (…) and choose Open MCP config file, then paste the block.
ClineClick the MCP Servers icon in the Cline panel, open the Configure tab, click Configure MCP Servers, and paste the block.
ZedGo to Settings, then AI, then MCP Servers, and choose Add Server, then Add Local Server. Enter the block's command, arguments and variables, and Zed saves them under context_servers.
Before you start0/3

Watch out: Use an API token, never your Global API Key. A token can be limited to the domains and permissions you pick, and the server only accepts tokens.

Set up your Cloudflare account

It takes two minutes.

Create an API token0/5

These are the permissions each kind of work needs:

What you wantPermission to add
Read domains and DNS recordsZone: Read and DNS: Read
Change DNS recordsDNS: Edit
Clear the cacheCache Purge
Read or change domain settingsZone Settings: Read or Edit
Read your Workers listWorkers Scripts: Read
Run analytics queriesAnalytics: Read

An account-owned token, made under Manage Account and then API Tokens, works too. Set CLOUDFLARE_TOKEN_KIND to account and CLOUDFLARE_ACCOUNT_ID to your account ID, so the doctor checks it the right way.

CLOUDFLARE_ZONE_ID and CLOUDFLARE_ACCOUNT_ID are optional defaults, so you don't have to name the domain every time. They don't limit what the token can reach, because the token's own settings do that.

To keep the token out of your app's config, save it alone in a file only you can read, and point CLOUDFLARE_TOKEN_FILE at that file's full path instead.

Check that it works

Run the doctor with --network. It checks your settings, then asks Cloudflare whether the token is active, without reading or changing a domain.

npx -y @thenavidm/cloudflare-mcp-cli doctor --network

When every line has a check mark, restart your app and ask it to list your domains. If the token is active but a domain read fails, the token doesn't include that domain or that permission.

In Claude Code, /mcp also shows whether the Cloudflare server is connected. It's one of the Claude Code commands worth knowing.

Use the Cloudflare CLI

The CLI is the same 29 tools as commands. AI agents that run commands, like Claude Code, Codex and OpenCode, use it on their own, and you can type the same commands in a terminal or a script.

Every tool name becomes a command with dashes, so list_dns_records runs as cloudflare-cli list-dns-records.

npm install -g @thenavidm/cloudflare-mcp-cli
cloudflare-cli
cloudflare-cli list-zones --per-page 10
cloudflare-cli list-dns-records --zone-id YOUR_ZONE_ID --type TXT
cloudflare-cli get-zone-setting --zone-id YOUR_ZONE_ID --setting-id ssl
cloudflare-cli purge-cache --zone-id YOUR_ZONE_ID --payload '{"files":["https://example.com/pricing"]}' --confirm

The bare cloudflare-cli lists every command, cloudflare-cli which <words> finds the command for a task, and cloudflare-cli <command> --help shows what a command takes. DNS changes, cache purges, setting changes and ruleset changes need --confirm, the terminal's version of your approval.

cloudflare-cli install <app> adds the server to Claude Code, Codex, Claude Desktop, Cursor, VS Code or Gemini CLI, in each app's own format.

These are the flags you'll use most:

FlagWhat it does
--jsonPrints JSON
--compactPrints the JSON on one line
--select a,b.cKeeps only those fields, and a dotted path goes deeper
--agentMachine mode: compact JSON, no prompts, and it never confirms anything
--confirmLets a write that asks first go ahead
--dry-runShows what a write would do, without doing it

A script can branch on the exit code:

Exit codeWhat it means
0It worked
1Something unexpected went wrong
2The command was typed wrong, or a write needed --confirm
3It wasn't found
4Cloudflare rejected the credentials
5Cloudflare failed or couldn't be reached
7You hit a rate limit, so wait and try again
10Nothing is set up yet

MCP server or CLI: which one?

Both are the same program with the same 29 tools. The difference is when your AI pays for them, in the tokens it reads.

Every message, in an app that loads every tool
MCP server
144,100 tokens
CLI
Nothing
Every message, in Claude Code
MCP server
610 tokens
CLI
Nothing
When Cloudflare comes up
MCP server
Nothing more, or in Claude Code the tools it picks
CLI
4,000 tokens, once
20 messages with Cloudflare in one, every tool loaded
MCP server
2,881,000 tokens
CLI
4,000 tokens
Works in Claude Desktop's chat
MCP server
Yes
CLI
No, there's no terminal there
Works in a script, a cron job or CI
MCP server
No
CLI
Yes

An app that loads every tool up front sends the full list with every message, whether you mention Cloudflare or not. Claude Code doesn't by default: its tool search sends only the tool names and the server's instructions, and loads a tool's full definition when your AI reaches for it.

The CLI costs nothing until Cloudflare comes up. Then your agent reads its skill file once and runs the commands it needs. With the skill added, Claude Code also lists its one-line description with every message, about 60 tokens.

When the whole conversation is about Cloudflare, the gap closes. Then the MCP server is the better experience, because you ask in plain language and your AI never has to look up a command.

How to spend less

In Claude Code, leave tool search on, which it is unless you've set ENABLE_TOOL_SEARCH=false.

Turn the server off when you aren't working on your domains. In Claude Code that's the /mcp panel, and every AI app has its own switch. CLOUDFLARE_READ_ONLY=1 cuts it to the 18 reading tools.

Or install the CLI and connect the server later, on the days it earns its place. Every tool stays in reach, and the standing cost drops to nothing.

Every number here was measured on October 5, 2026 in Claude Code 2.1.286 with Claude Opus 5.5. It's the same one-line prompt with and without the server connected, once with tool search off so every tool loads, and once with Claude Code's default. The skill was measured the same way, and other apps and models count tokens a little differently.

Change DNS and the cache safely

Before a change, your AI reads the domain and the record, so it knows exactly what it's changing. update_dns_record changes only the fields you name, and overwrite_dns_record replaces the whole record, so a field you leave out goes back to its default.

For several changes at once, preview_dns_batch checks up to 50 of them on your computer and gives the batch a fingerprint. apply_dns_batch sends them only with that same fingerprint. Cloudflare applies a batch all together or not at all, though DNS around the world still takes a little while to catch up.

purge_cache clears cached files by URL, cache tag, hostname, URL prefix or the whole domain. A success means Cloudflare took the request, and the next visit to a cleared page shows MISS in its CF-Cache-Status header.

Rulesets are where redirects, custom rules and header changes live now. Your AI reads them, and changes them only with your approval. Old Page Rules can be read, to plan a move to rulesets, but not changed.

Watch out: This server doesn't deploy Workers or touch their code. It lists your Workers scripts, and Wrangler is still the tool for deploying them.

Every Cloudflare tool

The tables below list all 29 tools, grouped by what they're for. Of these, 18 only read, and 11 change something in your Cloudflare account.

Domains and settings

list_provider_accounts
What it does
Lists the Cloudflare accounts your token can reach.
Kind
Reads
list_zones
What it does
Lists your domains, with search and filters.
Kind
Reads
get_zone
What it does
Reads one domain's status, nameservers and details.
Kind
Reads
get_zone_setting
What it does
Reads one domain setting, like the SSL mode.
Kind
Reads
update_zone_setting
What it does
Changes one domain setting.
Kind
Asks first

DNS records

list_dns_records
What it does
Lists a domain's DNS records, with search and filters.
Kind
Reads
get_dns_record
What it does
Reads one DNS record.
Kind
Reads
create_dns_record
What it does
Adds a DNS record.
Kind
Asks first
update_dns_record
What it does
Changes the fields you name on a DNS record.
Kind
Asks first
overwrite_dns_record
What it does
Replaces a DNS record completely.
Kind
Asks first
delete_dns_record
What it does
Deletes a DNS record.
Kind
Asks first
batch_dns_records
What it does
Sends several DNS changes in one request, without a review fingerprint.
Kind
Asks first
preview_dns_batch
What it does
Checks up to 50 DNS changes on your computer and gives the batch a fingerprint.
Kind
Reads
apply_dns_batch
What it does
Sends a checked DNS batch, only with the fingerprint from its preview.
Kind
Asks first

Cache

purge_cache
What it does
Clears cached files by URL, tag, hostname, prefix or the whole domain.
Kind
Asks first

Rulesets and Page Rules

list_zone_rulesets
What it does
Lists a domain's rulesets.
Kind
Reads
get_zone_ruleset
What it does
Reads one ruleset in full.
Kind
Reads
get_zone_entrypoint
What it does
Reads a domain's main ruleset for one phase, like redirects or custom rules.
Kind
Reads
create_zone_ruleset
What it does
Makes a new ruleset.
Kind
Asks first
update_zone_ruleset
What it does
Changes a ruleset, as a new version.
Kind
Asks first
delete_zone_ruleset
What it does
Deletes a ruleset and all its versions.
Kind
Asks first
list_page_rules
What it does
Lists a domain's old Page Rules.
Kind
Reads
get_page_rule
What it does
Reads one Page Rule.
Kind
Reads

Workers and analytics

list_workers
What it does
Lists your Workers scripts, without their code.
Kind
Reads
analytics_query
What it does
Runs one read-only GraphQL analytics query.
Kind
Reads

Your accounts and requests

list_accounts
What it does
Lists the accounts you've set up, without their tokens.
Kind
Reads
get_operation_schema
What it does
Shows every field Cloudflare accepts for one of these requests.
Kind
Reads
preview_operation
What it does
Checks a request on your computer, before anything goes to Cloudflare.
Kind
Reads
query_pages
What it does
Reads up to five pages of accounts, domains or DNS records at once.
Kind
Reads

Is the Cloudflare MCP server safe?

A DNS change can take a site or its email offline, and a purge sends every visitor back to your server for a moment. So 11 tools ask first: every DNS change, cache purge, setting change and ruleset change. They're the ones marked "Asks first" in the tool tables above.

The token is the real limit, though. Give it only the domains and permissions your work needs, and the server can't reach anything else.

When your AI calls one of them, the call needs a yes first. Where you use it decides who gives it:

  • Claude Code (2.1.246 and later) asks you before every call, in every one of its permission modes.
  • An app that can show forms asks you in a form.
  • Any other app takes your AI's confirm: true as the yes, so tell your AI to check with you first.
  • An agent with no person to ask needs CLOUDFLARE_CONFIRM=model, so its confirm: true counts in every app.
  • In a terminal, you add --confirm to the command.

If the answer is no, nothing reaches Cloudflare.

Make it read-only

Set CLOUDFLARE_READ_ONLY=1 and every tool that asks first disappears from the tool list, leaving 18 reading tools. A token with only Read permissions does the same at Cloudflare's end.

Keep a log of every write

Set CLOUDFLARE_AUDIT_LOG to a file path. The server writes one line per attempted write, allowed or blocked, with what it was about to do and who approved it.

Watch out: DNS TXT records and rule descriptions can be written by other people, and one can try to give your AI orders. Treat them as data, and use CLOUDFLARE_READ_ONLY=1 for an agent working on its own.

Your data

Your requests go straight to Cloudflare, with no server of ours in between and no tracking. Your token stays in your app's config, your shell or your token file.

DNS records and analytics can show private details about your sites, so keep anything you export out of public places.

To cut access, delete the token in My Profile, then API Tokens, and remove the server from your app's config.

Connect more than one Cloudflare account

Set CLOUDFLARE_ACCOUNTS to a JSON list with a name and a token, or a token file, for each account, plus an account ID, a zone ID and the token kind where you want them. CLOUDFLARE_DEFAULT_ACCOUNT picks the one that acts when a tool names none, and every tool takes an optional account.

An account never borrows another one's token, so a client's domains stay with the client's token.

Cloudflare MCP server settings

Every setting is an environment variable, in your app's config or your shell.

CLOUDFLARE_API_TOKEN
Default
none
What it does
Holds your API token
CLOUDFLARE_TOKEN_FILE
Default
none
What it does
Points at a private file holding the token, instead
CLOUDFLARE_ACCOUNTS
Default
none
What it does
Lists several accounts, as JSON
CLOUDFLARE_DEFAULT_ACCOUNT
Default
the first one
What it does
Picks the account that acts when a tool names none
CLOUDFLARE_ACCOUNT_ID
Default
none
What it does
Fills in your account ID when a tool needs one and you don't name it
CLOUDFLARE_ZONE_ID
Default
none
What it does
Fills in a domain's zone ID when you don't name one
CLOUDFLARE_TOKEN_KIND
Default
user
What it does
account makes the doctor check an account-owned token
CLOUDFLARE_REQUEST_TIMEOUT_MS
Default
30000
What it does
Gives up on a Cloudflare request after this many milliseconds
CLOUDFLARE_MIN_REQUEST_INTERVAL_MS
Default
200
What it does
Waits this many milliseconds between requests
CLOUDFLARE_READ_ONLY
Default
off
What it does
1 hides every tool that changes something
CLOUDFLARE_ALLOW_DESTRUCTIVE
Default
on
What it does
0 refuses the tools that ask first
CLOUDFLARE_AUDIT_LOG
Default
none
What it does
Names a file that gets one line per attempted write
CLOUDFLARE_SURFACE
Default
full
What it does
search lists three tools that find, describe and run the rest
CLOUDFLARE_TOOL_TIMEOUT_MS
Default
none
What it does
Gives up on any tool after this many milliseconds
CLOUDFLARE_CONFIRM
Default
human
What it does
model lets your AI's confirm: true approve on its own, for an agent with no person to ask
CLOUDFLARE_HTTP_PORT
Default
8787
What it does
Sets the port for --http
CLOUDFLARE_HTTP_HOST
Default
127.0.0.1
What it does
Sets the address for --http, and any other needs a token
CLOUDFLARE_HTTP_TOKEN
Default
none
What it does
Sets the bearer token every --http request needs
CLOUDFLARE_HTTP_ALLOWED_ORIGINS
Default
none
What it does
Lists other websites allowed to call --http, comma separated
CLOUDFLARE_DEBUG
Default
off
What it does
1 prints debug lines

Troubleshooting

Run the doctor first. It names the step that failed and the fix.

What you seeWhat to do
The doctor says the token isn't activeIt expired, or an IP filter blocks you. For an account-owned token, set CLOUDFLARE_TOKEN_KIND=account and your account ID
The token works, but a domain read failsThe token doesn't include that domain or that permission. Edit it in My Profile, then API Tokens
Cloudflare refuses a DNS changeSome records can't share a name, like an A record and a CNAME. Read the error and check the record type
A setting or rule won't changeYour plan may not include it. Read the setting first, and check that it can be edited
A 429 errorCloudflare allows 1,200 requests every 5 minutes per token. Wait, then check before you try again
Analytics come back emptyCheck the dataset, the time window and how long your plan keeps data. Some analytics are sampled
"…so it will not run without confirm: true"That's the safety check working. Approve it when your app asks

If the server doesn't show up in your app at all, run the command your app runs, in a terminal, and read the error.

FAQs about the Cloudflare MCP server & CLI

Here are the questions people ask most about the Cloudflare MCP server and CLI.

The Cloudflare MCP server & CLI is a free, open source program that lets an AI app like Claude, Codex or Cursor manage your Cloudflare domains.

It has 29 tools for domains, DNS records, cache, settings, rulesets, Workers and analytics, and the same tools run as a CLI that agents like Claude Code and Codex use, or that you type yourself.

An MCP server is a standard way to give an AI app real access to a tool, so it can act instead of guessing.

MCP stands for Model Context Protocol, and Claude, Codex, Cursor and many other AI apps speak it.

Every server I've made is on my MCP servers page.

The Cloudflare CLI is the same program as the Cloudflare MCP server, run as commands.

AI agents like Claude Code, Codex and OpenCode run them for you, and you can type them in a terminal or a script.

One npm package installs both.

Use the Cloudflare MCP server in an AI app with no terminal, like Claude Desktop's chat, and the CLI in a terminal, a script or a cron job.

In an AI app that can run commands, like Claude Code, Codex or Cursor, the CLI is the lighter choice, because it costs nothing until it runs.

Yes, the Cloudflare MCP server is free and open source under the AGPL-3.0-or-later license.

Cloudflare's API comes with every Cloudflare account, and what you can change depends on your plan.

Give the token only what your work needs: Zone: Read and DNS: Read to look around, DNS: Edit to change records, and Cache Purge to clear the cache.

Limit it to the domains you want it to reach.

No, the server only accepts API tokens.

A token can be limited to certain domains and permissions, and the Global API Key can't.

No, it only lists your Workers scripts.

Deploying them is still a job for Wrangler, Cloudflare's own CLI.

Yes, the Cloudflare MCP server connects as many accounts as you set up in CLOUDFLARE_ACCOUNTS, each with its own token.

Every tool takes an optional account, and an account never borrows another one's token.

To disconnect the Cloudflare MCP server, delete its token in My Profile, then API Tokens, which cuts access right away.

Then remove the server from your AI app's config.

The Cloudflare MCP server works with any app that speaks MCP.

That includes Claude Code, Claude Desktop, Codex, Cursor, VS Code, Windsurf, Zed, Cline, GitHub Copilot CLI, Gemini CLI, OpenCode, OpenClaw, Antigravity and Hermes.

I did.

I'm Navid Moazzez, and I made the Cloudflare MCP server & CLI as one of my free tools on navid.me.

You can read more about me.

The code is on GitHub under the AGPL-3.0-or-later license, and the package is on npm.

More MCP servers & CLIs

Related free tools

Navid Moazzez

AI business strategist

Navid Moazzez helps creators and founders master AI and build their own AI Operating System (AI OS) to automate their business and life.

Navid.me is reader-supported. When you buy through links on this site, I may earn an affiliate commission. Read the affiliate disclaimer.

Free AI newsletter

The most actionable AI newsletter for founders

Every week, get proven AI strategies, curated tools, and step-by-step systems to grow your audience, create better content, and build a profitable creator business.

No fluff, no filler, no BS. Just five minutes each week that might level up your online business and life.

P.S. Sign up now to get free access to my ultimate AI tools guide for creators.

Loved by 10,000+ readers
Loved by 10,000+ readers