Skip to content

Blog

Agents should write code to call MCP tools, not call them directly

In Anthropic's example, direct MCP tool calls took 150,000 tokens and an agent writing code to call the same tools took 2,000. Code execution is the way to use MCP.

Written by

Coding agent setup

Published: 30 December 2025 Updated: 2 min read

Anthropic just validated what I have been saying about MCP. Traditional MCP, with direct tool calls, wastes tokens. The answer is code execution.

What Anthropic found

In Anthropic’s example task:

  • Traditional MCP (direct tool calls): 150,000 tokens. It loads all tool definitions upfront, and every result flows through the model.
  • Code execution (agents write code): 2,000 tokens. It loads tools on demand and processes data in the execution environment.

That is a 98.7% token reduction.

What I argued earlier

On December 9, I posted “Ditching MCP”, advocating for CLI commands and code execution instead of MCP’s direct tool calls. On December 18, I warned about MCP’s hidden costs: tool descriptions consuming massive context, every integration eating 2 to 5% of your window.

Now Anthropic confirms it. Traditional MCP is inefficient. Let agents write code to call tools. This is what CLI approaches and code execution have been doing all along.

How code execution works

Agents discover tools via the filesystem and write code to call them. The benefits:

  • tools load on demand
  • loops, conditionals and error handling live in code
  • data stays in the execution environment
  • state persists, and agents build reusable skills

Traditional MCP does not scale. The answer is code execution with MCP servers as APIs. CLI approaches already work this way: tools as executable commands, agents writing scripts, data staying in the execution environment. MCP works efficiently only when you drop direct tool calls for code execution.

What to do with this

  • Using traditional MCP direct tool calls? You are wasting massive context. Switch to code execution.
  • Using CLI commands or code execution already? Anthropic just validated your choice.
  • Building new agents? Skip traditional MCP tool calling. Use code execution from the start.

Anthropic’s research confirms what many suspected: traditional MCP tool calling is inefficient. The fix is not more MCP adoption. It is code execution, whether via CLI commands, scripts or MCP servers as APIs. If your agent writes code to call tools instead of making direct tool calls, you are doing it right.

Are you still loading all tool definitions into context, or are your agents writing code?

Source: Anthropic Engineering, “Code execution with MCP: Building more efficient agents” (opens in a new tab), 4 November 2025.

Further reading

  1. The best agent architecture is a simple while loop Claude Code and the pi agent show the same thing: a main loop, a few general-purpose tools and careful context management beat elaborate orchestration. 1 min readShort post
  2. For tools you own, build a CLI before an MCP server Every MCP server loads all its tools into context before the agent starts. Keep MCP for external services and give your own tools a CLI, scripts or skills, which cost a fraction of the context. 2 min readShort post
  3. Slash commands, MCP, sub-agents and skills form a hierarchy Teams build the same workflow three ways because they treat Claude Code's four overlapping features as equals. They form layers: prompts at the base, MCP and sub-agents beside each other, skills composing the rest. 2 min readShort post

All 14 posts on Coding agent setup

ClientsClient work

Scaling needs named owners

Coding agents scale across teams when named people own the platform, the team practice, the guardrails, and the measurement. Rollout & scale is where that ownership is built and handed to internal owners, in your stack.

Training on this topic: Agentic Engineering for Developers and QA
See Rollout & scale

Want to check one team first? The self-check: twelve yes or no questions, three minutes, instant result, no account. Take the self-check