Workstation terminal securely connected to a cloud network control panel

Cloudflare runs an MCP server that gives an AI agent access to its entire API, more than 2,500 endpoints across DNS, Workers, R2, Zero Trust and WAF, through just two tools and roughly 1,000 tokens of context. The technique, called Code Mode, was introduced in February 2026, and its SDK ships as part of Cloudflare’s open-source Agents SDK. For system administrators, the interesting question is less how it works than how far an agent should be allowed to touch production configuration.

Key points of Cloudflare’s Code Mode MCP server in 20 seconds

  • What: an MCP server at mcp.cloudflare.com exposing only search() and execute().
  • Why it matters: about 1,000 tokens instead of 1.17 million with one tool per endpoint.
  • Access: OAuth 2.1 with user-approved scopes, or your own API token as a bearer token.

The classic MCP approach is one tool per operation. For the Cloudflare API that would mean, according to its documentation, 2,594 tools and about 1.17 million tokens with full schemas, or around 244,000 with required parameters only. Code Mode flips this around: the model writes JavaScript to search the OpenAPI specification with search() and to call the API with execute(). Our Spanish sister site has a broader look at Code Mode on Noticias.ai; here we focus on day-to-day use.

Connecting it to an MCP client

The server works with any MCP client that supports remote servers, from coding agents to desktop assistants. The minimal configuration Cloudflare documents is:

{
  "mcpServers": {
    "cloudflare-api": {
      "url": "https://mcp.cloudflare.com/mcp"
    }
  }
}Code language: JSON / JSON with Comments (json)

On first connection the server starts an OAuth 2.1 flow and the user chooses which permissions to grant; the resulting token is limited to those scopes. For CI/CD pipelines or self-managed credentials, a user or account API token can be sent as a bearer token in the Authorization header. In that case, create a dedicated token for the agent, scoped to the right account and zones, with only the permissions it needs.

What the agent does, and where the code runs

Asked to review the WAF rules on a zone, the agent first calls search() with a short snippet that filters the spec by product, path or tag and returns only the relevant operations. It then uses execute() to chain the calls, handle pagination and check responses in a single run. The full specification never enters the model’s context.

That code does not run on your machine. It runs in a V8 isolate on Workers with no file system, no environment variables and outbound requests disabled by default. That is solid containment against prompt injection, but it does not limit what the API lets the agent do with the token it was given.

Good practice before granting access

  • Start read-only: DNS audits, rule reviews and Workers inventories do not need write access.
  • Separate environments: one token for a test account or zone, a tighter one for production.
  • Review before applying: ask the agent to show its execute() code and planned changes before it edits DNS, WAF or Zero Trust.
  • Keep a trail: use the account audit log to see what the agent changed and when.
  • Rotate and revoke: give tokens an expiry and revoke them immediately if the client or workstation is compromised.

If you want the same pattern for your own API, the Code Mode SDK lives in the cloudflare/agents repository under the MIT licence, alongside the rest of the Agents SDK for building stateful agents on Durable Objects.

Frequently asked questions

What is the URL of the Cloudflare API MCP server?

https://mcp.cloudflare.com/mcp, added as a remote server in your MCP client.

Can I use an API token instead of OAuth?

Yes. A user or account token can be sent as a bearer token in the Authorization header, which suits CI/CD.

Where does the agent’s code run?

In a V8 isolate on Cloudflare Workers, with no file system, no environment variables and no outbound internet access by default.

Sources:

Scroll to Top