GitLab MCP Code Review
This MCP server integrates AI assistants like Claude with GitLab to automate comprehensive code review workflows through GitLab's API. It works with both gitlab.com and self-hosted GitLab instances.
Merge Request Management
Fetch detailed merge request information including diffs, commits, and comments
List all merge requests for a project with filtering by state (opened, closed, merged, locked)
Approve or unapprove merge requests
Analyze specific file changes within merge requests
Code Comparison & Analysis
Compare differences between branches, tags, or commits
View and analyze file-specific changes with line-level precision
Discussion & Comments
Add general comments to merge requests
Create discussions at specific positions in files
Reply to existing discussion threads
Resolve, unresolve, or delete discussions
Project Management
Search for GitLab projects by name
Browse accessible projects
Team Standards
Fetch team-specific code review rules from remote servers via SSH (optional configuration)
Provides tools for GitLab merge request management, including analyzing merge requests with full details and diffs, comparing different branches/tags/commits, adding comments, and managing approvals through the GitLab API.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@GitLab MCP Code Review review merge request #42 in project my-team/web-app"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
GitLab MCP 代码审查工具
本项目 fork 自 cayirtepeomer/gerrit-code-review-mcp 并为 GitLab 集成进行了适配。
一个用于将 Claude 等 AI 助手与 GitLab 的合并请求集成的 MCP (Model Context Protocol) 服务器。这使得 AI 助手可以通过 GitLab API 直接审查代码变更。
功能
完整的合并请求分析: 获取合并请求的全部详情,包括差异、提交和评论
文件特定的差异: 分析合并请求中特定文件的变更
版本比较: 比较不同的分支、标签或提交
审查管理: 添加评论、批准或取消批准合并请求
项目概览: 获取项目中的所有合并请求列表
Related MCP server: GitLab MR MCP
安装
先决条件
Python 3.10+
uv
具有 API 范围 (read_api, api) 的 GitLab 个人访问令牌
用于 MCP 集成的 Cursor IDE 或 Claude 桌面应用
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 交互:
工具 | 描述 |
| 通过 SSH 获取团队的代码审查规范文件 |
| 获取有关合并请求的完整信息 |
| 比较不同的分支、标签或提交 |
| 向合并请求添加评论 |
| 批准合并请求 |
| 取消批准合并请求 |
| 获取项目的合并请求列表 |
故障排除
如果遇到问题:
验证你的 GitLab 令牌是否具有适当的权限 (api, read_api)
确保你的 MCP 配置路径正确
使用以下命令测试连接:
curl -H "Private-Token: your-token" https://gitlab.com/api/v4/projects
许可证
本项目根据 MIT 许可证授权 - 有关详细信息,请参阅 LICENSE 文件。
Available Tools
12 toolsadd_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
Scored across 12 tools
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.
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.
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.
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
Related MCP Connectors
Operate GitHub from your AI assistant: repos, PRs, issues, Actions. Previews and read-only mode.
AI-native git hosting — repos, PRs, issues, CI gates, and AI code review over MCP (60 tools).
Connect AI assistants to GitHub - manage repos, issues, PRs, and workflows through natural language.
Versioned artifact review for people and AI agents, with contextual comments and human control.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables 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.3MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with GitLab repositories, manage merge requests, review code diffs, post comments, and handle issues directly through natural language.125 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables 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 npm94MIT
- FlicenseAqualityCmaintenanceConnects 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.122-