← All prompt collections
The full post, ready to copy
Cloudflare Code Mode: An Entire API in 1,000 Tokens
Slide 1
Cloudflare's post: "Code Mode: give agents an entire API in 1,000 tokens" (blog.cloudflare.com/code-mode-mcp).
The problem: with normal MCP, every tool's full description is loaded into the model's context, and every tool call is a round trip back to the model. Big APIs blow up your context before the agent does any work.
The fix: instead of thousands of tools, the server exposes just two: search() (search the API spec) and execute() (run code against the API). The model writes one piece of code that chains all the calls, handles paging and checks responses, and that code runs in a locked-down sandbox (a Dynamic Worker isolate with no file system and outside network access off by default). Only the result comes back to the model.
Slide 2
Cloudflare API, 2,500+ endpoints:
- Raw OpenAPI spec in the prompt: ~2,000,000 tokens
- Native MCP, full schemas: 2,594 tools, 1,170,523 tokens (585% of a 200k context window)
- Native MCP, required params only: 2,594 tools, 244,047 tokens
- Code Mode: 2 tools, 1,069 tokens (0.5%)
That's about 99.9% fewer input tokens, and the footprint stays the same however many endpoints the API has.
Slide 3
Cloudflare's Code Mode MCP server for its whole API:
https://mcp.cloudflare.com/mcp
Add it to Claude Code:
claude mcp add --transport http cloudflare-api https://mcp.cloudflare.com/mcp
Or in any MCP client config:
{"mcpServers": {"cloudflare-api": {"url": "https://mcp.cloudflare.com/mcp"}}}
The first time you use it, you're sent to Cloudflare to sign in and choose which permissions the agent gets. Start with read-only. For CI, you can use a Cloudflare API token as a bearer token instead.
Slide 4
- List all my Workers and when each was last deployed.
- Show every DNS record for my main domain and flag anything that looks unused.
- Which of my zones don't have "Always use HTTPS" turned on?
- Summarise my R2 buckets: name, size and object count.
- Find any Workers routes that point to a Worker that no longer exists.
Keep it on read-only access until you trust what it's doing.
Slide 5
Anthropic's version is called programmatic tool calling (stable in the Claude API). Claude writes code that calls your tools inside the code execution container, instead of a round trip through the model for every call.
How to turn it on:
1. Add the code execution tool: {"type": "code_execution_20260120", "name": "code_execution"}
2. On each of your tools, add: "allowed_callers": ["code_execution_20260120"]
Docs and full example: platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling
Building your own server? Cloudflare's Code Mode SDK is open source: github.com/cloudflare/agents (packages/codemode).
Slide 6
Block's open-source agent goose has Code Mode built in (since v1.17.0).
- Desktop app: click the extensions icon and turn on "Code Mode".
- CLI: run goose configure and enable the Code Mode extension.
It works with the MCP extensions you already have, so your tools stay the same.