Cloudflare Workers & R2 Context Guide for AI Coding (llms.txt + Rules + MCP)

Deploy serverless code instantly across the globe with zero server maintenance, KV storage, and S3-compatible R2 storage.

1. Cloudflare Workers & R2 Official llms.txt & Clean Markdown Documentation

Official Cloudflare Registry

Feed this clean, token-efficient Markdown documentation directly to Antigravity, Cursor, or Claude Code to prevent hallucinations and outdated API syntax.

# Standard llms.txt Index Endpoint
https://developers.cloudflare.com/llms.txt

# Comprehensive Documentation Bundle
https://developers.cloudflare.com/llms-full.txt
Estimated Token Footprint: ~41k tokens (Fits smoothly inside standard 128k/1M context windows)

2. Production-Ready Cloudflare Workers & R2 Cursor Rules (.cursorrules & .mdc)

Cloudflare Workers, Pages, and R2 rules for zero-cost indie hacker architectures. Save this into .cursor/rules/cloudflare.mdc in your project repository.

// Cloudflare Workers & R2 Rules
- Use wrangler.json / wrangler.toml to define bindings (KV, R2, D1, Queues).
- Prefer Web Standard APIs (Request, Response, Fetch, Crypto) natively provided by workerd.
- Cache static assets at edge with Cache-Control headers to maximize Cloudflare free tier.
- Use R2 for user file uploads with presigned URLs to avoid routing heavy payloads through worker CPU.

3. Cloudflare Workers & R2 Antigravity & Claude Code System Instructions

Add this concise instruction block to your workspace .gemini/rules or project system prompt.

// Context Anchor for Cloudflare Workers & R2
When writing code for Cloudflare Workers & R2, refer directly to the verified specifications at https://developers.cloudflare.com/llms.txt.
Follow strict error-handling and avoid deprecated API calls.

4. Model Context Protocol (MCP) Server Setup for Cloudflare Workers & R2

Connect your AI coding agent directly to live Cloudflare Workers & R2 tools and schemas via MCP.

{
  "mcpServers": {
    "cloudflare": {
      "command": "npx",
      "args": ["-y", "@cloudflare/mcp-server-cloudflare"]
    }
  }
}

5. Troubleshooting: Common Cloudflare Workers & R2 AI Coding Issues & Fixes

Frequently reported errors when LLMs generate Cloudflare Workers & R2 code without proper context:

⚠️ Proactive Fix: Fix: Workers have strict CPU time limits. Long-running CPU operations should be offloaded to Cloudflare Queues or Workflows.

6. Best Used With (Cloudflare Workers & R2 Architecture Combos)

Engineers building with Cloudflare Workers & R2 frequently combine these complementary developer frameworks: