GitLab Code Review MCP
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.
README
GitLab MCP for Code Review
This project is forked from cayirtepeomer/gerrit-code-review-mcp and adapted for GitLab integration.
An MCP (Model Context Protocol) server for integrating AI assistants like Claude with GitLab's merge requests. This allows AI assistants to review code changes directly through the GitLab API.
Features
- Complete Merge Request Analysis: Fetch full details about merge requests including diffs, commits, and comments
- File-Specific Diffs: Analyze changes to specific files within merge requests
- Version Comparison: Compare different branches, tags, or commits
- Review Management: Add comments, approve, or unapprove merge requests
- Project Overview: Get lists of all merge requests in a project
Installation
Prerequisites
- Python 3.10+
- GitLab personal access token with API scope (read_api, api)
- Cursor IDE or Claude Desktop App for MCP integration
Quick Start
- Clone this repository:
git clone https://github.com/lininn/gitlab-code-review-mcp.git
cd gitlab-mcp-code-review
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Create a
.envfile with your GitLab configuration (see.env.examplefor all options):
# Required
GITLAB_TOKEN=your_personal_access_token_here
# Optional settings
GITLAB_HOST=gitlab.com
GITLAB_API_VERSION=v4
LOG_LEVEL=INFO
Configuration Options
The following environment variables can be configured in your .env file:
| Variable | Required | Default | Description |
|---|---|---|---|
| GITLAB_TOKEN | Yes | - | Your GitLab personal access token |
| GITLAB_HOST | No | gitlab.com | GitLab instance hostname |
| GITLAB_API_VERSION | No | v4 | GitLab API version to use |
| LOG_LEVEL | No | INFO | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
| DEBUG | No | false | Enable debug mode |
| REQUEST_TIMEOUT | No | 30 | API request timeout in seconds |
| MAX_RETRIES | No | 3 | Maximum retry attempts for failed requests |
Cursor IDE Integration
To use this MCP with Cursor IDE, add this configuration to your ~/.cursor/mcp.json file:
{
"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
}
}
}
Replace /path/to/your/gitlab-mcp-code-review with the actual path to your cloned repository.
Claude Desktop App Integration
To use this MCP with the Claude Desktop App:
- Open the Claude Desktop App
- Go to Settings → Advanced → MCP Configuration
- Add the following configuration:
{
"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
}
}
}
Replace /path/to/your/gitlab-mcp-code-review with the actual path to your cloned repository.
Available Tools
The MCP server provides the following tools for interacting with GitLab:
| Tool | Description |
|---|---|
fetch_merge_request |
Get complete information about a merge request |
fetch_merge_request_diff |
Get diffs for a specific merge request |
fetch_commit_diff |
Get diff information for a specific commit |
compare_versions |
Compare different branches, tags, or commits |
add_merge_request_comment |
Add a comment to a merge request |
approve_merge_request |
Approve a merge request |
unapprove_merge_request |
Unapprove a merge request |
get_project_merge_requests |
Get a list of merge requests for a project |
Usage Examples
Fetch a Merge Request
# Get details of merge request #5 in project with ID 123
mr = fetch_merge_request("123", "5")
View Specific File Changes
# Get diff for a specific file in a merge request
file_diff = fetch_merge_request_diff("123", "5", "path/to/file.js")
Compare Branches
# Compare develop branch with master branch
diff = compare_versions("123", "develop", "master")
Add a Comment to a Merge Request
# Add a comment to a merge request
comment = add_merge_request_comment("123", "5", "This code looks good!")
Approve a Merge Request
# Approve a merge request and set required approvals to 2
approval = approve_merge_request("123", "5", approvals_required=2)
Troubleshooting
If you encounter issues:
- Verify your GitLab token has the appropriate permissions (api, read_api)
- Check your
.envfile settings - Ensure your MCP configuration paths are correct
- Test connection with:
curl -H "Private-Token: your-token" https://gitlab.com/api/v4/projects - Set LOG_LEVEL=DEBUG in your .env file for more detailed logging
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
See the CONTRIBUTING.md file for more details on the development process.
Code Review Standards
This project follows strict code review standards to ensure quality and maintainability:
- 📋 Code Review Guidelines: This project follows a strict set of code review guidelines to ensure quality and consistency. For detailed information on the review process, standards, and best practices, please see the Code Review Guidelines.
- ✅ Review Checklist: All pull requests should be checked against the PULL_REQUEST_CHECKLIST.md before submission.
- 🔄 CI/CD Pipeline: We use GitLab CI for automated quality checks. Ensure all pipeline checks pass before requesting a review.
- 📝 Templates: Please use the provided merge request and issue templates to ensure all necessary information is included.
Quick Start for Contributors
- Read the Code Review Guidelines
- Use the appropriate MR template when creating pull requests
- Ensure all CI checks pass before requesting review
- Address all reviewer feedback promptly
License
This project is licensed under the MIT License - see the LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。