cloudflare-mcp-smart-proxy
v1.1.1
Published
Smart proxy for Cloudflare MCP - routes tools to cloud or local execution
Maintainers
Readme
@cloudflare-mcp/smart-proxy
智能路由代理,自动将 MCP 工具请求路由到云端或本地执行。
功能特性
- ✅ 智能路由: 自动判断工具应该路由到云端还是本地
- ✅ 本地文件编辑: 支持读取、写入、差异编辑本地文件
- ✅ 云端工具集成: 无缝使用 Cloudflare MCP 的云端工具
- ✅ 统一接口: AI 看到的是合并后的工具列表
- ✅ 零配置: 通过 npx 自动安装和使用
工具路由规则
本地工具(直接执行)
read_file- 读取本地文件write_file- 写入本地文件edit_file- 差异编辑本地文件list_dir- 列出本地目录delete_file- 删除本地文件execute_command- 执行本地命令
云端工具(转发到 Cloudflare Workers)
web_search- 网络搜索github_*- GitHub API 操作memory_*- 记忆工具library_docs- 库文档查询codebase_search- R2 代码库搜索- 其他所有未匹配的工具
安装
方法 1: 使用安装脚本(推荐)
curl -fsSL https://raw.githubusercontent.com/your-repo/local-proxy/main/install.sh | bash或下载后执行:
chmod +x install.sh
./install.sh方法 2: 手动配置
- 在 Cursor 配置文件中添加:
~/.cursor/mcp.json (macOS/Linux)
%APPDATA%\Cursor\mcp.json (Windows)
{
"mcpServers": {
"cloudflare-mcp": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cloudflare-mcp/smart-proxy"],
"env": {
"CLOUDFLARE_MCP_URL": "https://your-worker.workers.dev",
"CLOUDFLARE_MCP_API_KEY": "your_api_key_here",
"WORKSPACE_ROOT": "/path/to/your/workspace"
}
}
}
}- 重启 Cursor IDE
环境变量
| 变量名 | 必需 | 说明 |
|--------|------|------|
| CLOUDFLARE_MCP_URL | ✅ | Cloudflare MCP 服务器 URL |
| CLOUDFLARE_MCP_API_KEY | ✅ | API Key |
| WORKSPACE_ROOT | ❌ | 工作目录根路径(默认: 当前目录) |
使用示例
读取本地文件
{
"tool": "read_file",
"params": {
"target_file": "src/index.js",
"offset": 0,
"limit": 50
}
}差异编辑文件
{
"tool": "edit_file",
"params": {
"path": "src/index.js",
"edits": [
{
"type": "replace",
"startLine": 10,
"endLine": 12,
"oldText": "const x = 1;\nconst y = 2;",
"newText": "const x = 1;\nconst y = 3;\nconst z = 4;"
}
],
"originalContent": "..."
}
}执行本地命令
{
"tool": "execute_command",
"params": {
"command": "npm test",
"cwd": "."
}
}安全特性
- ✅ 路径验证:防止路径遍历攻击
- ✅ 工作目录限制:只能访问指定目录内的文件
- ✅ 命令黑名单:禁止执行危险命令
- ✅ 超时保护:命令执行 30 秒超时
故障排除
问题 1: 无法连接到云端服务器
检查:
- 确认
CLOUDFLARE_MCP_URL正确 - 确认
CLOUDFLARE_MCP_API_KEY有效 - 检查网络连接
问题 2: 本地文件操作失败
检查:
- 确认文件路径在工作目录内
- 检查文件权限
- 确认路径不包含
..
问题 3: Cursor 无法识别服务器
检查:
- 重启 Cursor IDE
- 检查配置文件 JSON 格式
- 查看 Cursor 开发者工具中的错误日志
开发
本地测试
cd local-proxy
npm install
export CLOUDFLARE_MCP_URL="https://your-worker.workers.dev"
export CLOUDFLARE_MCP_API_KEY="your_key"
export WORKSPACE_ROOT="/path/to/workspace"
node index.js发布到 npm
npm login
npm publish --access public许可证
MIT
