Skip to main content
Glama
GitLab MCP Code Review

GitLab MCP Code Review

by ffpy

GitLab MCP 代码审查工具

Python 3.10+ License: MIT

本项目 fork 自 cayirtepeomer/gerrit-code-review-mcp 并为 GitLab 集成进行了适配。

一个用于将 Claude 等 AI 助手与 GitLab 的合并请求集成的 MCP (Model Context Protocol) 服务器。这使得 AI 助手可以通过 GitLab API 直接审查代码变更。

功能

  • 完整的合并请求分析: 获取合并请求的全部详情,包括差异、提交和评论

  • 文件特定的差异: 分析合并请求中特定文件的变更

  • 版本比较: 比较不同的分支、标签或提交

  • 审查管理: 添加评论、批准或取消批准合并请求

  • 项目概览: 获取项目中的所有合并请求列表

Related MCP server: GitLab MR MCP

安装

先决条件

Cursor IDE 集成

克隆此仓库:

git clone https://gitea.ffpy.site/ffpy/gitlab-mcp-code-review.git
cd gitlab-mcp-code-review

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

{
  "mcpServers": {
    "gitlab-mcp-code-review": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/your/gitlab-mcp-code-review",
        "run",
        "server.py"
      ],
      "env": {
        "GITLAB_HOST": "gitlab.com",
        "GITLAB_TOKEN": "xxx"
      }
    }
  }
}
  • 将 /path/to/your/gitlab-mcp-code-review 替换为你克隆仓库的实际路径。

  • 将 GITLAB_HOST 修改为你的Gitlab地址

  • 将 GITLAB_TOKEN 修改为你的AccessToken

环境变量

必需的环境变量

  • GITLAB_HOST: GitLab 实例的主机名(默认: gitlab.com)

  • GITLAB_TOKEN: GitLab 个人访问令牌(需要 api 和 read_api 权限)

可选的环境变量(用于代码审查规范功能)

如果你想使用 fetch_code_review_rules 工具从远程服务器获取团队的代码审查规范,需要配置以下环境变量:

  • CODE_REVIEW_SSH_HOST: SSH 服务器地址

  • CODE_REVIEW_SSH_PORT: SSH 端口(默认: 22)

  • CODE_REVIEW_SSH_USERNAME: SSH 用户名

  • CODE_REVIEW_SSH_PASSWORD: SSH 密码

  • CODE_REVIEW_RULE_FILE: 规范文件在服务器上的绝对路径(例如: /home/user/code-review-rules.md)

配置示例:

{
  "mcpServers": {
    "gitlab-mcp-code-review": {
      "command": "uv",
      "args": ["--directory", "/path/to/your/gitlab-mcp-code-review", "run", "server.py"],
      "env": {
        "GITLAB_HOST": "gitlab.com",
        "GITLAB_TOKEN": "xxx",
        "CODE_REVIEW_SSH_HOST": "your-server.com",
        "CODE_REVIEW_SSH_PORT": "22",
        "CODE_REVIEW_SSH_USERNAME": "your-username",
        "CODE_REVIEW_SSH_PASSWORD": "your-password",
        "CODE_REVIEW_RULE_FILE": "/path/to/code-review-rules.md"
      }
    }
  }
}

可用工具

MCP 服务器提供以下工具用于与 GitLab 交互:

工具

描述

fetch_code_review_rules

通过 SSH 获取团队的代码审查规范文件

fetch_merge_request

获取有关合并请求的完整信息

compare_versions

比较不同的分支、标签或提交

add_merge_request_comment

向合并请求添加评论

approve_merge_request

批准合并请求

unapprove_merge_request

取消批准合并请求

get_project_merge_requests

获取项目的合并请求列表

故障排除

如果遇到问题:

  1. 验证你的 GitLab 令牌是否具有适当的权限 (api, read_api)

  2. 确保你的 MCP 配置路径正确

  3. 使用以下命令测试连接:curl -H "Private-Token: your-token" https://gitlab.com/api/v4/projects

许可证

本项目根据 MIT 许可证授权 - 有关详细信息,请参阅 LICENSE 文件。

Available Tools

12 tools
add_merge_request_commentB
Add a general comment to a merge request.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
    body: The comment text
Returns:
    Dict containing the created comment information

Inputs: project_id (required), merge_request_iid (required), body (required). Returns: result

add_merge_request_discussionA
Add a discussion to a merge request at a specific position in a file.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
    body: The discussion text
    position: Position data for the discussion.
        Example:
        {
            "position_type": "text", // Required, Type of the position reference. Allowed values: text, image, or file. file introduced in GitLab 16.4.
            "base_sha": "...", // Required, Base commit SHA in the source branch.
            "start_sha": "...", // Required, SHA referencing commit in target branch.
            "head_sha": "...", // Required, SHA referencing HEAD of this merge request.
            "old_path": "path/to/file.py", // Required, File path before change.
            "new_path": "path/to/file.py", // Required, File path after change.
            "new_line": 15, // For text diff notes, the line number after change.
            "old_line": 10 // For text diff notes, the line number before change.
        }
