Cloudflare MCP Server
Enables AI assistants to manage Cloudflare resources through natural language, including DNS records, zone management, Workers KV storage, cache purging, and analytics. Supports comprehensive Cloudflare operations with secure API token authentication.
README
<img src="https://github.com/ry-ops/cloudflare-mcp-server/blob/main/cloudflare-mcp-server.png" width="100%">
Cloudflare MCP Server
A Model Context Protocol (MCP) server that provides seamless integration with the Cloudflare API. Built with Python and managed with uv for blazing-fast dependency management.
Features
🌐 Zone Management
- List all zones in your account
- Get detailed zone information
- Filter zones by name and status
🔧 DNS Management
- List DNS records with filtering
- Create new DNS records (A, AAAA, CNAME, TXT, MX, etc.)
- Update existing records
- Delete records
- Full support for proxied records and TTL configuration
💾 Workers KV Storage
- List KV namespaces
- Read values from KV
- Write key-value pairs with optional TTL
- Delete keys
- List keys with prefix filtering
- Support for metadata
⚡ Cache & Performance
- Purge cache (entire zone or specific files/tags/hosts)
- Get zone analytics (requests, bandwidth, threats)
Installation
Prerequisites
- Python 3.10 or higher
- uv installed
- A Cloudflare account with an API token
Quick Start with uv
- Clone or create the project:
mkdir cloudflare-mcp-server
cd cloudflare-mcp-server
- Install with uv:
uv pip install -e .
Or install from the directory:
uv pip install cloudflare-mcp-server
Alternative: Using pip
pip install -e .
Configuration
Getting Your Cloudflare Credentials
-
API Token (Required):
- Go to Cloudflare Dashboard
- Click "Create Token"
- Use "Edit zone DNS" template or create a custom token with the permissions you need
- Copy the token
-
Account ID (Optional, but required for KV operations):
- Go to your Cloudflare dashboard
- Select any website
- Scroll down on the Overview page to find your Account ID
Environment Variables
Set the following environment variables:
export CLOUDFLARE_API_TOKEN="your_api_token_here"
export CLOUDFLARE_ACCOUNT_ID="your_account_id_here" # Optional, needed for KV
Or create a .env file (see .env.example).
Claude Desktop Configuration
Add to your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Using uv (recommended):
{
"mcpServers": {
"cloudflare": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/cloudflare-mcp-server",
"run",
"cloudflare-mcp-server"
],
"env": {
"CLOUDFLARE_API_TOKEN": "your_api_token_here",
"CLOUDFLARE_ACCOUNT_ID": "your_account_id_here"
}
}
}
}
Using Python directly:
{
"mcpServers": {
"cloudflare": {
"command": "python",
"args": ["-m", "cloudflare_mcp_server"],
"env": {
"CLOUDFLARE_API_TOKEN": "your_api_token_here",
"CLOUDFLARE_ACCOUNT_ID": "your_account_id_here"
}
}
}
}
Available Tools
The server provides 13 powerful tools for managing Cloudflare resources:
Zone Operations
list_zones- List all zones (domains) with optional filteringget_zone- Get detailed information about a specific zone
DNS Operations
list_dns_records- List DNS records with filteringcreate_dns_record- Create new DNS recordsupdate_dns_record- Update existing DNS recordsdelete_dns_record- Delete DNS records
Cache Operations
purge_cache- Purge cached content (entire zone or specific files/tags/hosts)
Workers KV Operations
list_kv_namespaces- List all KV namespacesread_kv_value- Read a value from KV storagewrite_kv_value- Write a key-value pair to KVdelete_kv_value- Delete a key from KVlist_kv_keys- List all keys in a namespace
Analytics
get_zone_analytics- Get analytics data for a zone
For detailed documentation on each tool, see EXAMPLES.md.
Development
Using uv for Development
# Install in development mode with dev dependencies
uv pip install -e ".[dev]"
# Run the server directly
uv run cloudflare-mcp-server
# Run tests (when implemented)
uv run pytest
# Format code with ruff
uv run ruff format src/
# Lint code
uv run ruff check src/
Project Structure
cloudflare-mcp-server/
├── src/
│ └── cloudflare_mcp_server/
│ └── __init__.py # Main server implementation
├── tests/ # Tests (to be implemented)
├── pyproject.toml # Project configuration (uv-compatible)
├── README.md # This file
├── QUICKSTART.md # Quick start guide
├── EXAMPLES.md # Usage examples
└── .env.example # Environment template
Usage Examples
Example 1: List Your Zones
Ask Claude:
"Show me all my Cloudflare zones"
Example 2: Create a DNS Record
Ask Claude:
"Create an A record for api.example.com pointing to 192.0.2.100 with proxy enabled"
Example 3: Purge Cache
Ask Claude:
"Clear the cache for https://example.com/style.css"
For more examples, see EXAMPLES.md.
API Permissions
Your Cloudflare API token needs appropriate permissions based on what operations you want to perform:
Minimum Permissions:
- Zone - Zone - Read (for listing zones)
- Zone - DNS - Edit (for DNS operations)
Additional Permissions for Advanced Features:
- Account - Workers KV Storage - Edit (for KV operations)
- Zone - Cache Purge - Purge (for cache operations)
- Zone - Analytics - Read (for analytics)
Troubleshooting
Common Issues
-
"CLOUDFLARE_API_TOKEN environment variable is required"
- Make sure you've set the environment variable
- Check your Claude Desktop config has the correct token in the
envsection
-
"Account ID is required"
- Set
CLOUDFLARE_ACCOUNT_IDenvironment variable for KV operations - Or pass
account_idparameter directly in tool calls
- Set
-
uv command not found
- Install uv:
curl -LsSf https://astral.sh/uv/install.sh | sh - Or use pip as an alternative
- Install uv:
-
Module not found errors
- Make sure you installed the package:
uv pip install -e . - Check you're in the right directory
- Make sure you installed the package:
Why uv?
This project uses uv because it's:
- ⚡ 10-100x faster than pip
- 🔒 More reliable with better dependency resolution
- 🎯 Simpler - one tool for everything
- 🐍 Modern - built in Rust, designed for Python
Security Notes
- Never commit your API token to version control
- Store tokens securely using environment variables
- Use API tokens instead of API keys (they're more secure and can be scoped)
- Regularly rotate your API tokens
- Use the minimum required permissions for your token
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE file for details.
Links
Support
For issues related to:
- This MCP server: Open an issue on GitHub
- Cloudflare API: Check Cloudflare Developer Docs
- MCP Protocol: Check MCP Documentation
- uv: Check uv Documentation
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。