Home / MCP / GitLab MCP for Code Review MCP Server

GitLab MCP for Code Review MCP Server

An MCP server that integrates AI assistants with GitLab merge requests for full MR analysis and review actions.

python
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "mcpServers": {
        "gitlab_mcp": {
            "command": "python",
            "args": [
                "server.py",
                "--transport",
                "stdio"
            ],
            "env": {
                "GITLAB_TOKEN": "glpat-abcdefghijklmnopqrstuvwxyz",
                "GITLAB_HOST": "gitlab.com",
                "GITLAB_API_VERSION": "v4",
                "LOG_LEVEL": "INFO",
                "DEBUG": "false",
                "REQUEST_TIMEOUT": "30",
                "MAX_RETRIES": "3",
                "PYTHONPATH": "<path-to-your-mcp-root>",
                "VIRTUAL_ENV": "<path-to-your-venv>",
                "PATH": "<venv-path>:/usr/local/bin:/usr/bin:/bin"
            }
        }
    }
}

You run a Python-based MCP server that connects AI assistants to GitLab merge requests. It fetches complete MR data, diffs, commits, and comments, and lets you add comments or approvals, enabling automated code review workflows within GitLab.

How to use

You will run the MCP server locally and connect your MCP client (such as Cursor IDE or Claude Desktop App) to it. Once linked, you can request full merge request analyses, file-specific diffs, and version comparisons, then perform review actions like commenting or approving directly from your AI assistant.

How to install

Prerequisites: Python 3.10+ and a GitLab personal access token with API scope.

1. Create a virtual environment and activate it.

2. Install dependencies from the requirements file.

3. Prepare a configuration file with your GitLab settings (the example options below show the typical variables you will use). They include your GitLab token, host, API version, and logging preference.

4. Run the MCP server using the standard Python command sequence described in the configuration steps.

Configuration and usage notes

Environment variables you will configure in your environment file include the token, host, API version, and logging controls. The following options are commonly used:

GITLAB_TOKEN: Your GitLab personal access token with API scope

GITLAB_HOST: GitLab instance hostname (default: gitlab.com)

GITLAB_API_VERSION: API version to use (default: v4)

LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)

DEBUG, REQUEST_TIMEOUT, MAX_RETRIES: Optional controls for debugging and reliability

Troubleshooting

If you encounter issues, verify your GitLab token permissions, review your environment variable values, and confirm the MCP server path and Python virtual environment are correct. Increase logging by setting LOG_LEVEL to DEBUG for more details.

Available tools

fetch_merge_request

Get complete information about a merge request including details, diffs, commits, and comments.

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.