Skip to main content
Glama

GitLab MCP for Code Review

by mehmetakinn

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

Quick Start

  1. Clone this repository:
git clone https://github.com/mehmetakinn/gitlab-mcp-code-review.git cd gitlab-mcp-code-review
  1. Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file with your GitLab configuration (see .env.example for 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:

VariableRequiredDefaultDescription
GITLAB_TOKENYes-Your GitLab personal access token
GITLAB_HOSTNogitlab.comGitLab instance hostname
GITLAB_API_VERSIONNov4GitLab API version to use
LOG_LEVELNoINFOLogging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
DEBUGNofalseEnable debug mode
REQUEST_TIMEOUTNo30API request timeout in seconds
MAX_RETRIESNo3Maximum 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:

  1. Open the Claude Desktop App
  2. Go to Settings → Advanced → MCP Configuration
  3. 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:

ToolDescription
fetch_merge_requestGet complete information about a merge request
fetch_merge_request_diffGet diffs for a specific merge request
fetch_commit_diffGet diff information for a specific commit
compare_versionsCompare different branches, tags, or commits
add_merge_request_commentAdd a comment to a merge request
approve_merge_requestApprove a merge request
unapprove_merge_requestUnapprove a merge request
get_project_merge_requestsGet 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:

  1. Verify your GitLab token has the appropriate permissions (api, read_api)
  2. Check your .env file settings
  3. Ensure your MCP configuration paths are correct
  4. Test connection with: curl -H "Private-Token: your-token" https://gitlab.com/api/v4/projects
  5. Set LOG_LEVEL=DEBUG in your .env file for more detailed logging

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See the CONTRIBUTING.md file for more details on the development process.

License

This project is licensed under the MIT License - see the LICENSE file for details.

-
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

                  • A
                    security
                    F
                    license
                    A
                    quality
                    An MCP server that enables Claude and other compatible LLMs to interact with the GitHub API, supporting features like creating issues, retrieving repository information, listing issues, and searching repositories.
                    Last updated -
                    4
                  • -
                    security
                    A
                    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 -
                    8,525
                    1
                    MIT License
                  • A
                    security
                    F
                    license
                    A
                    quality
                    An MCP server that allows Claude and other MCP-compatible LLMs to interact with the GitHub API, supporting features like creating issues, getting repository information, listing issues, and searching repositories.
                    Last updated -
                    4
                  • -
                    security
                    A
                    license
                    -
                    quality
                    An MCP server that enables AI assistants like Claude to help users manage their GitHub notifications through natural language commands.
                    Last updated -
                    3
                    15
                    MIT License

                  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