Free Intensive Nov 21–22Free 2-day hands-on Vibecoding Intensive on Nov 21–22 at 16:00 MSK (Sat–Sun) · Live Cohort 3 starts Nov 23Join Free →Cohort 3 (Nov 23)
ReleaseAPI / Product · ActionableHabr AI→ original

Two Tools Instead of 2,500 API Methods: How to Keep an Agent from Burning 1.17 Million Tokens of Context

MCP is a way to connect external services to an AI agent, but descriptions of hundreds of methods flood the context, which is the model's working memory. Cloudflare's 2,500 API methods would take up roughly 1.17 million tokens (units of text). Code Mode leaves the agent with two tools: search() finds a method, and execute() runs a chain of calls as code. To keep the model from forgetting to search, the author added SKILLs, short instructions that name the methods to use.

AI-processed from Habr AI; edited by Hamidun News
Two Tools Instead of 2,500 API Methods: How to Keep an Agent from Burning 1.17 Million Tokens of Context
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Without Code ModeCloudflare's 2,500 methods come to about 1.17 million tokens
Key metric #2A single execute() call runs a chain of steps without returning to the model
The author did not measure the savingsthey need to be checked on your own tasks

Imagine hiring an assistant and reading them the instructions for all 2,500 buttons on a remote before every task. The work never gets done, because they tire of listening. That is roughly what happens to AI agents when many services are connected through MCP (Model Context Protocol, a standard by which an agent calls external tools).

The description of each method goes into the context, that is, the model's working memory, and it is measured in tokens: units of text that are billed and that cap the size of a request. The developer behind the Habr write-up ran into this on two tasks at once: setting up a personal agent called Nanabot, and writing an MCP server to manage the company's products. His recipe combines Code Mode MCP with SKILLs.

The problem with hundreds of tools

In a standard MCP setup, the MCP client passes the model descriptions of all connected tools. Cloudflare has more than 2,500 API methods, and by the company's estimate, describing them all as MCP tools would take about 1.17 million tokens. This is Cloudflare's own estimate, not a measurement by the article's author.

The company proposed Code Mode MCP. Instead of thousands of tools, the agent gets two. The first, search(), finds the methods it needs and returns their signatures (names, parameters, and required fields) based on a query. The second, execute(), runs JavaScript code that calls those methods. A single execute() call can combine several operations and return the result, and the language model does not have to be consulted after each step.

The article gives a simple example: the agent is told "open example.com and take a screenshot." Through search() it finds navigate_page and take_screenshot, then opens the page and captures the frame with a single script. No new request goes to the model between those two steps. An important caveat: the article presents searching an array of tools as one of the options for an aggregator. Cloudflare, for example, searches operations in an OpenAPI specification.

The scheme has weak spots too. The savings are not guaranteed: repeated searches and loading signatures also spend tokens. The size of the gain depends on the size of the catalog, how often searches happen, and the number of calls. An accurate estimate requires measurements on specific tasks. In addition, the model sometimes fails to find the method it needs, and sometimes does not realize it should search at all.

How SKILLs close the gap

Cloudflare recommends using SKILLs alongside MCP: a SKILL tells the agent when and which capabilities to apply. The author followed the same path. He hid many MCP servers behind Code Mode, so the model sees a single server with search and execution. In the SKILL he wrote a brief list of the needed servers and methods, without full descriptions.

A working example is the bugfix-process SKILL. The user writes: "Fix bug 731 in the two-server repository, current branch, run the two_jar_java17 build." The agent then proceeds as follows:

  • it sees a short description of the SKILL in its persistent context and understands that it applies;
  • it reads the SKILL itself and learns the order of steps and the servers ticket_mcp, samba_mcp, filesystem_mcp, git_mcp, codex_mcp, and jenkins_mcp;
  • through search() it requests signatures only for the methods it needs, such as get_ticket or download_attachment;
  • through execute() it collects the ticket, comments, attachments, and logs from Samba into the tickets/731/ folder;
  • it commits only that folder, so the materials do not mix with the future fix;
  • it launches Codex via start_task, waits for the result, checks the diff, and pushes the fix to the repository;
  • it runs Jenkins and sets the ticket status to Resolve or In Progress, then writes a report to result.fixed.md or result.in-progress.md.

There is one more saving here. Large logs and attachments sit on disk and never pass through the main agent's context. Codex reads them from the given path and takes only what it needs. The main agent acts as an organizer and delegates the programming itself.

Three layers of context and limitations

The resulting architecture looks like three layers. The persistent context holds the short SKILL descriptions and the two Code Mode tools. A SKILL is loaded when it matches the task and holds the algorithm and method names. Code Mode fetches the full signatures on demand and performs the calls. Previously the choice was between two bad options: load everything and spend tokens, or hide everything and hope the model guesses right. Now there is a third.

Limitations remain. The model may still fail to pick the right SKILL, make a mistake when searching for a method, or write incorrect JavaScript. Not every chain can be collapsed into a single call: sometimes the agent has to parse an intermediate result and make a new decision. The author does not give savings figures for his own scenarios, only the estimate that they are "likely."

The practical takeaway for teams: if you have many internal tools (tickets, CI, git, file storage), do not describe all of them in the system prompt. Describe the processes in short SKILLs, and give the agent search over signatures and execution of scripts. Before adopting this, measure token usage on real tasks, or you will have to take the benefit on faith.

Story

Key Questions Answered

What are the key details on The problem with hundreds of tools?

In a standard MCP setup, the MCP client passes the model descriptions of all connected tools. Cloudflare has more than 2,500 API methods, and by the company's estimate, describing them all as MCP tools would take about 1.17 million tokens. This is Cloudflare's own estimate, not a measurement by the article's author. The company proposed Code Mode MCP. Instead of thousands of tools, the agent gets two.

How SKILLs close the gap?

Cloudflare recommends using SKILLs alongside MCP: a SKILL tells the agent when and which capabilities to apply. The author followed the same path. He hid many MCP servers behind Code Mode, so the model sees a single server with search and execution. In the SKILL he wrote a brief list of the needed servers and methods, without full descriptions. A working example is the bugfix-process SKILL.

What are the key details on Three layers of context and limitations?

The resulting architecture looks like three layers. The persistent context holds the short SKILL descriptions and the two Code Mode tools. A SKILL is loaded when it matches the task and holds the algorithm and method names. Code Mode fetches the full signatures on demand and performs the calls. Previously the choice was between two bad options: load everything and spend tokens, or hide everything and hope the model guesses right. Now there is a third. Limitations remain.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…