Back to AI information
Anthropic releases "Execute Code with MCP" practice: Enabling agents to improve efficiency by writing code rather than directly connecting to tools.

Anthropic releases "Execute Code with MCP" practice: Enabling agents to improve efficiency by writing code rather than directly connecting to tools.

AI information Admin 113 views

On November 4, 2025, Anthropic published an engineering blog post proposing to prioritize the "code execution" path within the MCP (Model Context Protocol) ecosystem: generating callable code APIs for tools on each MCP server, allowing proxies to write code first and then call the tools, rather than cramming all tool definitions and intermediate results into the context. The post describes generating TypeScript file trees per server/tool, with proxies reading the required interfaces on demand, filtering and merging data in the execution environment, and only sending back necessary summaries to the model. Official examples show that the context consumption of approximately 150,000 tokens can be compressed to approximately 2,000, significantly reducing cost and latency. The post also cites Cloudflare's "Code Mode" observation, pointing to the same approach.

The article emphasizes the additional benefits of this method: handling loops, conditions, and errors through the execution environment; anonymizing personal data in a local/sandbox environment to prevent sensitive information from entering the model context; and combining it with file system persistence of intermediate artifacts, while also integrating with Claude Skills' reusable "skills" mechanism. However, code execution requires a reliable sandbox, quotas, and monitoring, introducing new operational and security requirements, thus necessitating a trade-off between efficiency and risk control.

Frequently Asked Questions

Q: What is the core message of this release?

A: Use code execution to connect to MCP: Map the tool to code API, load definitions on demand, process data in the execution environment, and then send the result summary back to the model, reducing context usage and error rate.

Q: How does its efficiency compare to the "model direct connection tool"?

A: The official example shows a comparison of reducing the number of tokens from approximately 150,000 to approximately 2,000, representing a saving of approximately 98.7%; the specific benefits depend on the scale of the tool and the amount of data.

Q: What is the relationship between this and Cloudflare's "Code Mode"?

A: Both viewpoints agree: allowing models to write code to call abstract APIs is more efficient. Anthropic directly cites this practice in its article.

Q: What improvements have been made to privacy and compliance?

A: Intermediate data remains in the execution environment by default. Sensitive fields such as emails and phone numbers can be tokenized and restored on the client side when transferring data across tools, reducing the leakage surface.

Q: How does it work in conjunction with Claude Skills?

A: The agent can save verified scripts as reusable skills (including SKILL.md and resources), which can be directly referenced in subsequent tasks, improving robustness and maintainability.

MCP ecosystem code execution priority strategy Map the tool to a callable code API The proxy writes the code first and then calls the tool flow. TypeScript file tree generated by server Load interfaces on demand to reduce context redundancy. Execution environment merges and filters intermediate data Context count reduced from 150,000 to 2,000 (example) Explanation of approximately 98.7% Token Savings Comparison of Model Direct Connection Tools and Code Mode CloudflareCodeMode's approach is consistent Handling loops and faulty branches within a sandbox Data anonymization tagging is performed at the local execution layer. Tokenization of sensitive fields to prevent leakage Only return the necessary result summary to the model File system persistence intermediates Integration with ClaudeSkills skill mechanics The scripts have been verified and can be used as reusable skills. SKILLmd and Resource Organization Best Practices Code execution requires quotas and monitoring governance. The trade-off between efficiency gains and risk control costs Abstract API layer for large toolsets Client-side recovery of cross-tool data flow Reduce the risk of tool definition hard-stuffing context Improve the stability and reproducibility of reasoning MCP remote server combined with code calls Task-driven interface definition reading by module Execution environment support conditions and retry mechanism Compliant handling of privacy within the private domain sandbox Multi-step toolchains are executed via code orchestration. How developers can build a security sandbox layer Auditable script repository for teams Runtime control combining permissions and quotas Path to connect cloud APIs and databases Minimal Context Summary Generation Paradigm Reduce model misuse and illusion injection surfaces Code-based patterns reduce latency and cost overhead Trade-offs with DeepContext material stacking approach Compliance and Audit Friendly for Enterprises Running agent scripts in the CI pipeline TypeGen automatically generates interface type definitions. Interface changes are managed through versioning. Optimize call count by combining caching and deduplication API encapsulation practices for multiple languages Closed-loop link from task to code to result Design for resuming execution after breakpoints in long-running tasks Script review and signing for team collaboration Tool directory and loading order standardization Error Classification and Recoverable Strategy Template Local priority principle for highly sensitive scenarios Layered architecture for code execution and model invocation

Recommended Tools

More