• Model Context Protocol (MCP) has become the standard way for AI agents to use external tools. • But there is a tension at its core: agents need many tools to do useful work, yet every tool added fills the model’s context window, leaving less room for the actual task. • Code Mode is a technique we first introduced for reducing context window usage during agent tool use. • Instead of describing every operation as a separate tool, let the model write code against a typed SDK and execute the code safely in a Dynamic Worker Loader. • The code acts as a compact plan. • The model can explore tool operations, compose multiple calls, and return just the data it needs.
Article Summaries:
- Cloudflare has released a new Model Context Protocol (MCP) server that exposes its entire API-spanning DNS, Zero Trust, Workers, and R2-through just two tools, search() and execute(). The server uses “Code Mode,” letting agents write compact JavaScript against a typed SDK instead of invoking thousands of individual tools. This approach cuts context‑window usage by 99.9%, reducing token consumption from over 1.17 million to roughly 1,000 tokens for a large API. The code runs in a sandboxed V8 isolate for safety. Cloudflare also open‑sources a Code Mode SDK, enabling developers to build similar MCP servers for other APIs.
Sources:
- https://blog.cloudflare.com/code-mode-mcp/ (Latest source article published: 2026-02-20 14:00 UTC)