Cloudflare Code Mode MCP: Two-Tool Pattern Gives Agents an Entire API in 1,000 Tokens — 99.9% Reduction from 1.17M Tokens Across 2,500 Endpoints
Cloudflare released a Code Mode MCP server that reduces the token footprint of their 2,500+ API endpoints from 1.17M tokens to ~1,000 — a 99.9% reduction. The approach uses just two tools: search() to query the OpenAPI spec by product area without loading it into context, and execute() to run agent-generated JavaScript inside a secure V8 isolate handling pagination and chained calls in a single cycle. The key insight: converting MCP tool definitions into a TypeScript API and asking the LLM to write code against it consistently outperforms sequential tool calling while cutting token usage by 81-99.9%. For builders: apply this pattern to any large API — expose search + execute over your OpenAPI spec instead of one MCP tool per endpoint.
↳ Follow the thread