2025-11-04 · Anthropic

Code execution with MCP: building more efficient AI agents

protocols

read at source ↗ www.anthropic.com

Code execution with MCP: building more efficient AI agents

Source: Anthropic Engineering Date: 2025-11-04 URL: https://www.anthropic.com/engineering/code-execution-with-mcp

Summary

Anthropic describes a pattern where agents write code to access MCP tools on-demand from a filesystem directory structure rather than receiving all tool definitions upfront as predefined function calls. In a sample Google Drive-to-Salesforce workflow, this reduced token usage from 150,000 to 2,000 tokens — a 98.7% reduction — by eliminating tool definition overhead and enabling intermediate data filtering inside the execution environment.

Implications

The MCP integration patterns thread. This is the most concrete MCP efficiency guidance Anthropic has published — the 98.7% token reduction is a striking number, though it comes from a context where nearly all cost was definition overhead. The pattern (organize tools as files, load on-demand) is directly applicable to any harness with large tool surfaces.

Context engineering in practice. This is just-in-time retrieval applied specifically to tool definitions, validating the broader context engineering post. The pattern extends naturally: any large static context (tool specs, policy docs, system prompts) should be lazy-loaded where possible.

Operational cost. Anthropic explicitly notes the trade-off: code execution requires secure sandboxing infrastructure. This is not a drop-in optimization — it trades prompt simplicity for infrastructure complexity. Shops without existing sandbox infrastructure should evaluate whether the token savings justify the ops overhead.

← all signals