在 Cursor 中 配置 GitHub MCP Server

1、简单回顾 sequentialthinking 的安装

我们已经在上一篇文章中安装了 sequentialthinking MCP
这个 MCP 是一个可以自己思考并且自主调度其它 MCP Tool

2、提出问题:如何在 cursor 配置 github mcp 呢

在 sequentialthinking MCP server 状态正常的前提下
在 agent 模式下提出问题:如何在 cursor 配置 github mcp 呢
可以看到,自动调用了 MCP tool sequentialthinking,思考了 5 步
在这里插入图片描述

3、结果如下

How to Configure GitHub MCP in Cursor

GitHub MCP (Model Context Protocol) integration in Cursor allows you to interact with
GitHub directly from your IDE, enabling features like creating PRs,
branches, finding code, and more. Here’s a step-by-step guide to set it up:

Prerequisites

  1. Make sure you have the latest version of Cursor installed (0.46 or later)
  2. A GitHub account with repositories you want to connect to

Step 1: Update Cursor (if needed)

Some users report not seeing the MCP section in older versions of Cursor. If you don’t see it, update to the latest version.

Step 2: Generate a GitHub Personal Access Token

  1. Go to GitHub and navigate to SettingsDeveloper SettingsPersonal Access TokensTokens (classic)
  2. Click Generate New Token (classic)
  3. Give your token a descriptive name (e.g., “Cursor MCP Integration”)
  4. Select the necessary scopes (recommended: repo, workflow)
  5. Click Generate Token and copy the token immediately (you won’t be able to see it again)

Step 3: Open Cursor MCP Settings

  1. Open Cursor
  2. Use the keyboard shortcut Cmd + Shift + J (Mac) or open Cursor settings through the menu
  3. Look for the MCP tab in the settings sidebar

Note: Don’t use the VS Code settings shortcut (Cmd + ,), as it won’t show the MCP section.

Step 4: Add GitHub MCP Server

There are two main ways to configure GitHub MCP:

Option 1: Using Smithery (Recommended)

  1. Visit Smithery
  2. Locate the GitHub MCP tool
  3. Paste your GitHub Personal Access Token
  4. Click Generate Command and copy the command provided

Option 2: Manual Configuration

Create a .cursor/mcp.json file in your project directory (for project-specific configuration) or ~/.cursor/mcp.json in your home directory (for global configuration) with the following content:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "mcp-server-github"],
      "env": {
        "GITHUB_TOKEN": "your-github-token-here"
      }
    }
  }
}

Replace your-github-token-here with your actual GitHub token.

Step 5: Add the MCP Server in Cursor

  1. Go back to Cursor Settings → MCP
  2. Click Add New MCP Server
  3. Enter a name (e.g., “GitHub MCP”)
  4. Set Type to Command
  5. Paste the command copied from Smithery or use your custom command
  6. Click Add
  7. Click Refresh - the GitHub MCP tool should appear in the list of tools

Step 6: Test the GitHub MCP Integration

  1. Open Cursor Chat
  2. Ask the AI assistant to perform a GitHub-related task, such as:
    • “Create a new branch called feature/test-mcp”
    • “List my recent commits”
    • “Check the status of my current repository”

Troubleshooting

  • MCP section not visible: Update Cursor to the latest version
  • “Client closed” error: Try restarting Cursor or check your GitHub token
  • No tools found: Make sure your GitHub token has the correct permissions
  • Connection issues: Check your internet connection and GitHub status

By following these steps, you should be able to successfully configure GitHub MCP in Cursor and start leveraging its powerful GitHub integration features to streamline your development workflow.

4、操作

Step4 中我们选择 Option1
需要注意的是,

  • token 获取方法:Settings/Developer settings/Personal access tokens (直接跳转 token 配置页)
    此外,需要按照细节权限选择授权的范围,默认都是不允许,此时获取token 是没有意义的
    在这里插入图片描述

  • Github 最火爆的 MCP server (直接跳转 github MCP 页面)

  • 首次进来,把 token 粘贴进去,点击 Connect
    在这里插入图片描述

  • 选择 Cursor,Copy 获取得到

npx -y @smithery/cli@latest install @smithery-ai/github --client cursor --config '"{\"githubPersonalAccessToken\":\"aaaaaaaaaa\"}"' --key xxxxxxxx-f937-4a71-b723-ccxxxxxxxxxx

在这里插入图片描述

  • 去Cursor 配置 github MCP Server

有一定概率网络不通, 解决网络问题 里有提到过如何处理

把下面 @smithery/cli@latest 替换为 github MCP 开源项目 说明中的服务器地址

npx -y @smithery/cli@latest install @smithery-ai/github --client cursor --config '"{\"githubPersonalAccessToken\":\"github_pat_aaaaaaaaaa\"}"' --key xxxxxxxx-f937-4a71-b723-ccxxxxxxxxxx

变为

npx -y @modelcontextprotocol/server-github install @smithery-ai/github --client cursor --config '"{\"githubPersonalAccessToken\":\"github_pat_aaaaaaaaaa\"}"' --key xxxxxxxx-f937-4a71-b723-ccxxxxxxxxxx

在这里插入图片描述
在这里插入图片描述

  • Cursor 选择 command 类型
    在这里插入图片描述

5、配置成功

npx -y @modelcontextprotocol/server-github install @smithery-ai/github --client cursor --config '"{\"githubPersonalAccessToken\":\"github_pat_aaaaaaaaaa\"}"' --key xxxxxxxx-f937-4a71-b723-ccxxxxxxxxxx

