|
| 1 | +# Cloudflare MCP Server |
| 2 | + |
| 3 | +An MCP (Model Context Protocol) server that exposes Cloudflare DNS management functionality as tools for AI assistants like Claude. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Install with MCP support: |
| 8 | + |
| 9 | +```bash |
| 10 | +# Using pip |
| 11 | +pip install lazyops[cloudflare] |
| 12 | + |
| 13 | +# Using uv |
| 14 | +uv pip install lazyops[cloudflare] |
| 15 | +``` |
| 16 | + |
| 17 | +## Configuration |
| 18 | + |
| 19 | +Set your Cloudflare credentials as environment variables: |
| 20 | + |
| 21 | +```bash |
| 22 | +# Using API Token (recommended) |
| 23 | +export CLOUDFLARE_API_TOKEN="your-api-token" |
| 24 | + |
| 25 | +# Or using API Key + Email |
| 26 | +export CLOUDFLARE_API_KEY="your-api-key" |
| 27 | +export CLOUDFLARE_EMAIL="your-email@example.com" |
| 28 | +``` |
| 29 | + |
| 30 | +## Running the Server |
| 31 | + |
| 32 | +### Using uv (Recommended) |
| 33 | + |
| 34 | +```bash |
| 35 | +# Run directly with uv |
| 36 | +uv run cloudflare-mcp |
| 37 | + |
| 38 | +# Or with inline dependencies |
| 39 | +uv run --with lazyops[cloudflare] cloudflare-mcp |
| 40 | +``` |
| 41 | + |
| 42 | +### Using Python Module |
| 43 | + |
| 44 | +```bash |
| 45 | +python -m lzl.api.cloudflare.mcp |
| 46 | +``` |
| 47 | + |
| 48 | +### Using Entry Point (after installation) |
| 49 | + |
| 50 | +```bash |
| 51 | +cloudflare-mcp |
| 52 | +``` |
| 53 | + |
| 54 | +## Claude Desktop Configuration |
| 55 | + |
| 56 | +Add to your Claude Desktop configuration file: |
| 57 | + |
| 58 | +**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json` |
| 59 | +**Windows**: `%APPDATA%\Claude\claude_desktop_config.json` |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "mcpServers": { |
| 64 | + "cloudflare": { |
| 65 | + "command": "uv", |
| 66 | + "args": ["run", "--with", "lazyops[cloudflare]", "cloudflare-mcp"], |
| 67 | + "env": { |
| 68 | + "CLOUDFLARE_API_TOKEN": "your-api-token" |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +Or if you have `lazyops` installed globally: |
| 76 | + |
| 77 | +```json |
| 78 | +{ |
| 79 | + "mcpServers": { |
| 80 | + "cloudflare": { |
| 81 | + "command": "cloudflare-mcp", |
| 82 | + "env": { |
| 83 | + "CLOUDFLARE_API_TOKEN": "your-api-token" |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Available Tools |
| 91 | + |
| 92 | +### Zone Management |
| 93 | + |
| 94 | +| Tool | Description | |
| 95 | +|------|-------------| |
| 96 | +| `cloudflare_list_zones` | List all zones in the account | |
| 97 | +| `cloudflare_get_zone` | Get details for a specific zone | |
| 98 | + |
| 99 | +### DNS Record Operations |
| 100 | + |
| 101 | +| Tool | Description | |
| 102 | +|------|-------------| |
| 103 | +| `cloudflare_list_records` | List DNS records for a zone | |
| 104 | +| `cloudflare_create_record` | Create a new DNS record | |
| 105 | +| `cloudflare_update_record` | Update an existing record | |
| 106 | +| `cloudflare_delete_record` | Delete a DNS record | |
| 107 | + |
| 108 | +### Record Type Helpers |
| 109 | + |
| 110 | +Convenience tools for common record types: |
| 111 | + |
| 112 | +| Tool | Description | |
| 113 | +|------|-------------| |
| 114 | +| `cloudflare_add_a_record` | Add an A record (IPv4) | |
| 115 | +| `cloudflare_add_aaaa_record` | Add an AAAA record (IPv6) | |
| 116 | +| `cloudflare_add_cname_record` | Add a CNAME record | |
| 117 | +| `cloudflare_add_mx_record` | Add an MX record | |
| 118 | +| `cloudflare_add_txt_record` | Add a TXT record | |
| 119 | + |
| 120 | +### Service Templates |
| 121 | + |
| 122 | +Pre-configured email service setups: |
| 123 | + |
| 124 | +| Tool | Description | |
| 125 | +|------|-------------| |
| 126 | +| `cloudflare_add_google_workspace_mx` | Add Google Workspace MX records | |
| 127 | +| `cloudflare_add_microsoft_365_mx` | Add Microsoft 365 MX record | |
| 128 | +| `cloudflare_add_spf_record` | Add SPF record with provider presets | |
| 129 | +| `cloudflare_add_dmarc_record` | Add DMARC record | |
| 130 | + |
| 131 | +### Export / Import |
| 132 | + |
| 133 | +| Tool | Description | |
| 134 | +|------|-------------| |
| 135 | +| `cloudflare_export_records` | Export records to JSON or BIND format | |
| 136 | +| `cloudflare_import_records` | Import records from JSON | |
| 137 | + |
| 138 | +### Diff / Compare |
| 139 | + |
| 140 | +| Tool | Description | |
| 141 | +|------|-------------| |
| 142 | +| `cloudflare_diff_records` | Preview changes without applying | |
| 143 | +| `cloudflare_compare_zones` | Compare records between two zones | |
| 144 | + |
| 145 | +### Declarative Management |
| 146 | + |
| 147 | +| Tool | Description | |
| 148 | +|------|-------------| |
| 149 | +| `cloudflare_apply_records` | Apply desired DNS state declaratively | |
| 150 | + |
| 151 | +## Example Prompts |
| 152 | + |
| 153 | +Once connected, you can ask Claude: |
| 154 | + |
| 155 | +- "List all my Cloudflare zones" |
| 156 | +- "Show me the DNS records for example.com" |
| 157 | +- "Add an A record pointing www.example.com to 192.0.2.1" |
| 158 | +- "Set up Google Workspace email for example.com" |
| 159 | +- "Add SPF and DMARC records for example.com" |
| 160 | +- "Export all DNS records from example.com" |
| 161 | +- "Compare DNS records between staging.example.com and example.com" |
| 162 | + |
| 163 | +## Security Notes |
| 164 | + |
| 165 | +- The server uses your Cloudflare credentials from environment variables |
| 166 | +- All operations are performed with the permissions of your API token |
| 167 | +- Use API tokens with minimal required permissions when possible |
| 168 | +- The `sync_mode="full"` option in `cloudflare_apply_records` can delete records - use with caution |
| 169 | + |
| 170 | +## Troubleshooting |
| 171 | + |
| 172 | +### Server won't start |
| 173 | + |
| 174 | +1. Ensure credentials are set: |
| 175 | + ```bash |
| 176 | + echo $CLOUDFLARE_API_TOKEN |
| 177 | + ``` |
| 178 | + |
| 179 | +2. Verify the MCP package is installed: |
| 180 | + ```bash |
| 181 | + uv pip show mcp |
| 182 | + ``` |
| 183 | + |
| 184 | +3. Test the server manually: |
| 185 | + ```bash |
| 186 | + uv run cloudflare-mcp |
| 187 | + ``` |
| 188 | + |
| 189 | +### Permission errors |
| 190 | + |
| 191 | +Ensure your API token has the required permissions: |
| 192 | +- `Zone:Read` - For listing zones |
| 193 | +- `DNS:Read` - For listing records |
| 194 | +- `DNS:Edit` - For creating/updating/deleting records |
| 195 | + |
| 196 | +### Connection issues |
| 197 | + |
| 198 | +Check that your `claude_desktop_config.json` is valid JSON and the paths are correct. |
0 commit comments