Back to MCP directory
publicPublicdnsLocal runtime

remote-mcp-server

该项目展示了如何在Cloudflare Workers上部署远程MCP服务器,并通过OAuth登录实现安全访问。支持本地开发调试、与MCP检查器和Claude桌面客户端的连接,最终可部署至Cloudflare云端。

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

你可以在浏览器中打开 http://localhost:8787/ 查看效果。

💻 使用示例

将 MCP Inspector 连接到你的服务器

要探索新的 MCP API,你可以使用 MCP Inspector

  • 使用 npx @modelcontextprotocol/inspector 启动它。
  • 在Inspector中,切换传输类型为 SSE,并在 URL 中输入 http://localhost:8787/sse 以连接到你的 MCP 服务器,然后点击“连接”。
  • 你将进入一个(模拟的)用户/密码登录页面。输入任何电子邮件和密码进行登录。
  • 成功登录后,你应该会被重定向回 MCP Inspector,并且可以列出并调用任何定义的工具!

将 Claude Desktop 连接到本地 MCP 服务器

MCP Inspector 非常有用,但我们更希望将其与 Claude 连接!按照 Anthropic 的快速入门指南,在 Claude Desktop 中转到 设置 > 开发者 > 编辑配置,找到你的配置文件。 用文本编辑器打开该文件,并替换为以下配置:

{
  "mcpServers": {
    "math": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:8787/sse"
      ]
    }
  }
}

这将运行一个本地代理,使 Claude 能够通过 HTTP 与你的 MCP 服务器通信。 当你打开 Claude 时,浏览器窗口应该会打开,并允许你登录。你应该会在右下角看到可用的工具。根据提示,Claude 应该会要求调用工具来回答问题。

部署到 Cloudflare

  1. npx wrangler kv namespace create OAUTH_KV
  2. 按照指南将kv命名空间ID添加到 wrangler.jsonc
  3. npm run deploy

从远程 MCP 客户端调用你的新部署的远程 MCP 服务器

就像在“本地开发”部分所做的那样,运行 MCP Inspector: npx @modelcontextprotocol/inspector@latest 然后在Inspector中输入你的 Worker 的 workers.dev URL(例如:worker-name.account-name.workers.dev/sse)作为 MCP 服务器的 URL,并点击“连接”。 你已经通过远程 MCP 客户端连接到了你的 MCP 服务器。

将 Claude Desktop 连接到你的远程 MCP 服务器

更新 Claude 配置文件,使其指向你的 workers.dev URL(例如:https://worker-name.account-name.workers.dev/sse),然后重启 Claude。

{
  "mcpServers": {
    "math": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://worker-name.account-name.workers.dev/sse"
      ]
    }
  }
}
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client