Skip to main content
Glama

GitLab MCP for Code Review

by mehmetakinn

GitLab MCP 用于代码审查

该项目从cayirtepeomer/gerrit-code-review-mcp分叉而来,并适用于 GitLab 集成。

一个 MCP(模型上下文协议)服务器,用于将 Claude 等 AI 助手与 GitLab 的合并请求集成。这使得 AI 助手可以直接通过 GitLab API 审查代码更改。

特征

  • 完整的合并请求分析:获取有关合并请求的完整详细信息,包括差异、提交和评论
  • 文件特定差异:分析合并请求中特定文件的更改
  • 版本比较:比较不同的分支、标签或提交
  • 审核管理:添加评论、批准或不批准合并请求
  • 项目概览:获取项目中所有合并请求的列表

安装

先决条件

快速入门

  1. 克隆此存储库:
git clone https://github.com/mehmetakinn/gitlab-mcp-code-review.git cd gitlab-mcp-code-review
  1. 创建并激活虚拟环境:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
  1. 安装依赖项:
pip install -r requirements.txt
  1. 使用您的 GitLab 配置创建一个.env文件(有关所有选项,请参阅.env.example ):
# Required GITLAB_TOKEN=your_personal_access_token_here # Optional settings GITLAB_HOST=gitlab.com GITLAB_API_VERSION=v4 LOG_LEVEL=INFO

配置选项

您可以在.env文件中配置以下环境变量:

多变的必需的默认描述
GITLAB_TOKEN是的-您的 GitLab 个人访问令牌
GITLAB_HOSTgitlab.comGitLab 实例主机名
GITLAB_API_版本v4要使用的 GitLab API 版本
日志级别信息日志级别(DEBUG、INFO、WARNING、ERROR、CRITICAL)
调试错误的启用调试模式
请求超时三十API 请求超时(秒)
最大重试次数3失败请求的最大重试次数

Cursor IDE 集成

要将此 MCP 与 Cursor IDE 一起使用,请将此配置添加到您的~/.cursor/mcp.json文件中:

{ "mcpServers": { "gitlab-mcp-code-review": { "command": "/path/to/your/gitlab-mcp-code-review/.venv/bin/python", "args": [ "/path/to/your/gitlab-mcp-code-review/server.py", "--transport", "stdio" ], "cwd": "/path/to/your/gitlab-mcp-code-review", "env": { "PYTHONPATH": "/path/to/your/gitlab-mcp-code-review", "VIRTUAL_ENV": "/path/to/your/gitlab-mcp-code-review/.venv", "PATH": "/path/to/your/gitlab-mcp-code-review/.venv/bin:/usr/local/bin:/usr/bin:/bin" }, "stdio": true } } }

/path/to/your/gitlab-mcp-code-review替换为克隆存储库的实际路径。

Claude 桌面应用程序集成

要将此 MCP 与 Claude 桌面应用程序一起使用:

  1. 打开 Claude 桌面应用程序
  2. 前往“设置”→“高级”→“MCP 配置”
  3. 添加以下配置:
{ "mcpServers": { "gitlab-mcp-code-review": { "command": "/path/to/your/gitlab-mcp-code-review/.venv/bin/python", "args": [ "/path/to/your/gitlab-mcp-code-review/server.py", "--transport", "stdio" ], "cwd": "/path/to/your/gitlab-mcp-code-review", "env": { "PYTHONPATH": "/path/to/your/gitlab-mcp-code-review", "VIRTUAL_ENV": "/path/to/your/gitlab-mcp-code-review/.venv", "PATH": "/path/to/your/gitlab-mcp-code-review/.venv/bin:/usr/local/bin:/usr/bin:/bin" }, "stdio": true } } }

/path/to/your/gitlab-mcp-code-review替换为克隆存储库的实际路径。

可用工具

MCP 服务器提供了以下与 GitLab 交互的工具:

工具描述
fetch_merge_request获取有关合并请求的完整信息
fetch_merge_request_diff获取特定合并请求的差异
fetch_commit_diff获取特定提交的差异信息
compare_versions比较不同的分支、标签或提交
add_merge_request_comment向合并请求添加评论
approve_merge_request批准合并请求
unapprove_merge_request取消批准合并请求
get_project_merge_requests获取项目的合并请求列表

使用示例

获取合并请求

# Get details of merge request #5 in project with ID 123 mr = fetch_merge_request("123", "5")

查看特定文件更改

# Get diff for a specific file in a merge request file_diff = fetch_merge_request_diff("123", "5", "path/to/file.js")

比较分支机构

# Compare develop branch with master branch diff = compare_versions("123", "develop", "master")

向合并请求添加评论

# Add a comment to a merge request comment = add_merge_request_comment("123", "5", "This code looks good!")

批准合并请求

# Approve a merge request and set required approvals to 2 approval = approve_merge_request("123", "5", approvals_required=2)

故障排除

如果您遇到问题:

  1. 验证您的 GitLab 令牌是否具有适当的权限(api、read_api)
  2. 检查你的.env文件设置
  3. 确保您的 MCP 配置路径正确
  4. 使用以下方法测试连接: curl -H "Private-Token: your-token" https://gitlab.com/api/v4/projects
  5. 在 .env 文件中设置 LOG_LEVEL=DEBUG 以获得更详细的日志记录

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

  1. 分叉存储库
  2. 创建你的功能分支( git checkout -b feature/amazing-feature
  3. 提交您的更改( git commit -m 'Add some amazing feature'
  4. 推送到分支( git push origin feature/amazing-feature
  5. 打开拉取请求

有关开发过程的更多详细信息,请参阅CONTRIBUTING.md文件。

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

MCP 服务器将 Claude 等 AI 助手与 GitLab 的合并请求相集成,允许他们直接通过 GitLab API 审查代码更改、添加注释以及批准/取消批准合并请求。

  1. 特征
    1. 安装
      1. 先决条件
      2. 快速入门
    2. 配置选项
      1. Cursor IDE 集成
        1. Claude 桌面应用程序集成
          1. 可用工具
            1. 使用示例
              1. 获取合并请求
              2. 查看特定文件更改
              3. 比较分支机构
              4. 向合并请求添加评论
              5. 批准合并请求
            2. 故障排除
              1. 贡献
                1. 执照

                  Related MCP Servers

                  • -
                    security
                    F
                    license
                    -
                    quality
                    A custom server implementation that allows AI assistants to interact with GitLab repositories, providing capabilities for searching, fetching files, creating/updating content, and managing issues and merge requests.
                    Last updated -
                    JavaScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    An MCP server that enables communication with GitLab repositories, allowing interaction with GitLab's API to manage projects, issues, and repositories through natural language.
                    Last updated -
                    20
                    1
                    JavaScript
                    MIT License
                  • A
                    security
                    F
                    license
                    A
                    quality
                    An MCP server that enables AI assistants to manage GitHub Actions workflows by providing tools for listing, viewing, triggering, canceling, and rerunning workflows through the GitHub API.
                    Last updated -
                    9
                    16
                    37
                    TypeScript
                    • Linux
                    • Apple
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Model Context Protocol server that enables AI assistants to interact with GitLab repositories, allowing tasks like managing merge requests, searching projects, and creating comments through RESTful API integration.
                    Last updated -
                    67
                    2
                    TypeScript
                    • Apple

                  View all related MCP servers

                  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/mehmetakinn/gitlab-mcp-code-review'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server