The Model Context Protocol MCP has a problem with scaling. The context window pushes every tool definition, and each intermediate result through it. This means that large workflows quickly burn tokens or reach their latency and costs limits. Anthropic’s new ‘code execution with MCP’ pattern This pipeline is restructured by turning MCP Tools into APIs at the code level and asking models to run and write code, instead of calling directly tools.
MCP Tools as Direct Model Calls
MCP, an open standard, allows AI systems to communicate with other external systems using MCP servers. The tools allow a model to query databases, use APIs or access files via a single interface.
In default patterns, agents load many tool definitions to the model context. Every tool definition includes schema and metadata. The context is also notified of the intermediate results for each tool.
Anthropic describes an example where an agent would use an MCP Server for Google Drive in order to retrieve a lengthy sales meeting transcript, and then update the record using another MCP Server for Salesforce. First, the full transcript will be returned via the model. Then it will be sent again once the Salesforce tool has been called. This can result in tens or thousands of tokens being added to a meeting that is long.
The pattern will not scale when there are numerous MCP Servers and tools. It is profitable to use large catalogs of tools and move payloads from one tool to another. Costs increase, latency grows, and system behavior becomes more rigid as context limitations are imposed.
MCP Servers are now coded APIs
Anthropic proposes to embed MCP within a loop of code execution. The MCP client does not let the model directly call the tools, but instead exposes the code modules of each server in a filesystem. TypeScript is used by the model to compose and import these modules. The code then runs within a sandboxed system.
There are three steps to the design.
- The MCP Client generates an directory like
You can also find out more about the following:This mirrors all the MCP server and tool options. - The MCP creates, for each tool in the MCP, a thin wrapping function that is implemented within a file source, such as
servers/google-drive/getDocument.tsThis internally invokes the MCP Tool with parameters typed. - The model must write TypeScript that runs the functions imported, handles data flow inside execution environments, controls control flow within them and imports those functions.
The previous Google Drive and Salesforce work flow becomes a script. The script uses the Google Drive wrapper to manipulate or inspect the data, and then invokes the Salesforce Wrapper. Only the summary and the small sample or final transcripts are passed through to the model.
Cloudflare’s ‘Code Mode’ work uses the same idea in its Workers platform. The MCP tool is converted into TypeScript and model-generated code runs inside an isolated with restricted bindings.
Token usage falls by 987 percent.
Anthropic is a good example. The workflow, which consumed approximately 150,000 tokens before when the tools and data intermediates were directly passed through the model has been reimplemented using code execution APIs and MCP filesystem-based APIs. This new pattern only used 2,000 tokens. The tokens were used 98.7 % less in this scenario. Cost and latency are also lower.
Agent builders can benefit from design benefits
The code execution of MCP offers several benefits to engineers that design agents.
Progressive tool discoveryAgents do not require all definitions of tools in context. This allows it to explore the created filesystem and list all available servers. It will only read certain tool modules if they are needed. It moves tool catalogs out of the model context and into code so tokens only go towards relevant interfaces.
Context efficient data handling: The execution environment is able to handle large datasets. TypeScript code, for instance, can be used to read through a spreadsheet using an MCP, filter columns, compute aggregates and then log back only small sample data and summary stats. Code does all the work, while the model only sees the compact version of the data.
Operation privacy preservingThe Anthropic pattern describes how sensitive fields, such as phone or email addresses are tokenized within the execution environment. While the model only sees placeholders in its execution environment, MCP maintains secure mappings and returns real values to downstream tools. The data can move freely between MCP servers, without having to reveal raw identifiers.
Skills that are reusable and state-specificAgents can store scripts and intermediate files in the filesystem. The filesystem allows agents to store scripts and intermediate files. The following are some of the skills that you can learn. Directory and import in subsequent sessions. Anthropic equates this with Claude Skills.
Anthropic’s ‘code execution with MCP’ approach is a sensible next step for MCP powered agents. The MCP server is presented as a code API, which pushes work to an isolated TypeScript runtime. This directly targets the costs of routing large results and loading tools definitions. Agents become more efficient and teams are forced to consider code execution security. This launch converts MCP, which was a list of tools into an API that is executable.

