Skip to content
anthropic.com·

🧠Anthropic's MCP Code Execution Cuts Agent Token Use 98.7% in Test

Your agent's context window is bleeding money

TL;DR

Agents loading every MCP tool definition upfront burn tokens and time. Running MCP servers as code APIs cut one workflow from 150,000 tokens to 2,000, a 98.7% saving. If your agents touch many tools, this pattern is worth copying now.

Loading every tool definition into the context window upfront is the wrong default, and the numbers prove it. A new pattern presents MCP servers as code APIs instead of direct tool calls, so agents load only what they need and filter data before it hits the model. If you're building agents on MCP, this hits your bill and your latency. Right now the MCP client pushes every tool definition and every intermediate result through the model, one message loop at a time. As connected tools grow, that gets slow and expensive fast. Cloudflare reached similar conclusions and calls the approach "Code Mode." The headline number: one workflow dropped from 150,000 tokens to 2,000, a 98.7% reduction. The method generates a file tree of available tools, with each tool as a TypeScript file under ./servers/. Agents discover tools by listing directories and reading only the files they need. Security and state management also get better, according to the approach's authors. Worth watching: whether MCP's SDK maintainers bake this pattern into official clients, since thousands of servers already exist and most clients still load everything up front.

Anthropic's MCP Code Execution Cuts Agent Token Use 98.7% in Test — anthropic.com

Key Points

1

The 150,000-to-2,000 token reduction works out to a 98.7% cut in tokens for the tested workflow, a saving in both time and cost.

Keep reading — it's free

Enter your email to keep reading — plus the best of AI & tech, daily. Free, forever.

Also get
or

Already a member? Sign in

MCPAI agentstoken optimizationCloudflaredeveloper tools

Comments

Subscribe to join the conversation...

Be the first to comment