Your AI agent needs to check DNS records or review a cloud configuration. The task sounds straightforward. Before it can act, however, the agent may have to process a large collection of instructions explaining which tools exist and how to use them.
That preparation consumes context space before useful work begins.
Cloudflare Code Mode addresses this problem by giving agents a compact way to discover API operations and execute them through code. Cloudflare’s official Code Mode announcement introduced an MCP server in February 2026 that could access more than 2,500 endpoints across Cloudflare’s API using two core tools: search() and execute().
What Is Cloudflare Code Mode?
The Cloudflare Code Mode documentation describes an approach in which an AI model writes code to coordinate tools, process their results, and return useful information.
An API endpoint represents a particular operation, such as retrieving records or updating a setting. When thousands of operations are available, explaining each one separately can consume substantial model context.
Code Mode lets the agent discover relevant capabilities and express several steps in one executable plan. The code can handle loops, conditions, and filtering without sending every intermediate result back through the model.
MCP, or Model Context Protocol, provides the connection between an AI agent and external tools. Code Mode changes how agents work with those tools while continuing to use that connection.
How the Cloudflare Code Mode MCP Architecture Works
The core workflow separates discovering an operation from performing it.
Search Finds the Right Operation
The search() tool allows an agent to query an OpenAPI description: a structured reference containing available endpoints, inputs, and responses.
For a DNS task, the agent can locate relevant operations and inspect the information required to call them. The full API description stays outside the model’s context; the search returns the details needed for the task.
Execute Turns the Plan into Actions
The execute() tool runs generated code that makes authenticated API requests. That code can retrieve information, process additional result pages, combine responses, and return a focused result.
A workflow may require several search and execution calls. “Two tools” describes the core interface, rather than a fixed limit of two calls per task.
Cloudflare’s current MCP repository also lists supporting tools, including docs for documentation searches and whoami for identifying the connected user or account.
What Does the 1,000 Token Figure Actually Mean?
Cloudflare reported that its original two-tool interface occupied approximately 1,000 tokens. Its comparison showed around 1.17 million tokens for an equivalent MCP approach exposing individual operations with full definitions.
The reported 99.9% reduction applies to that tool-definition overhead.
Tokens are the units of text a model processes. Reducing the space occupied by tool instructions leaves more room for the task, relevant information, and useful results.
However, a completed workflow still consumes tokens for instructions, generated code, discovered schemas, responses, and further reasoning. The launch figure therefore cannot establish the total cost of every AI task.
For a business evaluating this approach, the useful question is whether the complete workflow becomes more efficient while producing accurate results. That requires measuring actual tasks, including retries and human review.
How This Could Help Everyday Cloud Operations
Consider a team reviewing DNS records across several domains it manages.
An agent could first discover the appropriate endpoints, retrieve the records, and filter them using criteria supplied by the team. It could then return a shortlist for an engineer to investigate.
This is an illustrative workflow, but it follows the documented Code Mode pattern of combining operations and processing intermediate data in code.
The engineer still needs to define what deserves attention. An unfamiliar record is not automatically incorrect, and an agent should not delete it simply because it looks unusual.
Similar reasoning applies to cloud and DevOps practices, where automation, monitoring, and deployment controls need to work together.
A useful implementation should make the result easier to verify. For example, a DNS review should identify which domain was checked, what record needs attention, and why it was flagged. A confident summary without supporting details creates more work for the person reviewing it.
Does Code Mode Make AI Agents Secure?
Running generated code requires clear boundaries. Cloudflare’s runtime documentation describes isolated execution with controlled access to external capabilities. Generated code does not automatically receive host credentials, Node.js APIs, or unrestricted network access.
Those restrictions help contain execution, but they do not determine whether a permitted action is appropriate.
Keep Permissions Narrow
An agent reviewing configuration should receive the access required for that review. Write access should follow a separate decision about which changes it may make and under what conditions.
Cloudflare’s implementation guidance keeps authentication in the host request function and requires authorization around operations. Developers remain responsible for enforcing these controls and any necessary approvals before changes occur.
Review Consequential Changes
The same discipline matters when teams prioritize critical vulnerabilities. Automated findings should support investigation, while proposed fixes need validation against the affected application and its production environment.
An agent may retrieve the correct information and still suggest an unsuitable change. Review should consider the evidence, expected impact, and recovery options before the action proceeds.
What Should Developers Check Before Adoption?
Cloudflare currently labels Code Mode experimental and warns that breaking changes may occur. Teams should check the specific SDK and server version they intend to use.
Start with a bounded workflow that is easy to evaluate, such as gathering configuration details for review. Compare it with the existing process using:
Correctness of the selected endpoints and parameters.
Total tokens and time needed to finish.
Frequency of retries or failed requests.
Clarity of the information returned.
Amount of human review still required.
Failure handling deserves particular attention. If one change succeeds and the next request fails, retrying everything could repeat work already completed. Execution records, safe retry behavior, and tested recovery procedures help prevent that problem.
Making Large APIs Easier to Use
Cloudflare Code Mode gives AI agents a practical way to work with extensive API catalogs through selective discovery and executable plans. Its value comes from keeping unnecessary tool information and intermediate processing out of the model’s context.
For businesses, the next step is a carefully scoped trial. Evaluate whether the agent completes useful work accurately, produces results people can inspect, and stays within its permissions. Those outcomes provide a stronger basis for adoption than a token-saving headline alone.