Returns:
    Dict containing the created discussion information

Inputs: project_id (required), merge_request_iid (required), body (required), position (required). Returns: result

approve_merge_requestC
Approve a merge request.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
    approvals_required: Optional number of required approvals to set
Returns:
    Dict containing the approval information

Inputs: project_id (required), merge_request_iid (required), approvals_required. Returns: result

compare_versionsC
Compare two commits/branches/tags to see the differences between them.

Args:
    project_id: The GitLab project ID or URL-encoded path
    from_sha: The source commit/branch/tag
    to_sha: The target commit/branch/tag
Returns:
    Dict containing the comparison information

Inputs: project_id (required), from_sha (required), to_sha (required). Returns: result

delete_merge_request_discussionC
Delete a merge request discussion.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
    discussion_id: The ID of the discussion to delete
Returns:
    Dict containing the status of the deletion

Inputs: project_id (required), merge_request_iid (required), discussion_id (required). Returns: result

fetch_code_review_rulesA
Fetch the team's code review rules from a remote server via SSH.

IMPORTANT: You should call this tool BEFORE reviewing any merge requests or code changes
to understand the team's code review standards and guidelines.

Returns:
    str: The code review rules content on success, or a simple message if SSH is not configured
    Dict: Error information only on connection failures

Inputs: no named parameters.

fetch_merge_requestA
Fetch a GitLab merge request and its contents.

IMPORTANT: You MUST call fetch_code_review_rules BEFORE using this tool to understand 
the team's code review standards and guidelines.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
Returns:
    XML string containing the merge request information

Inputs: project_id (required), merge_request_iid (required).

get_project_merge_requestsB
Get all merge requests for a project.

Args:
    project_id: The GitLab project ID or URL-encoded path
    state: Filter merge requests by state (all, opened, closed, merged, or locked)
    limit: Maximum number of merge requests to return
Returns:
    List of merge request objects

Inputs: project_id (required), state, limit. Returns: result

reply_to_merge_request_discussionC
Reply to a merge request discussion.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
    discussion_id: The ID of the discussion to reply to
    body: The reply text
Returns:
    Dict containing the created note information

Inputs: project_id (required), merge_request_iid (required), discussion_id (required), body (required). Returns: result

resolve_merge_request_discussionB
Resolve or unresolve a merge request discussion.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
    discussion_id: The ID of the discussion
    resolved: True to resolve, False to unresolve
Returns:
    Dict containing the updated discussion information

Inputs: project_id (required), merge_request_iid (required), discussion_id (required), resolved. Returns: result

search_projectsC
Search for GitLab projects by name.

Args:
    project_name: The name of the project to search for. If None, returns all projects.
Returns:
    A list of projects matching the search criteria.

Inputs: project_name. Returns: result

unapprove_merge_requestB
Unapprove a merge request.

Args:
    project_id: The GitLab project ID or URL-encoded path
    merge_request_iid: The merge request IID (project-specific ID)
Returns:
    Dict containing the unapproval information

Inputs: project_id (required), merge_request_iid (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 12 tools

    Disambiguation4/5

    Most tools have distinct purposes focused on merge request management and code review workflows, with clear boundaries between actions like adding comments, approving, and comparing versions. However, there is some potential overlap between 'add_merge_request_comment' and 'add_merge_request_discussion' as both involve commenting, though the latter is more specific to file positions.

    Naming Consistency5/5

    Tool names follow a consistent verb_noun pattern throughout, such as 'add_merge_request_comment', 'approve_merge_request', and 'fetch_code_review_rules'. All tools use snake_case and maintain a predictable structure, making them easy to parse and understand.

    Tool Count5/5

    With 12 tools, the set is well-scoped for a GitLab code review server, covering essential operations like fetching merge requests, managing discussions, approvals, and project searches. Each tool serves a clear purpose without redundancy, fitting the domain appropriately.

    Completeness4/5

    The toolset provides comprehensive coverage for code review tasks, including fetching rules, listing and fetching merge requests, adding and managing discussions, and handling approvals. A minor gap is the lack of tools for directly modifying merge requests (e.g., updating or merging them), but core review workflows are well-supported.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to review GitLab merge requests by fetching diffs, analyzing code changes, adding comments, and managing approvals through the GitLab API. Supports comprehensive merge request analysis and version comparison for automated code review workflows.
      3
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to interact with GitLab repositories, manage merge requests, review code diffs, post comments, and handle issues directly through natural language.
      125 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to interact with GitLab repositories, allowing them to manage merge requests and issues including listing projects, fetching MR details and diffs, adding comments, and updating MR titles and descriptions.
      125 npm
      94
      MIT
    • F
      license
      A
      quality
      C
      maintenance
      Connects AI assistants to GitLab to interact with merge requests, reviews, discussions, pipelines, and test results through natural language queries. Supports viewing MR details, responding to comments, checking test summaries, and analyzing job logs.
      12
      2
      -