← Back
Cloudflare
Cloudflare releases Code Mode MCP server, compressing entire API into 1,000 tokens
Cloudflare WorkersCloudflare · apifeaturesdkintegrationopen-source · blog.cloudflare.com ↗

Code Mode: Efficient API Access for AI Agents

Cloudflare has released a new MCP (Model Context Protocol) server that provides access to the entire Cloudflare API while dramatically reducing context window consumption. Instead of exposing thousands of individual tools, the server uses a pattern called Code Mode that requires only two tools: search() and execute().

How Code Mode Works

Rather than describing each API operation as a separate tool in the model context, Code Mode lets AI agents write JavaScript code against a typed SDK and execute it safely:

  • Search Tool: Agents write JavaScript to query the OpenAPI specification, filtering endpoints by product, path, tags, or metadata without loading the full spec into context
  • Execute Tool: Agents write code to make actual Cloudflare API requests, handle pagination, chain operations, and process responses—all in a single execution

Both tools run generated code inside a Dynamic Worker isolate (V8 sandbox) with built-in security: no file system access, no environment variable leakage, and disabled external fetches by default.

Massive Token Savings

The efficiency gains are substantial:

  • Code Mode approach: ~1,000 tokens for the entire Cloudflare API
  • Traditional MCP equivalent: 1.17 million tokens—exceeding the context windows of advanced foundation models
  • Reduction: 99.9% fewer input tokens

What's Included

The new MCP server provides agent access to:

  • DNS management
  • Zero Trust networking
  • Workers and edge computing
  • R2 object storage
  • And the full breadth of Cloudflare's API surface

Cloudflare has also open-sourced the Code Mode SDK in the Cloudflare Agents SDK, allowing developers to implement the same pattern in their own MCP servers and AI agents.

Getting Started

Developers can start using the new Cloudflare MCP server today. The open-source SDK enables building Code Mode support into custom AI applications and MCP servers.