Overview
[AI Summary]: This engineering blog post from Anthropic introduces an efficient approach to building AI agents using code execution with the Model Context Protocol (MCP). As agents connect to hundreds or thousands of tools across multiple MCP servers, loading all tool definitions upfront and passing intermediate results through the context window becomes inefficient. The solution is to present MCP servers as code APIs rather than direct tool calls, allowing agents to write code that loads tools on-demand and processes data in the execution environment. This approach reduces token usage by up to 98.7% while providing benefits including progressive tool disclosure, context-efficient filtering and transformation of large datasets, privacy-preserving operations through tokenization, and state persistence via filesystem access. The post demonstrates practical implementation patterns using TypeScript and discusses security considerations for running agent-generated code in sandboxed environments.
- Published: November 4, 2025
- Authors: Adam Jones, Conor Kelly (Anthropic)
- Type: Engineering blog post
- Language: English