
More than 2,500 endpoints in roughly 1,000 tokens.
That is what Cloudflare achieved with an approach called Code Mode, which changes how agents use tools.
What is the problem?
The MCP protocol connects language models to external tools such as files, databases and other systems. With the traditional approach, however, the description of every tool is loaded into the model's context from the moment it starts, and every result passes through it. So the more tools you add, the higher the consumption and the less room remains for the task itself.
What is the proposed solution?
Instead of calling the tools one by one, the model writes code that calls them. The code runs in an isolated environment and returns to the model only the result it needs.
The numbers:
- At Cloudflare, the description of all endpoints dropped from about 1.17 million tokens to about 1,000.
- At Anthropic, a practical example dropped from 150,000 tokens to 2,000, a saving of 98.7%.
Over 2,500 Endpoints in Around 1,000 Tokens.
That is what Cloudflare achieved with an approach called Code Mode, changing how AI agents interact with tools.
What’s the problem?
The MCP protocol connects language models to external tools such as files, databases, systems, and more. However, with the traditional approach, the description of every tool is loaded into the model’s context from the very first moment it runs, and every result passes back through it. As the number of tools grows, token consumption rises and leaves less room for the actual task.
What’s the proposed solution?
Instead of calling tools one by one, the model writes code that invokes them. The code runs in an isolated environment and returns only the result the model actually needs.
The numbers:
At Cloudflare, the token cost for describing all endpoints dropped from roughly 1.17 million tokens down to around 1,000.
At Anthropic, a practical example dropped from 150,000 tokens to 2,000—a 98.7% reduction.





























