“MCP standardizes how a client discovers what tools exist, fetches schemas, authorizes access … Once you have capabilities, you choose how to present them to the model, [of which generating TypeScript code, as Cloudflare’s post suggests, is one good option].” That good option falters in many scenarios, despite performing well in others, and so only suits a small subset of AI <> MCP possibilities.
Advantages of code execution
Benefits of code execution:- Enables agents to use context more efficiently by loading tools on demand (Anthropic have shown how MCP code execution slashes token usage in AI agents by 98.7%)
- Enables agents to filter data before it reaches the model
- Enables agents to execute complex logic in a single step (loops, conditionals, and error handling can be done with familiar code patterns rather than chaining individual tool calls)
- Intermediate results stay in the execution environment by default. This way, the agent only sees what you explicitly log or return
- Agents can write intermediate results to files, enabling them to resume work and track progress. Agents can also persist their own code as reusable functions.
“LLMs are adept at writing code and developers should take advantage of this strength to build agents that interact with MCP servers more efficiently.” https://www.anthropic.com/engineering/code-execution-with-mcp