Vibeleaderboard
← All Intel
Intel / article

Code execution with MCP: Building more efficient agents

Source
anthropic.com
Author
Anthropic
Date

Context

An connected to many tools can spend substantial space reading tool descriptions and intermediate results. Anthropic describes a code-execution approach to MCP, the protocol connecting agents to external tools: let the agent discover the interfaces it needs and write code that calls them.

The code can filter or transform data before returning a small result to the model. In the article's spreadsheet example, the agent sees five rows instead of the 10,000 the sheet contains. The model therefore need not read the entire sheet to perform that operation. The tradeoff is operating an environment for generated code, including , resource limits and monitoring.

Terms in this piece · Glossary
  • AI agent — An AI system that doesn't just answer once but works toward a goal in a loop — taking actions, reading the results, and deciding what to do next.
  • context window — The maximum amount of text a model can consider at once — its working memory for the current conversation or task.
  • MCP — The Model Context Protocol — an open standard that lets any AI assistant plug into any tool or data source without custom integration code.
  • sandbox — An isolated environment where AI-generated code or agent actions run without being able to touch anything real.
Key quotes

“Today developers routinely build agents with access to hundreds or thousands of tools across dozens of MCP servers. However, as the number of connected tools grows, loading all tool definitions upfront and passing intermediate results through the context window slows down agents and increases costs.”

Anthropic

“Every intermediate result must pass through the model. In this example, the full call transcript flows through twice. For a 2-hour sales meeting, that could mean processing an additional 50,000 tokens. Even larger documents may exceed context window limits, breaking the workflow.”

Anthropic

“This lets the agent load only the definitions it needs for the current task. This reduces the token usage from 150,000 tokens to 2,000 tokens—a time and cost saving of 98.7%”

Anthropic

“When agents use code execution with MCP, intermediate results stay in the execution environment by default. This way, the agent only sees what you explicitly log or return, meaning data you don’t wish to share with the model can flow through your workflow without ever entering the model's context.”

Anthropic

“Note that code execution introduces its own complexity. Running agent-generated code requires a secure execution environment with appropriate sandboxing , resource limits, and monitoring.”

Anthropic
Read the source www.anthropic.com
More from Anthropic
Recommended reads
Comments

Checking sign-in…

Loading comments…