Skip to content
Back to search

cloudflare-mcp

unofficial mcp server for cloudflare api

Safety scan

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

Checked today
Badge for your README
findsafeskills safety rating

Markdown

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

HTML

<a href="/listings/mattzcarey--cloudflare-mcp"><img src="/api/listings/mattzcarey--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 · 141 lines

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

  1. > [!WARNING]
  2. > This repository is a read-only archive and no longer maintained or deployed.
  3. > It is likely that none of the steps below will work.
  4. > Please see [cloudflare/mcp](https://github.com/cloudflare/mcp) for the official Cloudflare API MCP Server.
  5. # cloudflare-mcp
  6. > A smol MCP server for the complete Cloudflare API.
  7. [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/mattzcarey/cloudflare-mcp)
  8. Uses codemode to avoid dumping too much context to your agent.
  9. ## Get Started
  10. ### Create API Token
  11. Create a [Cloudflare API token](https://dash.cloudflare.com/profile/api-tokens) with the permissions you need.
  12. Both **user tokens** and **account tokens** are supported:
  13. | Token Type | Description | Requirements |
  14. |------------|-------------|--------------|
  15. | User Token | Created at user level, can access multiple accounts | Requires `account_id` parameter on each execute call |
  16. | Account Token | Scoped to single account | `account_id` auto-detected, no parameter needed |
  17. For account tokens, include the **Account Resources : Read** permission so the server can auto-detect your account ID.
  18. ## The Problem
  19. The Cloudflare OpenAPI spec is **2.3 million tokens** in JSON format. Even compressed to TypeScript endpoint summaries, it's still **~50k tokens**. Traditional MCP servers that expose every endpoint as a tool, or include the full spec in tool descriptions, leak this entire context to the main agent.
  20. This server solves the problem by using **code execution** in a [codemode](https://blog.cloudflare.com/code-mode/) pattern - the spec lives on the server, and only the results of queries are returned to the agent.
  21. ## Tools
  22. Two tools where the agent writes code to search the spec and execute API calls. Akin to [ACI.dev's MCP server](https://github.com/aipotheosis-labs/aci) but with added codemode.
  23. | Tool | Description |
  24. | --------- | ----------------------------------------------------------------------------- |
  25. | `search` | Write JavaScript to query `spec.paths` and find endpoints |
  26. | `execute` | Write JavaScript to call `cloudflare.request()` with the discovered endpoints |
  27. **Token usage:** Only search results and API responses are returned. The 6MB spec stays on the server.
  28. ```
  29. Agent MCP Server
  30. │ │
  31. ├──search({code: "..."})───────►│ Execute code against spec.json
  32. │◄──[matching endpoints]────────│
  33. │ │
  34. ├──execute({code: "..."})──────►│ Execute code against Cloudflare API
  35. │◄──[API response]──────────────│
  36. ```
  37. ## Supported Products
  38. Workers, KV, R2, D1, Pages, DNS, Firewall, Load Balancers, Stream, Images, AI Gateway, Vectorize, Access, Gateway, and more. See the full [Cloudflare API schemas](https://github.com/cloudflare/api-schemas).
  39. ## Usage
  40. Once configured, just ask your agent to do things with Cloudflare:
  41. - "List all my Workers"
  42. - "Create a KV namespace called 'my-cache'"
  43. - "Add an A record for api.example.com pointing to 192.0.2.1"
  44. The agent will search for the right endpoints and execute the API calls. Here's what happens behind the scenes:
  45. ```javascript
  46. // 1. Search for endpoints
  47. search({
  48. code: `async () => {
  49. const results = [];
  50. for (const [path, methods] of Object.entries(spec.paths)) {
  51. for (const [method, op] of Object.entries(methods)) {
  52. if (op.tags?.some(t => t.toLowerCase() === 'workers')) {
  53. results.push({ method: method.toUpperCase(), path, summary: op.summary });
  54. }
  55. }
  56. }
  57. return results;
  58. }`,
  59. });
  60. // 2. Execute API call (user token - account_id required)
  61. execute({
  62. code: `async () => {
  63. const response = await cloudflare.request({
  64. method: "GET",
  65. path: \`/accounts/\${accountId}/workers/scripts\`
  66. });
  67. return response.result;
  68. }`,
  69. account_id: "your-account-id",
  70. });
  71. // 2. Execute API call (account token - account_id auto-detected)
  72. execute({
  73. code: `async () => {
  74. const response = await cloudflare.request({
  75. method: "GET",
  76. path: \`/accounts/\${accountId}/workers/scripts\`
  77. });
  78. return response.result;
  79. }`,
  80. });
  81. ```
  82. ## Token Comparison
  83. | Content | Tokens |
  84. | ----------------------------- | ---------- |
  85. | Full OpenAPI spec (JSON) | ~2,352,000 |
  86. | Endpoint summary (TypeScript) | ~43,000 |
  87. | Typical search result | ~500 |
  88. | API response | varies |
  89. ## Architecture
  90. ```
  91. src/
  92. ├── index.ts # MCP server entry point
  93. ├── server.ts # Search + Execute tools
  94. ├── executor.ts # Isolated worker code execution
  95. ├── truncate.ts # Response truncation (10k token limit)
  96. └── data/
  97. ├── types.generated.ts # Generated endpoint types
  98. ├── spec.json # OpenAPI spec for search
  99. └── products.ts # Product list
  100. ```
  101. Code execution uses Cloudflare's Worker Loader API to run generated code in isolated workers, following the [codemode pattern](https://github.com/cloudflare/agents/tree/main/packages/codemode).
  102. ## Development
  103. ```bash
  104. npm i
  105. npm run deploy
  106. ```

Ratings and comments

Sign in to rate this skill.

Sign in

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