跳到正文

Cloudflare MCP Server

活跃
cloudflare/mcp

让 AI 智能体访问完整 Cloudflare API(约 2,500 个端点)的 MCP 服务器,借助 Code Mode 仅需约 1,000 个 token。

在 GitHub 查看
星标
936
Fork
126
关注
936
未关闭 Issue
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.

按共同分类和标签排序的同类开源项目。

全部 AI 项目 →