GitLab Code Review MCP server

Integrates with GitLab's REST API to provide merge request analysis, diff comparison, review comment management, and approval workflows for streamlined code review processes across GitLab.com and self-hosted instances.
Back to servers
Setup instructions
Provider
lininn
Release date
Aug 27, 2025
Language
Go
Stats
1 star

The GitLab MCP server enables AI assistants like Claude to interact with GitLab merge requests for code review. This integration allows AI assistants to fetch merge request details, analyze code changes, and provide comments directly through the GitLab API.

Installation

Prerequisites

Setup Steps

  1. Clone the repository:
git clone https://github.com/lininn/gitlab-code-review-mcp.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:
# Required
GITLAB_TOKEN=your_personal_access_token_here

# Optional settings
GITLAB_HOST=gitlab.com
GITLAB_API_VERSION=v4
LOG_LEVEL=INFO

Configuration

You can customize the server behavior using these environment variables 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

Connecting 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 your actual repository path.

Connecting with Claude Desktop App

  1. Open the Claude Desktop App
  2. Navigate 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 your actual repository path.

Available Tools

The MCP server provides these tools for GitLab interaction:

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

Fetching Merge Request Details

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

Viewing 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")

Comparing Branches

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

Adding Comments

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

Approving Merge Requests

# 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 your GitLab connection with: curl -H "Private-Token: your-token" https://gitlab.com/api/v4/projects
  5. Enable detailed logging by setting LOG_LEVEL=DEBUG in your .env file

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "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}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "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
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration 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
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later