Cloudflare MCP Server
镜像
简介
Cloudflare MCP 服务器允许您通过自然语言使用 Claude Desktop 或其他 MCP 客户端操作 Cloudflare 账户,管理 Workers、KV 存储、R2 存储和 D1 数据库等资源。
安装与设置
npx @cloudflare/mcp-server-cloudflare init
重启 Claude Desktop 后,您将看到一个 🔨 图标,表示 Cloudflare 工具已可用。
核心功能
Workers
// 列出所有 Workers
worker_list()
// 创建或更新 Worker
worker_put({
name: "my-worker",
script: "export default { async fetch(request, env, ctx) { ... }}",
bindings: [
{
type: "kv_namespace",
name: "MY_KV",
namespace_id: "abcd1234"
}
],
compatibility_date: "2024-01-01"
})
KV 存储
// 列出所有 KV 命名空间
get_kvs()
// 存储值
kv_put({
namespaceId: "your_namespace_id",
key: "myKey",
value: "myValue"
})
// 获取值
kv_get({
namespaceId: "your_namespace_id",
key: "myKey"
})
R2 存储
// 列出存储桶
r2_list_buckets()
// 创建存储桶
r2_create_bucket({ name: "my-bucket" })
// 上传对象
r2_put_object({
bucket: "my-bucket",
key: "folder/file.txt",
content: "Hello, World!",
contentType: "text/plain"
})
D1 数据库
// 列出数据库
d1_list_databases()
// 执行查询
d1_query({
databaseId: "your_database_id",
query: "SELECT * FROM users WHERE age > ?",
params: ["25"]
})
开发模式
# 安装依赖并运行开发服务器
pnpm install
pnpm build:watch
# 在另一个终端中初始化
node dist/index.js init
直接使用服务器
本地运行服务器:
node dist/index run <account-id>
使用 tools/list
命令获取所有可用工具,然后通过 tools/call
调用它们。
更多详细信息请访问 MCP 协议官方文档。