Cloudflare has introduced a major evolution in how AI agents access complex APIs by launching a new Model Context Protocol (MCP) server powered by Code Mode, dramatically reducing the cost of interacting with its full API platform. The new approach highlights a new way for agent‑to‑tool integrations in the MCP ecosystem.
At its core, MCP is an emerging standard that lets large language models (LLMs) interface with external tools and APIs by exposing structured tools the model can call during execution. Traditionally, each API endpoint exposed to an agent represented a separate tool definition. While straightforward, this model incurs a significant context window cost every time a tool specification consumes tokens in the model’s limited input budget, leaving less room for reasoning about the user’s task.
Luuk Hofman, Solutions Engineer at Cloudflare, noted:
So we tried: convert MCP tools into a TypeScript API and just ask the LLM to write code against it.
Cloudflare’s Code Mode instead exposes only two tools, search() and execute(), backed by a type‑aware SDK that allows the model to generate and execute JavaScript inside a secure V8 isolate. This compiles an agent’s plan into a small code snippet orchestrating multiple operations against the OpenAPI spec, avoiding the need to load all endpoint definitions into context.

Traditional MCP vs Cloudflare Code Mode (Source: Cloudflare Blog Post)
The practical impact is significant: Cloudflare reports that Code Mode reduces the token footprint of interacting with over 2,500 API endpoints from more than 1.17 million tokens to roughly 1,000 tokens, a reduction of around 99.9%. This fixed footprint holds regardless of API surface size, enabling agents to work across large, feature‑rich platforms without exhausting the model context.
Cloudflare emphasized in a Reddit post:
The team utilized a specialized encoding strategy to fit expansive API schemas into minimal context windows without losing functional precision.
Agents first use search() to query the OpenAPI spec by product area, path, or metadata; the spec itself never enters the model’s context. Then, execute() runs code handling pagination, conditional logic, and chained API calls in a single cycle, cutting round-trip overhead.
Cloudflare emphasized the security and sandboxing model during execution. The server runs user‑generated code in a Dynamic Worker isolate with no file system, no environment variables exposed, and outbound requests controlled via explicit handlers. This design mitigates risks associated with executing untrusted code while preserving agent autonomy.
This new MCP server for the entire Cloudflare API spans DNS, Zero Trust, Workers, and R2 services already and is immediately available for developers to integrate. Cloudflare also open‑sourced a Code Mode SDK within its broader Agents SDK to enable similar patterns in third‑party MCP implementations.
Analysts and practitioners see Code Mode as a key step in scaling agentic workflows beyond simple, single‑service interactions toward broad, multi‑API automation. The pattern may influence both standard MCP server designs and agent frameworks in the coming year, as industry players grapple with context costs and orchestration complexity in production‑grade AI agents.