Skip to content
Back to search

mcp

MCP server for the Cloudflare API

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/cloudflare/mcp with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/cloudflare/mcp'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/cloudflare--mcp/badge.svg)](/listings/cloudflare--mcp)

HTML

<a href="/listings/cloudflare--mcp"><img src="/api/listings/cloudflare--mcp/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 224 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. # Cloudflare MCP Server
  2. > A token-efficient MCP server for the entire Cloudflare API. 2500 endpoints in 1k tokens, powered by [Code Mode](https://blog.cloudflare.com/code-mode-mcp/).
  3. ## Token Comparison
  4. | Approach | Tools | Token cost | Context used (200K) |
  5. | ------------------------------------------- | ----- | ---------- | ------------------- |
  6. | Raw OpenAPI spec in prompt | — | ~2,000,000 | 977% |
  7. | Native MCP (full schemas) | 2,594 | 1,170,523 | 585% |
  8. | Native MCP (minimal — required params only) | 2,594 | 244,047 | 122% |
  9. | Code mode | 3 | ~1,100 | 0.5% |
  10. ## Get Started
  11. MCP URL: `https://mcp.cloudflare.com/mcp`
  12. ### Option 1: OAuth (Recommended)
  13. Just connect to the MCP server URL - you'll be redirected to Cloudflare to authorize and select permissions.
  14. #### Example JSON Configuration
  15. ```json
  16. {
  17. "mcpServers": {
  18. "cloudflare-api": {
  19. "type": "http",
  20. "url": "https://mcp.cloudflare.com/mcp"
  21. }
  22. }
  23. }
  24. ```
  25. ### Option 2: API Token
  26. For CI/CD, automation, or if you prefer managing tokens yourself.
  27. Create a [Cloudflare API token](https://dash.cloudflare.com/profile/api-tokens) with the permissions you need. Both **user tokens** and **account tokens** are supported. For account tokens, include the **Account Resources : Read** permission so the server can auto-detect your account ID.
  28. > **Note:** API tokens with **Client IP Address Filtering** enabled are not currently supported.
  29. ### Add to Agent
  30. | Setting | Value |
  31. | ------------ | --------------------------------------------------------------------------- |
  32. | MCP URL | `https://mcp.cloudflare.com/mcp` |
  33. | Bearer Token | Your [Cloudflare API Token](https://dash.cloudflare.com/profile/api-tokens) |
  34. ### Disable Code Mode
  35. If your MCP client already uses code mode, or you're composing this server with another server that uses code mode, you can disable it with the `?codemode=false` query parameter. This registers a tool for each Cloudflare API method instead of the code mode API tools, about 3,000, generated by [forge](https://github.com/cloudflare/forge). Each takes its arguments grouped by where they go: `{ path, query, headers, body }`. The `docs` and `whoami` tools remain available in both modes.
  36. ```
  37. https://mcp.cloudflare.com/mcp?codemode=false
  38. ```
  39. #### Example JSON Configuration
  40. ```json
  41. {
  42. "mcpServers": {
  43. "cloudflare-api": {
  44. "type": "http",
  45. "url": "https://mcp.cloudflare.com/mcp?codemode=false"
  46. }
  47. }
  48. }
  49. ```
  50. When code mode is disabled:
  51. - Each API endpoint is registered as its own tool (e.g., `get_workers_scripts`, `post_d1_database`)
  52. - Tool input schemas are derived from the endpoint's path parameters, query parameters, and request body
  53. - Tools make direct API calls — no code execution involved
  54. - Path parameters like `account_id` are auto-resolved when possible (single account)
  55. > **Note:** Disabling code mode significantly increases the token cost (~244k tokens vs ~1k tokens). Only disable it when necessary for composition with other code mode systems.
  56. ### Tool Result Truncation
  57. In code mode, the server caps each `search` and `execute` result at ~6,000 tokens, to avoid context overload. Oversized JSON stays valid JSON: long lists keep their first items whole, long strings are clipped, and every cut is marked with `--- TRUNCATED ---`. An agent that writes a result straight to a file or pipe, rather than reading it into the conversation, can pass `truncate: false` to that call to get the whole result.
  58. > **Note:** Without the cap, a broad query can return megabytes. Only turn it off when the result doesn't go to the model.
  59. With code mode disabled, the direct tools return whole results. The clients that disable it usually run code mode themselves: they call the direct tools from their own code and parse each result, so a capped result would lose data.
  60. ### Missing Permissions
  61. When Cloudflare refuses a call because the OAuth connection lacks a scope, the server asks the client to re-authorize with that scope added to the ones it already has. Claude and other clients that follow the [MCP authorization spec](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization#scope-challenge-handling) get a `403 insufficient_scope` challenge. Codex and ChatGPT get it in the tool result, which is where they look for it. Either way, the tool error says which scope is missing. Some endpoints, such as `GET /zones`, don't refuse: they answer with an empty list when the scope is missing. An empty list from a read the connection holds no accepted scope for is refused the same way, so it isn't mistaken for an empty account.
  62. ## The Problem
  63. The Cloudflare OpenAPI spec is **2 million tokens**. Even with native MCP tools using minimal schemas, it's still **~244k tokens**. Traditional MCP servers that expose every endpoint as a tool leak this entire context to the main agent.
  64. This server solves the problem by using **code execution** in a [Code Mode](https://blog.cloudflare.com/code-mode-mcp/) pattern - the spec lives on the server, and only the result of the code execution is returned to the agent.
  65. ## Tools
  66. Agent writes code to search the spec and execute API calls. It can also search Cloudflare's developer documentation directly.
  67. | Tool | Description |
  68. | --------- | ----------------------------------------------------------------------------- |
  69. | `docs` | Search Cloudflare developer documentation |
  70. | `search` | Write JavaScript to query `spec.paths` and find endpoints |
  71. | `execute` | Write JavaScript to call `cloudflare.request()` with the discovered endpoints |
  72. | `whoami` | Return the Cloudflare user or account this connection is authenticated as |
  73. ```
  74. Agent MCP Server
  75. │ │
  76. ├──search({code: "..."})───────►│ Execute code against spec.json
  77. │◄──[matching endpoints]────────│
  78. │ │
  79. ├──execute({code: "..."})──────►│ Execute code against Cloudflare API
  80. │◄──[API response]──────────────│
  81. ```
  82. `whoami` takes no arguments and returns `{ id, email }` for a user credential or `{ id, name }` for an account token. The `id` is `user:<user id>` or `account:<account id>`, so it stays the same across token refresh, reconnection and permission changes. Clients can use it to tell connected accounts apart; it is marked as an [OpenAI profile tool](https://developers.openai.com/plugins/build/auth#implement-and-declare-your-profile-tool).
  83. ## Skills
  84. The server also serves the [Cloudflare skills](https://github.com/cloudflare/skills) (Wrangler, Durable Objects, Agents SDK, Workers best practices and more) through the MCP [Skills extension](https://modelcontextprotocol.io/extensions/skills/overview). Clients that support it discover them with `skills/list` and read each file at `skill://<name>/<path>`. The catalog is synced from GitHub every six hours.
  85. ## Supported Products
  86. Workers, KV, R2, D1, Pages, DNS, Firewall, Load Balancers, Stream, Images, AI Gateway, Vectorize, Access, Gateway, and more. The server ships the OpenAPI document from a pinned [Forge](https://github.com/cloudflare/forge) release (`openapi.forge.json`), updated by pull request.
  87. ## Usage
  88. Once configured, just ask your agent to do things with Cloudflare:
  89. - "List all my Workers"
  90. - "Create a KV namespace called 'my-cache'"
  91. - "Add an A record for api.example.com pointing to 192.0.2.1"
  92. The agent will search for the right endpoints and execute the API calls. Here's what happens behind the scenes:
  93. ```javascript
  94. // 1. Search for endpoints
  95. search({
  96. code: `async () => {
  97. const results = [];
  98. for (const [path, methods] of Object.entries(spec.paths)) {
  99. for (const [method, op] of Object.entries(methods)) {
  100. if (op.tags?.some(t => t.toLowerCase() === 'workers')) {
  101. results.push({ method: method.toUpperCase(), path, summary: op.summary });
  102. }
  103. }
  104. }
  105. return results;
  106. }`,
  107. });
  108. // 2. Execute API call (user token - account_id required)
  109. execute({
  110. code: `async () => {
  111. const response = await cloudflare.request({
  112. method: "GET",
  113. path: \`/accounts/\${accountId}/workers/scripts\`
  114. });
  115. return response.result;
  116. }`,
  117. account_id: "your-account-id",
  118. });
  119. // 2. Execute API call (account token - account_id auto-detected)
  120. execute({
  121. code: `async () => {
  122. const response = await cloudflare.request({
  123. method: "GET",
  124. path: \`/accounts/\${accountId}/workers/scripts\`
  125. });
  126. return response.result;
  127. }`,
  128. });
  129. ```
  130. ### GraphQL Analytics API
  131. The server automatically detects and handles Cloudflare's GraphQL Analytics API endpoints. GraphQL queries work seamlessly through the same `execute` tool:
  132. ```javascript
  133. execute({
  134. code: `async () => {
  135. const response = await cloudflare.request({
  136. method: "POST",
  137. path: "/client/v4/graphql",
  138. body: {
  139. query: \`query {
  140. viewer {
  141. zones(filter: { zoneTag: "your-zone-id" }) {
  142. httpRequests1dGroups(limit: 7, orderBy: [date_ASC]) {
  143. dimensions {
  144. date
  145. }
  146. sum {
  147. requests
  148. bytes
  149. cachedBytes
  150. }
  151. }
  152. }
  153. }
  154. }\`,
  155. variables: {}
  156. }
  157. });
  158. return response.result;
  159. }`,
  160. account_id: "your-account-id",
  161. });
  162. ```
  163. ## Build a Code Mode MCP Server
  164. Code execution uses Cloudflare's [Dynamic Worker Loader API](https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/) to run generated code in isolated Workers, following the [Code Mode pattern](https://github.com/cloudflare/agents/tree/main/packages/codemode).
  165. Read the [Code Mode SDK docs](https://developers.cloudflare.com/agents/api-reference/codemode/) for more info.
  166. ### Resources
  167. - [Code Mode blog post](https://blog.cloudflare.com/code-mode/)
  168. - [Build your own remote MCP server](https://developers.cloudflare.com/agents/guides/remote-mcp-server/)
  169. - [Cloudflare's own MCP Servers](https://github.com/cloudflare/mcp-server-cloudflare)

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.