article
README
🚀 在 Cloudflare 上搭建远程 MCP 服务器
本项目可以帮助你在 Cloudflare Workers 上启动一个运行良好的远程 MCP 服务器,并集成 OAuth 登录功能!
🚀 快速开始
📦 安装指南
本地开发
# 克隆仓库
git clone git@github.com:cloudflare/ai.git
# 安装依赖项
cd ai
npm install
# 本地运行
npx nx dev remote-mcp-server-bearer-auth
你应该能够打开 http://localhost:8787/ 在浏览器中查看。
部署到 Cloudflare
npm run deploy
💻 使用示例
将 MCP 检查器连接到你的服务器
要探索新的 MCP API,你可以使用 MCP Inspector。
- 使用
npx @modelcontextprotocol/inspector启动它。 - 在检查器中(例如:http://localhost:5173),切换传输类型为
SSE,并在 URL 中输入http://localhost:8787/sse作为 MCP 服务器地址,然后点击“连接”。 - 添加一个 bearer token 并点击“连接”。
- 点击“列出工具”。
- 运行“getToken”工具,它应该返回你在检查器中设置的 Authorization 头。
将 Claude Desktop 连接到你的本地 MCP 服务器
"remote-example": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8787/sse",
"--header",
"Authorization: Bearer {token}"
]
}
从远程 MCP 客户端调用你的新远程 MCP 服务器
就像在“本地开发”中一样,运行 MCP 检查器:
npx @modelcontextprotocol/inspector@latest
然后在检查器中输入你 Worker 的 workers.dev URL(例如:worker-name.account-name.workers.dev/sse)作为 MCP 服务器地址,并点击“连接”。
你现在已将 MCP 服务器连接到远程 MCP 客户端。你可以像上面提到的那样传递 bearer token。
将 Claude Desktop 连接到你的远程 MCP 服务器
TODO:我们需要支持任意头文件到 mcp-remote 代理
🔧 调试
如果遇到任何问题,重新启动 Claude 或直接通过以下命令连接到你的 MCP 服务器可能会有帮助。
npx mcp-remote http://localhost:8787/sse
在极少数情况下,清除 ~/.mcp-auth 目录中的文件可能有所帮助:
rm -rf ~/.mcp-auth
微信扫一扫