A server for hosting Model Context Protocol (MCP) tools on Cloudflare Workers with OAuth authentication, allowing Claude AI and other MCP clients to access extended capabilities.
这是一个基于Cloudflare Worker的MCP (Model Context Protocol) 服务器,用于提供各种工具API,包括Gmail、Google Calendar等功能。该项目使用TypeScript开发,并使用@remote-mcp/server库来简化MCP服务器的实现。
# 克隆仓库 git clone https://github.com/yourusername/remote-mcp-server.git cd remote-mcp-server # 安装依赖 npm install
src/config.ts
文件中的 OAuth 配置export const GOOGLE_OAUTH_CONFIG = { clientId: '你的客户端ID', clientSecret: '你的客户端密钥', redirectUri: 'https://your-worker.your-subdomain.workers.dev/oauth/gmail/callback', scopes: [ 'https://www.googleapis.com/auth/gmail.send', 'https://www.googleapis.com/auth/gmail.readonly', 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events' ] };
对于生产环境,你需要配置KV命名空间来存储OAuth令牌:
wrangler.jsonc
中的KV配置部分,并添加你的命名空间ID:"kv_namespaces": [ { "binding": "OAUTH_KV", "id": "你的KV命名空间ID" } ]
# 运行开发服务器 npm run dev
# 构建并部署 npm run deploy
remote-mcp-server/
├── src/ # 源代码
│ ├── index.ts # 主入口文件
│ ├── config.ts # 配置文件
│ ├── services/ # 服务实现
│ │ └── google.ts # Google服务(Gmail, Calendar)
│ └── utils.ts # 工具函数
├── dist/ # 编译后的文件
├── static/ # 静态资源
├── build.js # 构建脚本
└── wrangler.jsonc # Cloudflare Workers配置
/tools
- 获取可用工具列表/api/mcp
- MCP API端点/oauth/gmail
- Gmail OAuth认证/oauth/gmail/callback
- Gmail OAuth回调wrangler.jsonc
中配置了正确的KV命名空间ID,或者暂时注释掉KV配置部分进行测试部署noEmit
设置为false
,允许生成JavaScript文件使用Cloudflare Workers控制台查看日志和调试信息。
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)MIT
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!