Gitcode MCP Server 是 Gitcode 推出的模型上下文协议(Model Context Protocol)服务实现,旨在通过标准化协议将 AI 助手深度集成到代码管理流程中。它允许开发者通过 AI 编程工具(如 Cursor、Windsurf 等)直接操作代码仓库资源,实现智能化开发协作
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 9 个月前 | ||
| 6 个月前 | ||
| 6 个月前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 6 个月前 | ||
| 1 年前 | ||
| 9 个月前 | ||
| 1 年前 | ||
| 6 个月前 |
GitCode MCP 服务器
这是一个基于 Model Context Protocol (MCP) 的 GitCode 集成服务器,允许 Cursor、Windsurf 等 IDE 无缝接入 GitCode 的功能。
功能
- 仓库管理:查看、创建、编辑仓库
- 分支管理:查看、创建、切换分支
- Issue 跟踪:查看、创建、更新 Issue
- Pull Request:查看、创建、评论 PR
- 搜索功能:搜索仓库、代码、Issues 等
安装
方法一:使用 pip 安装
# 从源码安装
pip install -e .
安装后可以直接使用命令行工具:
gitcode-mcp
gitcode
方法二:手动安装依赖
pip install -r requirements.txt
使用方法
- 设置环境变量(或者创建
.env文件):
GITCODE_TOKEN=your_personal_access_token
# 可选:如果需要使用代理
HTTP_PROXY=http://localhost:8080
HTTPS_PROXY=https://localhost:8080
- 运行服务器:
python -m gitcode_mcp
- 使用 CLI 直接操作 GitCode:
gitcode auth status
gitcode repo list
gitcode repo view owner/repo
gitcode issue create owner/repo --title "Bug report" --body "Steps to reproduce"
gitcode pr create owner/repo --title "Ship feature" --head feature-branch --base main --body "Ready for review"
gitcode search repos mcp server
gitcode api GET /user/repos --field per_page=20 --json
- 在支持 MCP 的 IDE 中配置服务器连接
代理支持
GitCode MCP 支持通过 HTTP/HTTPS 代理访问 GitCode API。您可以通过以下方式配置代理:
方式一:环境变量
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
方式二:在 MCP 配置文件中设置
{
"mcpServers": {
"gitcode": {
"command": "python",
"args": ["-m", "gitcode_mcp"],
"env": {
"GITCODE_TOKEN": "your_personal_access_token_here",
"HTTP_PROXY": "http://proxy.example.com:8080",
"HTTPS_PROXY": "http://proxy.example.com:8080"
}
}
}
}
支持的代理格式:
http://proxy.example.com:8080- 基础 HTTP 代理http://user:password@proxy.example.com:8080- 带认证的代理socks5://proxy.example.com:1080- SOCKS5 代理(需要安装aiohttp-socks)
在 Cursor 中接入
Cursor 支持通过 MCP 协议连接到外部服务器。按照以下步骤在 Cursor 中接入 GitCode:
方法一:项目级配置(仅对当前项目生效)
- 在项目根目录创建
.cursor/mcp.json文件,内容如下:{ "mcpServers": { "gitcode": { "command": "python", "args": ["-m", "gitcode_mcp"], "env": { "GITCODE_TOKEN": "your_personal_access_token_here" } } } }
方法二:全局配置(对所有项目生效)
-
在用户主目录创建
~/.cursor/mcp.json文件,内容如上。 -
启动或重启 Cursor
-
使用 GitCode 功能
- 使用
/命令可访问 GitCode 相关功能 - 或直接告诉 AI 助手使用 GitCode 工具完成任务
- 使用
配置文件示例: 在 examples/cursor_config.json 中提供了 Cursor 的配置示例,可以作为参考。
在 Windsurf 中接入
Windsurf 同样支持 MCP 协议。按照以下步骤设置:
方法一:使用配置文件
-
创建或编辑 Windsurf 的 MCP 配置文件,添加以下内容:
{ "mcpServers": { "gitcode": { "command": "python", "args": ["-m", "gitcode_mcp"], "env": { "GITCODE_TOKEN": "your_personal_access_token_here" } } } } -
确保 GitCode MCP 服务器已安装
pip install -e . -
启动或重启 Windsurf
-
使用 GitCode 功能
- 在编辑器中通过命令面板访问 GitCode 功能
- 或直接告诉 AI 助手使用 GitCode 工具完成任务
配置文件示例: 在 examples/windsurf_config.json 中提供了 Windsurf 的配置示例,可以作为参考。
方法二:通过设置界面(旧版本)
如果您使用的是不支持新配置格式的旧版 Windsurf,可以通过以下步骤设置:
-
确保 GitCode MCP 服务器已启动
python -m gitcode_mcp -
打开 Windsurf 设置面板
- 点击右上角菜单或使用快捷键进入设置
-
找到 AI 扩展或 MCP 服务器配置部分
- 选择 "添加新服务器" 或类似选项
-
配置服务器连接
- 连接类型: stdio
- 命令:
python -m gitcode_mcp - 服务器名称: GitCode
- 环境变量: 添加
GITCODE_TOKEN=your_token_here
-
保存并启用服务器
- 启用后,Windsurf 应该会显示连接状态
排查问题
如果连接失败,请检查:
- GitCode MCP 服务器是否正在运行
- 个人访问令牌是否正确设置
- IDE 中的路径配置是否正确(确保 Python 和模块可访问)
- 查看服务器日志以获取更多信息
开发
本项目使用官方的 MCP Python SDK 实现,遵循 Model Context Protocol 规范。
本地开发
-
克隆仓库
git clone https://github.com/yourusername/gitcode-mcp-server.git cd gitcode-mcp-server -
创建虚拟环境
python -m venv venv source venv/bin/activate # Linux/macOS venv\Scripts\activate # Windows -
安装开发依赖
pip install -e ".[dev]"
贡献代码
欢迎贡献代码!请按照以下步骤:
- Fork 本仓库
- 创建您的特性分支 (
git checkout -b feature/amazing-feature) - 提交您的更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 开启一个 Pull Request
许可证
本项目采用 MIT 许可证 - 详见 LICENSE 文件