GitLab MCP服务器
一个模型上下文协议(MCP)服务器,使您能够与您的GitLab帐户进行交互。获取差异、分析合并请求、审查代码、挑选更改等等。这是的扩展版本 MCP GitLab服务器 来自模型上下文协议项目。
特性
此MCP服务器提供了与GitLab存储库交互的全面工具,包括:
核心存储库功能
- 列出项目并检索详细信息
- 管理分支和存储库
- 处理合并请求和差异
- 添加评论和内部注释以合并请求
- 更新合并请求属性
- 列出并处理问题
- 获取和比较存储库文件内容
项目设置和集成
- 管理项目集成和服务
- 配置和控制Slack集成
- 设置、更新和测试webhooks
CI/CD管理
- 使用管道触发令牌
- 管理CI/CD变量
- 触发和控制管道
用户和组管理
- 列出和管理用户
- 与团体和团体成员合作
- 管理项目成员和访问级别
安装
先决条件
- Node.js(v16或更高版本)
- npm
- 带有API令牌的GitLab帐户
设置
- 克隆存储库:
git clone https://github.com/rifqi96/mcp-gitlab.git
cd mcp-gitlab- 安装依赖项:
npm install- 构建服务器:
npm run build- 安装git钩子(可选,但建议贡献者使用):
npm run install-hooks这将安装一个预提交钩子,当src/utils/TOOLS-data.ts更改时,该钩子会自动重新生成TOOLS.md。
- 配置您的GitLab API令牌:
您需要在MCP设置配置文件中提供您的GitLab API令牌。该令牌用于通过GitLab API进行身份验证。
对于Cursor/Roo Cline,将以下内容添加到MCP设置文件中(~/Library/Application Support/Cursor/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json):
{
"mcpServers": {
"gitlab": {
"command": "node",
"args": [
"/path/to/mcp-gitlab/build/index.js"
],
"env": {
"GITLAB_API_TOKEN": "YOUR_GITLAB_API_TOKEN",
"GITLAB_API_URL": "https://gitlab.com/api/v4"
}
}
}
}对于Claude Desktop,将以下内容添加到MCP设置文件中(~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"gitlab": {
"command": "node",
"args": [
"/path/to/mcp-gitlab/build/index.js"
],
"env": {
"GITLAB_API_TOKEN": "YOUR_GITLAB_API_TOKEN",
"GITLAB_API_URL": "https://gitlab.com/api/v4"
}
}
}
}替换 YOUR_GITLAB_API_TOKEN 使用您的实际GitLab API令牌。您可以在GitLab帐户的“设置”>“访问令牌”下生成令牌。
可用工具
有关可用工具及其参数的完整列表,请参阅 TOOLS.md.
示例用法
以下是如何将这些工具与支持MCP的AI助手一起使用的示例:
列出您的项目
Could you list my GitLab projects?获取有关特定合并请求的信息
Can you show me the details of merge request with ID 123 in the project 'mygroup/myproject'?向合并请求添加注释
Please add a comment to merge request 123 in project 'mygroup/myproject' saying "This looks good, but please add more tests."在合并请求中添加内部注释
Add an internal note to merge request 123 in project 'mygroup/myproject' that says "Needs security review before merging." Make sure it's only visible to team members.更新合并请求标题和描述
Update the title of merge request 123 in project 'mygroup/myproject' to "Fix login page performance issues" and update the description to include "This PR addresses the slow loading times on the login page by optimizing database queries."比较分支
Compare the 'feature-branch' with 'main' in the project 'mygroup/myproject' and show me the differences.实用工作流程
审阅合并请求
1. Show me merge request 123 in project 'mygroup/myproject'
2. Show me the changes for this merge request
3. Add an internal note with my review comments
4. Update the merge request title to better reflect the changes项目勘探
1. List all my GitLab projects
2. Show me the details of project 'mygroup/myproject'
3. List all branches in this project
4. Show me the content of the README.md file in the main branch可用资源
gitlab://projects
使用API令牌可访问的GitLab项目列表。
与AI助手集成
GitLab MCP服务器与支持模型上下文协议(MCP)的AI助手集成。
能力
当连接到AI助手时,此服务器使助手能够:
- 查看和分析代码:助手可以获取文件内容,查看分支差异,并检查合并请求更改,以便更好地理解代码。
- 提供代码审查:助理可以分析合并请求,并通过评论或内部注释提供反馈。
- 管理项目工作流程:助手可以更新合并请求属性、添加注释以及帮助执行存储库管理任务。
- 探索项目结构:助手可以浏览项目、分支和文件,以了解代码库结构。
- 配置CI/CD和集成:该助手可以帮助设置Webhook、管理CI/CD变量和配置项目集成。
从AI助手集成中获得最大收益
- 询问项目、合并请求或文件时要具体
- 尽可能提供项目ID或路径
- 使用助手进行代码审查,让它分析特定的合并请求
- 让助手帮助完成存储库配置和管理任务
- 使用内部笔记对合并请求进行团队反馈
许可证
麻省理工学院