在这里插入图片描述
在这里插入图片描述

6、测试下新建分支

还提示我确认下用户名一类的
在这里插入图片描述

7、低版本 cursor 只支持 json格式配置MCP

可以直接用下面的内容整体复制
在这里插入图片描述
配置完如下
在这里插入图片描述
在这里插入图片描述

<think>嗯,用户提到在WSL中使用Tab键进行命令联想时会卡死,但路径补全正常。首先,我需要理解问题的具体情况。可能的原因有很多,我需要一步步分析。 首先,考虑WSL版本。用户可能使用的是WSL1,因为WSL1和WSL2在处理文件系统时有差异。WSL1的I/O性能较差,尤其是访问Windows文件系统时,可能导致Tab补全卡顿。这时候建议用户升级到WSL2,看看是否有改善。 接下来,检查自动补全相关的配置文件,比如.bashrc或.zshrc。如果用户自定义了一些补全脚本,可能存在冲突或者效率低下的代码。例如,某些插件或者别名可能加载缓慢。这时候建议用户备份配置文件后,暂时注释掉部分代码,逐步排查问题。 然后,考虑文件系统的问题。如果当前目录包含大量文件或符号链接,Tab补全时需要枚举所有文件,可能导致延迟甚至卡死。这时候可以建议用户切换到其他目录测试,或者调整目录结构减少文件数量。 另外,Bash版本或补全包的问题也可能导致卡顿。建议用户更新bash和bash-completion包,确保使用的是最新版本。如果问题依旧,尝试重新安装这些包。 还有可能是第三方工具的影响,比如防病毒软件或者Windows的实时保护功能在扫描WSL进程,导致延迟。可以建议用户暂时禁用这些安全软件,测试是否有改善。 资源不足也是一个可能的原因,比如内存或CPU占用过高。检查系统资源使用情况,关闭不必要的程序,释放资源。 如果上述方法都无效,可能需要重置WSL环境或者创建新的发行版实例来测试是否是环境损坏导致的问题。 最后,建议用户根据具体情况逐一尝试这些解决方案,定位问题根源。如果还是无法解决,提供详细的日志或错误信息会有助于进一步诊断。</think>关于WSL中按Tab键进行命令联想卡死但路径补全正常的问题,以下是逐步分析及解决方案: --- ### **1. 问题定位** 首先需明确卡死现象的特征: - **仅命令联想卡死**:如输入`git`后按Tab补全子命令时卡顿 - **路径补全正常**:如输入`cd /u`按Tab补全为`/usr/`时正常 - **可能伴随高CPU/内存占用** --- ### **2. 常见原因** #### **(1) WSL文件系统差异** - **WSL1与WSL2差异**: - WSL1的`/mnt/`目录(挂载的Windows驱动器)I/O性能较差 - 在Windows目录下执行补全时,文件枚举速度慢 - ✅ 解决方案:迁移到WSL2(执行`wsl --set-version <发行版> 2`) #### **(2) 自动补全配置冲突** - **Bash补全包问题**: - 某些第三方补全脚本(如`bash-completion`)可能存在低效代码 - 自定义的`.bashrc`或`.zshrc`中添加了复杂补全逻辑 - ✅ 临时测试:新建一个用户环境测试 ```bash # 新建测试用户 sudo useradd testuser sudo -u testuser -i # 在新环境中尝试Tab补全 ``` #### **(3) 特殊符号链接** - **递归符号链接**: - 当前目录中存在循环符号链接(如`ln -s . loop`) - Tab补全会尝试遍历所有子目录 - ✅ 解决方案:检查并删除异常符号链接 --- ### **3. 分步排查** #### **步骤1:验证WSL版本** ```bash # 查看WSL版本 wsl.exe --list --verbose # 若为WSL1,建议升级到WSL2 wsl.exe --set-version <发行版名称> 2 ``` #### **步骤2:简化Shell配置** ```bash # 备份配置文件 cp ~/.bashrc ~/.bashrc.bak # 清空配置测试 echo "" > ~/.bashrc # 重新加载环境 exec bash ``` #### **步骤3:检查补全包状态** ```bash # 更新软件包 sudo apt update && sudo apt upgrade -y # 重新安装bash-completion sudo apt install --reinstall bash-completion ``` --- ### **4. 高级调试** #### **(1) 追踪补全过程** ```bash # 启用调试模式 set -x # 执行补全操作(观察输出卡顿点) set +x # 关闭调试 ``` #### **(2) 检查系统日志** ```bash # 查看内核日志(需Windows端配合) dmesg | grep -i "error" ``` --- ### **5. 替代方案** 如果问题仍未解决,可尝试: 1. **切换Shell**:改用`zsh`+`oh-my-zsh` ```bash sudo apt install zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ``` 2. **手动补全工具**:使用`fzf`模糊搜索 ```bash sudo apt install fzf # 绑定Ctrl+R搜索历史命令 ``` --- ### **总结建议** | 现象 | 优先级 | 解决方案 | |------|--------|----------| | WSL1下操作Windows目录卡顿 | 高 | 升级到WSL2 | | 自定义配置冲突 | 中 | 清理`.bashrc` | | 文件系统异常 | 低 | 检查符号链接 | 若以上方法无效,建议提供以下信息进一步诊断: - WSL发行版名称及版本(Ubuntu 22.04? Debian?) - 执行`echo $BASH_VERSION`的输出 - 卡顿时使用`top`命令的CPU/内存占用截图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值