# Cloudflare put 2,500 API endpoints behind two commands. Is this the future of MCP?

> Source: <https://industrycontents.com/cloudflare-code-mode-mcp-explained/>
> Published: 2026-10-20 21:22:56+00:00

9 min read

## In short

- Code Mode, built by the web infrastructure company Cloudflare, exposes more than 2,500 of its API endpoints through two tools called `search` and`execute` , with a starting footprint of roughly 1,000 tokens.
- Agents find the operations they need, then write code to run them.
- Anthropic, the maker of Claude, is working on related ideas, so this looks like a wider shift in how agents work and extends beyond one company’s design.
- MCP stays in place. The open question is whether code becomes the default way to run large collections of MCP tools.

Before an AI agent reads a word of your request, it may have used 15,000 tokens just learning what it is allowed to do.

That was the situation with one of [Cloudflare’s GitLab servers](https://blog.cloudflare.com/internal-ai-engineering-stack/). GitLab is a platform where teams store and manage code. The server exposed 34 tools, and their definitions alone took about 15,000 tokens of context. The agent had started no work and was still reading the menu.

Now multiply the problem. Cloudflare’s full platform has more than 2,500 API endpoints, which are the access points software uses to talk to its services. Listing each one as a separate tool on the Model Context Protocol (MCP) would swamp a model before it began. For Cloudflare, the fix decided whether agents could work with big software platforms at all.

Its answer, [announced in February 2026](https://blog.cloudflare.com/code-mode-mcp/), was to stop describing every operation upfront. The company calls it Code Mode.

## Why more tools can mean a weaker agent

Anthropic introduced MCP in November 2024 so AI applications could connect to outside data and tools through one standard. Before that, developers built custom links for each pairing of model and service.

Each MCP tool comes with a name, a description and a parameter schema, which lists the inputs the tool accepts. That works fine for a handful of tools. Picture an agent running a website, with access to traffic analytics, DNS settings, caching rules, firewall configuration, deployment history and error logs. Connect it to several business systems and the list runs to hundreds or thousands of operations.

Two costs follow. The first is definition overhead, meaning tokens spent describing tools the model never uses. The second is intermediate results, where data returned by one tool passes through the model before it reaches the next. [Anthropic described this in a November 2025 engineering article](https://www.anthropic.com/engineering/code-execution-with-mcp). An agent moving a meeting transcript into a customer relationship management (CRM) system could end up processing the same long document several times, adding tens of thousands of tokens. MCP never forced clients to load every tool upfront, though many clients do.

## Two tools instead of thousands

Cloudflare’s server offers two general tools. `search` finds relevant API operations and explains how to use them. `execute` lets the agent write JavaScript that calls those operations inside a controlled environment.

The agent searches for what the task needs, then writes code to do it. Cloudflare built this on typed API definitions and its Dynamic Workers infrastructure, so generated code runs against a defined interface with limited access to the host system. The company reported a context reduction of roughly 99.9%.

That figure needs careful reading. It measures the initial description of the tools. The tokens spent on discovery, code generation, execution and the final answer sit outside it. API calls still happen when the generated program runs, as required by the task. What shrank is how the capabilities are presented to the model.

## How a task changes

Take an agent asked to look into a spike in suspicious traffic. With ordinary tool calling, the model fetches traffic data, reads it, requests security events, reads those, then pulls firewall rules. Each step is another model decision and another response in the context.

With Code Mode, the agent searches for the right APIs and writes one program. The program pulls the data, filters it, groups requests and returns a short summary. The model then interprets that summary and recommends what to do.

*Illustrative workflow, built to explain the idea and taken from no Cloudflare benchmark. Discovery, error handling and approvals may still need extra model steps.*

The model still decides what the user wants and what to examine. Filtering, looping and combining data are jobs ordinary software has done reliably for decades, and there is little reason to make a language model read every row. A wrong filter in the generated code can still produce a misleading summary, but the code gives developers a clear place to add checks.

## Anthropic is circling the same idea

In November 2025, [Anthropic published an analysis of code execution with MCP](https://www.anthropic.com/engineering/code-execution-with-mcp). It described agents using generated code to work with tools, instead of routing every call and result through the model. Later that month it [added Tool Search Tool, Programmatic Tool Calling and Tool Use Examples](https://www.anthropic.com/engineering/advanced-tool-use) to its developer platform. Together they let a model find tools on demand, call them through code, and learn how to use them beyond what a schema can say.

The two approaches are related and still differ in deployment models, interfaces and security controls. Neither proves that every agent should write code, and a simple one-step job is better served by a direct tool call. Finding tools and running tools are becoming separate problems, and that shared direction counts for more than either product.

## From one API to a company’s whole toolkit

In April 2026, [Cloudflare brought Code Mode to MCP Server Portals](https://blog.cloudflare.com/enterprise-mcp/). A portal sits in front of several existing MCP servers and offers the agent a small search and execute interface in their place. Companies can keep each integration they have built. With the portal in place, the 34 GitLab tools no longer need to appear one by one in the client’s initial context.

For a company running one or two MCP servers, the saving may be small. For one connecting dozens of services, repeated tool definitions across thousands of agent sessions could add up. Published examples show large savings in particular kinds of overhead, and they leave the standard cut in production costs unanswered. The real number depends on how often agents run, how much discovery costs, how well generated code performs and how many retries are needed.

## Is Code Mode replacing MCP?

It sits at a different layer. MCP is the standard way clients and servers describe tools and resources. Code Mode is a way for an agent to find and use them. It can sit behind a server, as with Cloudflare’s API, or in front of existing servers, as with portals. The protocol itself stays the same. Cloudflare has also worked on a command line interface for its platform, a reminder that one interface will rarely suit every task.

## The security question gets bigger

Letting a model write code invites an obvious worry. An agent can pick the wrong operation, use the wrong parameters or change something it should only have read. Reading firewall analytics and editing a firewall rule call for different permissions.

A sandbox limits where code runs. Judging whether an authorised action suits the moment is a separate job. Companies need to answer three separate questions.

- Can the generated code run safely in a restricted environment?
- Is the agent allowed to call the APIs it finds?
- Should this action go ahead without further confirmation?

A system can pass the first test and fail the others. Audit records need to keep pace with the token savings, so that a small interface stays transparent.

## The winners if this spreads

If this pattern spreads, software companies may need to rethink their APIs. Code Mode rewards clear specifications, typed SDKs (software development kits), predictable error messages and firm authorisation boundaries. A badly documented API stays unreliable even when an agent writes the code against it, and messy naming or hidden dependencies could make errors harder to trace.

Infrastructure providers see a commercial angle too. Agents that reach business systems need authentication, policy enforcement, code execution, secrets management and activity logs, whichever model writes the code. Cloudflare’s portals, access controls and Dynamic Workers cover part of that. Others are building the same layers, and the market is far from settled.

## Which approach fits which job

| Scenario | Likely fit | Reason | 
|---|---|---|
| One or two simple API calls | Direct tool calling | Little to orchestrate | 
| Large API with hundreds of operations | Code Mode | Skips loading definitions upfront | 
| Reporting across several systems | Code driven execution | Processes data outside the model | 
| Sensitive admin changes | Either, with strong controls | Permissions outweigh interface size | 
| Fixed, repeated workflow | Prewritten automation | Logic is predictable | 

*These are architectural judgments and carry no measured ranking.*

## What the evidence shows so far

Cloudflare has shown that a very large API can sit behind a tiny initial interface, and that the pattern extends to existing MCP servers. Anthropic’s work suggests others are tackling the same problem.

Whether Code Mode is cheaper, faster or more reliable overall remains unproven, and five questions are open. Cost and speed depend on the total after discovery, code generation, execution and retries. Reliability depends on whether agents finish complex tasks more accurately with code or fail in new ways. Governance turns on whether companies can keep fine grained permissions and full audit trails. Portability asks whether workflows can move between execution environments without a rewrite. Complexity asks whether the saved context justifies the extra infrastructure needed to run and debug generated code. Published examples tend to report successful runs, while production systems also face failures, changed permissions and odd API behaviour.

## The next test

Four signals will show whether this spreads. More providers need to offer searchable, executable interfaces. Independent benchmarks need to measure total cost, latency and error rates. Enterprises need stronger controls over generated code. Workflows need to move across clients, servers and providers.

Cloudflare’s demonstration works because it exposes a mismatch. Software has been presented to models as a long menu, while agents may need to treat it as something to search and program against. Pulling that off once on one API is far easier than doing it reliably across dozens of systems with every action logged.

## Sources and methodology

Based on published [Cloudflare Code Mode documentation](https://blog.cloudflare.com/code-mode-mcp/), its [internal engineering account](https://blog.cloudflare.com/internal-ai-engineering-stack/) and [enterprise MCP announcement](https://blog.cloudflare.com/enterprise-mcp/), alongside [Anthropic’s code execution analysis](https://www.anthropic.com/engineering/code-execution-with-mcp) and [advanced tool use announcement](https://www.anthropic.com/engineering/advanced-tool-use). IC Lab Desk did not deploy or benchmark Code Mode. Performance figures are attributed to their publishers.
