MCP Server with GitHub OAuth
模型上下文协议 (MCP) 服务器 + Github OAuth
这是一个支持远程 MCP 连接并内置 Github OAuth 的 模型上下文协议 (MCP) 服务器。
你可以将其部署到自己的 Cloudflare 账户中,在创建自己的 Github OAuth 客户端应用后,你将拥有一个功能完备的远程 MCP 服务器,并可以在此基础上进行开发。用户将能够通过使用其 GitHub 账户登录来连接到你的 MCP 服务器。
你可以将此作为参考示例,了解如何使用 workers-oauth-provider 库 将其他 OAuth 提供商与部署到 Cloudflare 的 MCP 服务器集成。
该 MCP 服务器(由 Cloudflare Workers 提供支持):
作为你 MCP 客户端的 OAuth 服务器
作为你 真实 OAuth 服务器(在本例中为 GitHub)的 OAuth 客户端
入门指南
直接克隆仓库并安装依赖:npm install。
或者,你可以使用下面的命令行在本地机器上创建远程 MCP 服务器:
npm create cloudflare@latest -- my-mcp-server --template=cloudflare/ai/demos/remote-mcp-github-oauth用于生产环境
创建一个新的 GitHub OAuth 应用:
对于主页 URL,指定
https://mcp-github-oauth.<your-subdomain>.workers.dev对于授权回调 URL,指定
https://mcp-github-oauth.<your-subdomain>.workers.dev/callback记录你的客户端 ID 并生成客户端密钥。
通过 Wrangler 设置密钥
wrangler secret put GITHUB_CLIENT_ID
wrangler secret put GITHUB_CLIENT_SECRET
wrangler secret put COOKIE_ENCRYPTION_KEY # add any random string here e.g. openssl rand -hex 32设置 KV 命名空间
创建 KV 命名空间:
wrangler kv:namespace create "OAUTH_KV"使用 KV ID 更新 Wrangler 文件
部署与测试
部署 MCP 服务器,使其在你的 workers.dev 域名上可用
wrangler deploy
使用 Inspector 测试远程服务器:
npx @modelcontextprotocol/inspector@latest输入 https://mcp-github-oauth.<your-subdomain>.workers.dev/sse 并点击连接。完成身份验证流程后,你将看到工具正常工作:
现在你已经部署了一个远程 MCP 服务器!
访问控制
此 MCP 服务器使用 GitHub OAuth 进行身份验证。所有经过身份验证的 GitHub 用户都可以访问诸如 "add" 和 "userInfoOctokit" 之类的基本工具。
"generateImage" 工具仅限于 ALLOWED_USERNAMES 配置中列出的特定 GitHub 用户:
// Add GitHub usernames for image generation access
const ALLOWED_USERNAMES = new Set([
'yourusername',
'teammate1'
]);从 Claude Desktop 访问远程 MCP 服务器
打开 Claude Desktop 并导航至 Settings -> Developer -> Edit Config。这将打开控制 Claude 可以访问哪些 MCP 服务器的配置文件。
将内容替换为以下配置。重启 Claude Desktop 后,将打开一个浏览器窗口显示你的 OAuth 登录页面。完成身份验证流程以授予 Claude 访问你 MCP 服务器的权限。授予访问权限后,工具即可供你使用。
{
"mcpServers": {
"math": {
"command": "npx",
"args": [
"mcp-remote",
"https://mcp-github-oauth.<your-subdomain>.workers.dev/sse"
]
}
}
}一旦工具(在 🔨 下方)出现在界面中,你就可以要求 Claude 使用它们。例如:“你能使用数学工具计算 23 加 19 吗?”。Claude 应该会调用该工具并显示由 MCP 服务器生成的结果。
用于本地开发
如果你想迭代和测试你的 MCP 服务器,可以在本地开发中进行。这需要你在 GitHub 上创建另一个 OAuth 应用:
对于主页 URL,指定
http://localhost:8788对于授权回调 URL,指定
http://localhost:8788/callback记录你的客户端 ID 并生成客户端密钥。
在项目根目录中创建一个
.dev.vars文件,内容如下:
GITHUB_CLIENT_ID=your_development_github_client_id
GITHUB_CLIENT_SECRET=your_development_github_client_secret开发与测试
在本地运行服务器,使其在 http://localhost:8788 可用
wrangler dev
要测试本地服务器,请在 Inspector 中输入 http://localhost:8788/sse 并点击连接。按照提示操作后,你将能够“列出工具”。
使用 Claude 和其他 MCP 客户端
当使用 Claude 连接到你的远程 MCP 服务器时,你可能会看到一些错误消息。这是因为 Claude Desktop 尚不支持远程 MCP 服务器,所以有时会出错。要验证 MCP 服务器是否已连接,请将鼠标悬停在 Claude 界面右下角的 🔨 图标上。你应该能看到你的工具在那里可用。
使用 Cursor 和其他 MCP 客户端
要将 Cursor 与你的 MCP 服务器连接,请选择 Type: "Command",并在 Command 字段中将命令和参数字段合并为一个(例如 npx mcp-remote https://<your-worker-name>.<your-subdomain>.workers.dev/sse)。
请注意,虽然 Cursor 支持 HTTP+SSE 服务器,但它不支持身份验证,因此你仍然需要使用 mcp-remote(并且要使用 STDIO 服务器,而不是 HTTP 服务器)。
你可以通过打开客户端的配置文件、添加与 Claude 设置相同的 JSON 并重启 MCP 客户端,将你的 MCP 服务器连接到 Windsurf 等其他 MCP 客户端。
Related MCP server: GitHub MCP Server
它如何工作?
许可证
本项目采用 GPL-3.0 许可证。详情请参阅 LICENSE 文件。
OAuth 提供商
OAuth 提供商库作为 Cloudflare Workers 的完整 OAuth 2.1 服务器实现。它处理 OAuth 流程的复杂性,包括令牌颁发、验证和管理。在本项目中,它扮演双重角色:
对连接到你服务器的 MCP 客户端进行身份验证
管理与 GitHub OAuth 服务的连接
在 KV 存储中安全地存储令牌和身份验证状态
持久化 MCP
Durable MCP 使用 Cloudflare 的 Durable Objects 扩展了基础 MCP 功能,提供:
为你的 MCP 服务器提供持久状态管理
在请求之间安全存储身份验证上下文
通过
this.props访问已验证用户信息支持基于用户身份的条件工具可用性
MCP 远程
MCP 远程库使你的服务器能够公开可由 Inspector 等 MCP 客户端调用的工具。它:
定义客户端与服务器之间的通信协议
提供定义工具的结构化方式
处理请求和响应的序列化与反序列化
维护客户端与服务器之间的服务器发送事件 (SSE) 连接
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityAmaintenanceA Model Context Protocol server for Git repository interaction and automation. This server provides tools to read, search, and manipulate Git repositories via Large Language Models.1289,977MIT
- FlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI models to interact with GitHub's API, allowing for repository creation and management with descriptions, topics, and website URLs through natural language commands.11
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that supports remote connections and authenticates users via GitHub OAuth, allowing them to access tools based on their GitHub identity.
- FlicenseNot gradedqualityNot gradedmaintenanceModel Context Protocol server that enables interaction with GitHub repositories, issues, pull requests, and search functionality through natural language.1
Related MCP Connectors
A MCP server built for developers enabling Git based project management with project and personal…
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
An MCP server that gives your AI access to the source code and docs of all public github repos
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/byjit/cloudflare-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server