Code Mode: give agents an entire API in 1,000 tokens
2026-02-20
10 min read
28
by Matt Carey
Endigest AI Core Summary
Cloudflare introduces Code Mode, a technique that exposes their entire 2,500+ endpoint API to AI agents via just two MCP tools consuming only ~1,000 tokens.
- •Code Mode replaces individual tool definitions with two tools: search() and execute(), both accepting JavaScript code as input
- •The search() tool lets agents write JavaScript against a pre-resolved OpenAPI spec to filter endpoints without loading the full spec into context
- •The execute() tool runs authenticated Cloudflare API requests inside a sandboxed V8 Workers isolate with no file system or environment variable leakage
- •An equivalent native MCP server would consume 1.17 million tokens; Code Mode reduces this by 99.9%
- •The server is OAuth 2.1 compliant and the Code Mode SDK is open-sourced via the Cloudflare Agents SDK
Tags:
#Developers
#Developer Platform
#AI
#Workers AI
#Cloudflare Workers
#Optimization
#Open Source
