Remote MCP Server (远程模型上下文协议服务器)
一个适用于 Cloudflare Workers 的模型上下文协议服务器,集成了 Claude AI,通过 OAuth 登录和 SSE 连接启用工具使用。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"math": {
"args": [
"mcp-remote",
"http://localhost:8787/sse"
],
"command": "npx"
}
}
}
服务介绍
Snappy MCP 服务器与 Xano 集成
基于 Cloudflare Workers 构建的远程 MCP 服务器,集成了 Xano 数据库,用于工具管理、会话跟踪和 OAuth。
本地开发
# clone the repository
git clone https://github.com/roboulos/remote-mcp-server.git
# install dependencies
cd remote-mcp-server
npm install
# Configure Xano API Key
# Add your Xano API key to wrangler.jsonc in the XANO_API_KEY variable
# run locally
npm run dev
你应该能够在浏览器中打开 http://localhost:8787/
将 MCP 检查器连接到你的服务器
要探索你的新 MCP API,你可以使用 MCP Inspector。
- 使用
npx @modelcontextprotocol/inspector启动它 - 在检查器内,将传输类型切换为
SSE并输入http://localhost:8787/sse作为要连接的 MCP 服务器的 URL,然后点击“连接” - 你将导航到一个(模拟)用户名/密码登录屏幕。输入任何电子邮件和密码进行登录。
- 你应该会被重定向回 MCP Inspector,现在你可以列出并调用任何已定义的工具!
将 Claude Desktop 连接到你的本地 MCP 服务器
MCP 检查器很棒,但我们真正想做的是将其连接到 Claude!请遵循 Anthropic 的快速入门指南,并在 Claude Desktop 中转到设置 > 开发者 > 编辑配置以找到你的配置文件。
在文本编辑器中打开该文件,并将其替换为此配置:
{
"mcpServers": {
"math": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8787/sse"
]
}
}
}
这将运行一个本地代理,并让 Claude 通过 HTTP 与你的 MCP 服务器通信
当你打开 Claude 时,应该会打开一个浏览器窗口并允许你登录。你应该能在右下角看到可用的工具。给定正确的提示,Claude 应该会询问是否调用工具。
Xano 集成
此 MCP 服务器使用 Xano 作为后端,用于:
- 工具管理:在 Xano 的
____mcp_tools表中定义工具,它们将自动注册到 MCP 服务器 - 会话跟踪:所有 MCP 会话都在
___mcp_sessions表中跟踪 - OAuth 身份验证:OAuth 令牌和状态存储在 Xano 的
___oauth_tokens和___oauth_states表中 - 日志记录:所有 MCP 请求都记录在
___mcp_logs表中
设置 Xano
- 创建一个包含所需表的 Xano 项目(参见数据库模式)
- 创建以下 API 端点:
/api/tools- GET - 列出所有工具/api/tools/execute/{tool_name}- POST - 执行特定工具/api/sessions- POST - 创建新会话/api/sessions/update-activity- PUT - 更新会话活动/api/oauth/tokens- POST - 存储 OAuth 令牌/api/oauth/tokens/{user_id}/{provider}- GET - 获取 OAuth 令牌/api/oauth/states- POST - 存储 OAuth 状态/api/oauth/states/{state}- GET - 验证 OAuth 状态/api/logs- POST - 记录 MCP 请求
部署到 Cloudflare
npx wrangler kv namespace create OAUTH_KV- 按照指引将 kv 命名空间 ID 添加到
wrangler.jsonc - 将你的 Xano API 密钥添加到
wrangler.jsonc中的XANO_API_KEY变量 npm run deploy
从远程 MCP 客户端调用你新部署的远程 MCP 服务器
就像你在“本地开发”中所做的那样,运行 MCP 检查器:
npx @modelcontextprotocol/inspector@latest
然后在检查器中输入你的 Worker 的 workers.dev URL(例如:worker-name.account-name.workers.dev/sse)作为要连接的 MCP 服务器的 URL,并点击“连接”。
现在你已经从远程 MCP 客户端连接到了你的 MCP 服务器。
将 Claude Desktop 连接到你的远程 MCP 服务器
更新 Claude 配置文件以指向你的 workers.dev URL(例如:worker-name.account-name.workers.dev/sse),并重启 Claude
{
"mcpServers": {
"math": {
"command": "npx",
"args": [
"mcp-remote",
"https://worker-name.account-name.workers.dev/sse"
]
}
}
}
调试
如果出现问题,重新启动 Claude 或尝试使用以下命令直接从命令行连接到你的 MCP 服务器可能会有所帮助。
npx mcp-remote http://localhost:8787/sse
在某些罕见情况下,清除添加到 ~/.mcp-auth 的文件可能有所帮助。
rm -rf ~/.mcp-auth