Why Your AI Agent Should Talk to Cloudflare, With Limits
Connect Claude Code to Cloudflare MCP with scoped permissions. Choose read access, control production changes, and verify access limits before relying on it.

On this page
- Give the agent visibility before giving it control
- Choose the Cloudflare MCP server that fits the job
- Connect Claude Code from your operations directory
- Restrict the credential to a specific resource
- Review the operation inside each tool call
- Verify both permitted and excluded access
- Approve a production change with a rollback ready
- Run a bounded DNS review today
- FAQ
The usual assumption is that connecting an AI agent to Cloudflare means handing it the account. It does not: the useful starting point is narrowly scoped read access. Connect Claude Code to an official Cloudflare MCP server, restrict the credential to the resources it needs, and verify those restrictions. Keep production writes behind explicit approval and a separate, temporary grant.
Give the agent visibility before giving it control
An agent with SSH access can inspect your application while remaining blind to the configuration that sends visitors to it. On a single VPS running Ubuntu 24.04 LTS, that gap matters when the application responds locally but the public hostname fails. Reading the relevant Cloudflare configuration gives Claude Code evidence it would otherwise ask you to copy from the dashboard.
We recommend starting with an investigation you already understand, such as checking whether a hostname points at the intended origin. Have the agent compare observed configuration with your deployment notes and identify discrepancies. It should explain what it found before proposing any change.
The connection is useful when dashboard lookups repeatedly interrupt your work. If you change DNS rarely and can answer the question from a short dashboard visit, adding another authenticated integration may not help. Our guide to delegating operations work explains how to choose work that benefits from agent access.
Choose the Cloudflare MCP server that fits the job
Model Context Protocol, or MCP, lets an agent discover and call tools exposed by another service. Cloudflare provides a documentation server and an authenticated API server, alongside servers for particular products. Choose from the official Cloudflare MCP catalog, because the endpoint determines what integration you are actually connecting.
| Your task | Connection to choose | Boundary to establish |
|---|---|---|
| Look up Cloudflare configuration guidance | Documentation MCP server | No account access needed for the task |
| Inspect your actual DNS configuration | Cloudflare API MCP server | DNS read permission for the selected zone |
| Make an approved DNS correction | API connection with temporary write access | Selected zone, reviewed operation, recorded rollback |
| Repeat a fixed deployment operation | Consider a reviewed script instead | Explicit inputs and a dedicated credential |
Reading documentation cannot establish what your account currently contains. Conversely, access to account configuration does not explain whether your application process is healthy. Keep those evidence sources separate when asking the agent to diagnose a failure.
For this setup, run Claude Code on your laptop and connect to Cloudflare's hosted endpoint. You do not need to host an MCP service on the VPS or open an inbound port for this connection. If the request path is unclear, first review where the reverse proxy and CDN sit.
Connect Claude Code from your operations directory
Start on a laptop where Claude Code is already installed and authenticated. Open your operations repository, then register the API server using local scope. In Claude Code, local scope makes the connection private to you and available in that project; it does not restrict Cloudflare permissions. The command syntax and scope behavior are documented in the Claude Code MCP reference.
claude mcp add --transport http --scope local cloudflare-api https://mcp.cloudflare.com/mcp
claude mcp get cloudflare-apiStart Claude Code in that directory and enter /mcp in its interactive prompt. Select the Cloudflare connection and follow the browser authentication flow. Inspect the requested permissions before authorizing; stop if the grant is broader than the investigation requires.
Treat the operations directory as a working convenience rather than a security boundary. A narrowly named connection can still hold broad credentials. The restriction that matters must survive an incorrect tool call.
Restrict the credential to a specific resource
For a DNS investigation, begin with DNS read access to the particular zone involved. A zone is the domain container for the DNS records you manage in Cloudflare. Avoid granting edit access simply because a setup template includes it.
Use OAuth when its authorization flow gives you the required boundary. If it cannot express that boundary, use a custom scoped API token through the server's supported bearer-token authentication, or leave account access disconnected. Do not compensate for an oversized grant by writing a stricter prompt.
Cloudflare API tokens support permission groups and resource restrictions, including DNS read access limited to a selected zone. Token expiration can limit how long a grant remains useful. Inspect the permission summary before creating it, following Cloudflare's token creation instructions.
- Choose the exact zone needed for the task instead of all zones.
- Grant read access initially; add another permission only after identifying the operation that requires it.
- Give the credential a purpose-specific name so you can find and revoke it later.
- Keep production write credentials out of the ordinary investigation session.
DNS edit access to a zone should be treated as authority over that zone's records, even when your request names only one hostname. If you require enforcement at the individual-record level, use a controlled wrapper that validates the target or perform the change yourself. A sentence in the task cannot narrow the provider's permission boundary.
Keep token values out of prompts and tracked configuration. Supply credentials through a protected local configuration mechanism, and remember that an agent with broad shell access may still read credentials accessible to that operating-system user. Plan storage and revocation together using the guide to scoped agent credentials.
Review the operation inside each tool call
The Cloudflare API server exposes search for discovering API operations and execute for running generated code that calls them. The same execution tool can support reads or writes, depending on the request and credential. Bearer-token authentication is supported, but tokens with client IP filtering are currently unsupported by this server. These details are documented in the official Cloudflare MCP project.
Our recommendation is to review the underlying request whenever a write-capable credential is present. Approving a tool name such as execute tells you little about the effect of the code inside it. Inspect the target resource and requested operation before allowing execution.
Do not permanently approve every execution call to remove interruptions. Keep routine diagnosis on a credential that cannot mutate production, then authorize a separate maintenance session when a reviewed change is necessary. This makes an accidental approval less consequential.
Treat text returned from tools as evidence rather than instructions. A record comment or other returned content should never authorize a permission expansion or a new destination for account data. Request only the fields needed to answer the operational question, especially when returned data could contain sensitive information.
Verify both permitted and excluded access
Ask Claude Code to read a known DNS record in the selected zone and report its configured target and proxy status. Compare the result with the dashboard yourself. Use a record whose expected configuration you already know so that an incorrect account selection is obvious.
Next, attempt a harmless read against another zone you control that is deliberately excluded from the credential. Use its known identifier rather than asking the agent to discover every accessible zone. Inspect the tool response directly; the agent declining your request does not demonstrate provider-side enforcement.
Inspect the credential's permission summary to confirm it contains no write grant. If you want an empirical write-denial check, use a disposable record in a nonproduction zone where an unexpectedly successful change is acceptable. Never attempt a destructive production operation merely to see whether it fails.
When a permitted read fails, inspect the requested operation and its documented permissions before changing the credential. Some failures come from the wrong resource identifier or an expired authorization. Broadening access until the error disappears can leave you with permissions unrelated to the original task.
Approve a production change with a rollback ready
Before granting write access, require a proposal that identifies the exact resource and shows its current and intended values. For a DNS correction, include the record type, target, TTL and proxy state so that unrelated settings do not change accidentally. Record the existing state somewhere you can reach without the agent.
- Review the proposed operation and decide how you will restore the previous configuration.
- Provide a separate, narrowly scoped write grant for the maintenance task.
- Approve the specific change after inspecting the actual request.
- Read back the resulting configuration and check application behavior independently.
- Revoke the temporary grant and return routine work to read access.
An accepted API request proves that a configuration operation was accepted; it does not prove visitors can use the application. DNS caching can also delay what different clients observe, including after a rollback. Keep an independent application check running while you assess the result.
Disconnecting an MCP server and revoking its provider credential are separate actions. When retiring access, revoke the token or application authorization in Cloudflare as appropriate, then clear the client connection. Keep ordinary dashboard access available so recovery does not depend on the same integration you are troubleshooting.
Run a bounded DNS review today
Choose one public hostname served by your VPS and write down its expected origin address. Connect the API server with read access to its zone, then ask Claude Code to compare the actual DNS record with that expectation. Require it to distinguish observed configuration from assumptions about application health.
Save the investigation task and its required permissions in your operations notes so the next session starts with a defined boundary. Pair the review with independent small-server monitoring, which can tell you whether the public application works regardless of what the agent reports. Leave write access disconnected until you have a concrete change to approve.
FAQ
What is a Cloudflare MCP server?
It is a service that exposes Cloudflare-related tools through Model Context Protocol. The distinction to check is whether the server provides reference material or authenticated access to your account. For operations work, choose the connection based on the evidence you need, then evaluate its credentials separately from the tools it advertises.
How do I connect a Cloudflare MCP server to Claude Code?
Register the official remote endpoint with claude mcp add, using HTTP transport, then complete authentication through /mcp inside Claude Code. Run the setup from your operations directory with local scope if the connection belongs to that project. Before investigating production, verify a known read and inspect the authorization granted to the connection.
Can I make Cloudflare MCP read-only?
You can constrain the underlying authorization to read permissions for the resources involved. The presence of a general execution tool does not require granting write access. Check the actual credential or OAuth grant, because naming a connection read-only or instructing the agent to avoid changes does not enforce that restriction.
Does Cloudflare MCP replace SSH access to my VPS?
No. Cloudflare account access cannot establish whether your application process is running correctly inside Ubuntu 24.04 LTS. You still need an appropriate way to inspect the origin when the evidence points there. We recommend granting each investigation only the access it needs, rather than attaching unrestricted server access to every Cloudflare session.
Should I use Cloudflare MCP or a script for DNS changes?
Use MCP when the task involves investigating an unfamiliar configuration and deciding what evidence to collect next. Prefer a reviewed script when the operation is fixed and repeated, with known inputs and expected results. Either approach needs scoped credentials, but a fixed script usually gives you a smaller change to review for routine maintenance.
Put this guide in the bigger picture
See how this topic connects to the rest of your product. Our free field guide explains apps, infrastructure and AI, with checklists to help you make business decisions.






