cloudflare-api-mcp
这是一个轻量级模型控制协议 (MCP) 服务器,由create-mcp引导并部署在 Cloudflare Workers 上。
该 MCP 服务器允许代理(例如 Cursor)与Cloudflare REST API进行交互。
它仍在开发中,当我发现自己需要时,我会添加更多工具。
可用工具
当前的工具列表请参阅src/index.ts 。该类中的每个方法都是一个 MCP 工具。
Related MCP server: Cloudflare MCP Server
安装
运行自动安装脚本来克隆此 MCP 服务器并将其部署到您的 Cloudflare 帐户:
bun create mcp --clone https://github.com/zueai/cloudflare-api-mcp
打开
Cursor Settings -> MCP -> Add new MCP server并将复制的命令粘贴到剪贴板。上传您的 Cloudflare API 密钥并通过电子邮件发送给您的工作人员机密:
bunx wrangler secret put CLOUDFLARE_API_KEY
bunx wrangler secret put CLOUDFLARE_API_EMAIL
本地开发
将您的 Cloudflare API 密钥和电子邮件添加到.dev.vars文件:
CLOUDFLARE_API_KEY=<your-cloudflare-api-key>
CLOUDFLARE_API_EMAIL=<your-cloudflare-api-email>
部署
运行部署脚本:
bun run deploy
重新加载“光标”窗口以查看新工具。
如何创建新的 MCP 工具
要创建新的 MCP 工具,请在src/index.ts中的MyWorker类中添加方法。每个函数都会自动成为代理可以使用的 MCP 工具。
例子:
/**
* Create a new DNS record in a zone.
* @param zoneId {string} The ID of the zone to create the record in.
* @param name {string} The name of the DNS record.
* @param content {string} The content of the DNS record.
* @param type {string} The type of DNS record (CNAME, A, TXT, or MX).
* @param comment {string} Optional comment for the DNS record.
* @param proxied {boolean} Optional whether to proxy the record through Cloudflare.
* @return {object} The created DNS record.
*/
createDNSRecord(zoneId: string, name: string, content: string, type: string, comment?: string, proxied?: boolean) {
// Implementation
}
JSDoc 注释很重要:
第一行成为工具的描述
@param标签定义工具的参数类型和描述@return标签指定返回值和类型