Agent setup · Exercise 05
Tools
Connect your agent to the Cloudflare API with the Cloudflare MCP server, which uses Code Mode to stay token-efficient.
Prompt for your agent
Copied! Now paste that into your agent...
Tools
MCP (Model Context Protocol) is how an agent gets extra tools from an outside server. Cloudflare’s MCP server gives your agent access to the whole Cloudflare API, so it can look things up and manage your account without you copy-pasting from the dashboard.
Why Code Mode matters
Normally, every tool’s name, description, and parameters sit in the model’s context window for the entire conversation. The Cloudflare API has around 2,500 endpoints. Describing each as its own tool would take roughly 244,000 tokens, more than most models can even hold.
Cloudflare’s server uses Code Mode instead. It exposes a few tools that take JavaScript:
search: the agent writes code to query the API’s OpenAPI spec and find the endpoints it needsexecute: the agent writes code to call those endpointsdocs: search the Cloudflare developer docs
The whole definition costs about 1,100 tokens, around 0.5% of the alternative, and your agent can still reach every endpoint. The context window stays free for your actual work.
Add the server
The server lives at https://mcp.cloudflare.com/mcp and uses OAuth: your agent sends you to Cloudflare to log in and choose which permissions to grant. Start with read-only if you’re not sure.
| Agent | Add it | Then |
|---|---|---|
| Claude Code | claude mcp add --transport http --scope user cloudflare https://mcp.cloudflare.com/mcp |
Run /mcp and log in |
| Codex | codex mcp add cloudflare --url https://mcp.cloudflare.com/mcp |
codex mcp login cloudflare |
| OpenCode | opencode mcp add (type remote) |
opencode mcp auth cloudflare |
| Cursor | Add the config below to ~/.cursor/mcp.json |
Connect it in Settings, Tools & MCP |
| GitHub Copilot CLI | /mcp add (type HTTP) |
Authorize in the browser |
| Pi (0.99+) | pi mcp add cloudflare --url https://mcp.cloudflare.com/mcp |
pi mcp login cloudflare |
Any other agent that supports remote MCP servers can use this config:
{
"mcpServers": {
"cloudflare": {
"type": "http",
"url": "https://mcp.cloudflare.com/mcp"
}
}
}
Restart your agent if the new tools don’t show up.
Try it
Ask your agent something harmless, like “List the Workers on my Cloudflare account” or “How do Durable Objects handle alarms?” You should see it call search to find the right endpoint, then execute to run it.
MCP server or cf?
Use cf (from the CLI exercise) to build and deploy projects from your terminal. Use the MCP server to query and manage account resources through the API, and for anything cf doesn’t cover yet. Your agent has both. Because execute can change real resources, expect your agent to check with you before it writes or deletes anything.