Skip to content

Cloudflare MCP Server

Active
cloudflare/mcp

MCP server that gives AI agents the entire Cloudflare API — about 2,500 endpoints — in roughly 1,000 tokens using Code Mode.

View on GitHub
Stars
936
Forks
126
Watchers
936
Open issues
34

Overview

The Cloudflare MCP Server gives AI agents access to the entire Cloudflare API — roughly 2,500 endpoints — through the Model Context Protocol, while using only about 1,000 tokens of context. It achieves this with Cloudflare’s “Code Mode” pattern: instead of exposing every endpoint as a separate tool, the agent writes small pieces of code that search the API spec and execute calls on the server.

Why Code Mode Matters

The full Cloudflare OpenAPI spec is about 2 million tokens. Even a minimal MCP tool per endpoint costs around 244,000 tokens — more than most context windows. Code Mode keeps the spec on the server and returns only the results, so the agent’s context stays small.

Approach Tools Approx. token cost
Raw OpenAPI spec in the prompt — ~2,000,000
Native MCP, minimal schemas ~2,600 ~244,000
Code Mode 3 ~1,100

Tools

Tool What it does
docs Searches Cloudflare’s developer documentation
search Runs JavaScript against the API spec to find endpoints
execute Runs JavaScript that calls the discovered endpoints
whoami Shows which user or account the connection is authenticated as

Getting Started

Add the hosted server to any MCP-compatible client:

{
  "mcpServers": {
    "cloudflare-api": {
      "type": "http",
      "url": "https://mcp.cloudflare.com/mcp"
    }
  }
}
  • OAuth (recommended): connect and you are redirected to Cloudflare to authorize and choose permissions.
  • API token: for CI/CD and automation, pass a Cloudflare API token as a bearer token (user and account tokens are both supported).

Options

  • ?codemode=false registers one tool per endpoint, for clients that already implement Code Mode themselves (much higher token cost).
  • ?truncateToolResult=false disables the default ~6,000-token cap on each tool result, for clients that bound results on their own.

Use Cases

  • Let a coding agent configure DNS, Workers, R2, or WAF rules in plain language
  • Automate account audits and reporting across many zones
  • Combine Cloudflare operations with other MCP servers in one agent

License

Apache License 2.0.

Similar open-source projects, ranked by shared categories and tags.

All AI projects →