关于 🔄 MCP + Cursor GitHub Setup
这是一份将 Cursor 连接到 MCP 服务并通过 GitHub 插件管理仓库的设置指南,面向需要在 Cursor 中执行 GitHub 操作的开发者。内容包括服务器配置、令牌设置及工具示例。
主要功能
- 01配置 Cursor 的 MCP 服务连接
- 02通过 mcp.json 配置服务器与令牌
- 03使用 GitHub 工具管理仓库
- 04通过提示词触发仓库操作
- 05提供终端命令示例
适用场景
- 01在 Cursor 中创建 GitHub 仓库
- 02搜索 GitHub 仓库
- 03读取或更新仓库文件
- 04通过命令行触发仓库操作
MCP 相关
指南说明如何将 Cursor 连接至本地 MCP 服务,并配置 GitHub 插件工具。连接后可在 Cursor 提示词栏或命令行中执行仓库操作。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
title: 连接 Cursor 与 MCP,实现 GitHub 控制
🔄 MCP + Cursor GitHub 配置
MCP 服务运行后,即可通过 Cursor 设置完整的 GitHub 控制。
🛠️ MCP 的 Cursor 分步配置
🧭 1. 打开 Cursor 编辑器
- 启动 Cursor,这是一款 AI 优先的代码编辑器。
- 点击 Settings(左下角 ⚙️)。
🌐 2. 前往 MCP 部分
- 在 Settings 中向下滚动至 MCP (Model Context Protocol) 部分。
- 点击 "Add Server"。
🔧 3. 填写 MCP 服务详情
- 名称:
Local MCP Server - URL:
http://localhost:3333(或server.js中配置的端口) - 客户端: 选择
ollama或你偏好的大模型引擎。 - 身份验证: 本地使用时(位于防火墙后)留空。若使用基于令牌的身份验证,请添加标头。
✅ Cursor 现已连接到你的 MCP 服务!
⚙️ 确保 MCP 服务正在运行
在终端中本地运行服务:
node server.js
预期输出:
✅ MCP server running at http://localhost:3333
🤖 使用 Cursor 提示词控制 GitHub
连接 MCP 后,使用 Cursor 命令面板:
⌘ + K / Ctrl + K → 输入:
Create a private GitHub repo named ai-lab
Add README.md to ai-lab repo with initial text
Search repositories about 'android hacking tools'
MCP GitHub 插件(
@smithery-ai/github)通过你的服务处理 GitHub API 调用。
✅ 通过 MCP 提供的 GitHub 工具
| 工具 | 描述 |
|---|---|
create_or_update_file | 创建或更新文件 |
create_repository | 创建新的 GitHub 仓库 |
delete_repository | 删除仓库(如支持) |
get_file_contents | 读取文件内容 |
search_repositories | 查找 GitHub 仓库 |
这些工具可以通过 Cursor 的提示词栏触发,也可以通过:
npx @smithery/cli
🧠 最佳实践提示
- 妥善保护你的
mcp.json(尤其是 GitHub 令牌)。 - 在生产环境中使用环境变量存储密钥。
- 使用以下命令测试服务连接:
curl http://localhost:3333
日志会显示工具调用和 API 响应,便于调试。
title: "MCP 服务 + GitHub Cursor 配置指南" description: "分步指南:配置 MCP 服务与 Cursor GitHub 集成,实现仓库自动化、创建、删除和提交控制。"
🚀 MCP 服务 + GitHub Cursor 集成
本教程将介绍如何使用 Cursor 配置 MCP 与 GitHub,并通过终端或自动化工作流控制仓库。
📦 前提条件
- 已安装 Node.js 和 npm
- 已为你的操作系统下载 Cursor 命令行工具
- 一个 GitHub 账户
- 配置了
@modelcontextprotocol/sdk的兼容 MCP 的 Agent
🔐 步骤 1:创建 GitHub 个人访问令牌
- 前往 GitHub 开发者设置
- 点击 "Fine-grained tokens" → Generate new token
- 设置:
- 名称:
just_think - 过期时间:2025 年 5 月 18 日(或你偏好的日期)
- 权限:
- 仓库:完整读写权限
- 用户:完整读写权限
- 名称:
- 立即复制令牌。之后将无法再次查看!
github_pat_11A4PP7FQ07lGRHVynbe5e_... (keep it secret!)
⚙️ 步骤 2:配置 mcp.json
{
"defaultClient": "ollama",
"ollama": {
"baseUrl": "http://localhost:11434",
"model": "llama2"
},
"github": {
"token": "<your_copied_github_token>"
},
"agent": {
"name": "DevOpsAgent",
"persona": "An automation assistant for GitHub repo management"
}
}
将其保存为项目文件夹中的 mcp.json。
💻 步骤 3:运行 MCP Studio 服务
// server.js
import { studio } from '@modelcontextprotocol/sdk/server/studio.js';
studio.run({
config: './mcp.json',
port: 3333
});
然后运行:
node server.js
🧠 步骤 4:将 Cursor 连接到 GitHub
npx -y @smithery/cli@latest install @smithery-ai/github --client claude --config mcp.json
这将安装 GitHub Cursor 适配器,并注册 mcp.json 中的令牌。
🔧 步骤 5:通过 Cursor 自动化仓库控制
使用终端创建、删除或管理 GitHub 仓库:
✅ 创建仓库
npx @smithery/cli ask "Create a new private repo called test-automation"
❌ 删除仓库
npx @smithery/cli ask "Delete the repo named old-project"
📥 提交代码
npx @smithery/cli ask "Commit all changes to the repo my-app with message 'Init commit'"
📚 使用场景
- 🚀 CI/CD 流水线 – 通过 GitHub Actions 部署工作流
- 🧠 大模型自动化 – Agent 可以触发仓库事件
- 🛡 安全 DevOps – 使用细粒度令牌来保障安全
- 🧰 全面开发自动化 – 无需手动点击,完全由终端驱动
📎 资源
如果你想要一个包含这些文件、可直接克隆的完整仓库,只需告诉我,我就会生成一个!
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。