Skip to main content
Glama
GitLab MR Comments MCP Server

GitLab MR Comments MCP Server

GitLab MR Comments MCP Server

A Model Context Protocol (MCP) server that fetches merge request comments from GitLab, including file names, line numbers, and comment text.

Features

  • Fetches comments from GitLab merge requests via the GitLab API

  • Returns structured data with:

    • File name (if comment is on a specific file)

    • Line number (if comment is on a specific line)

    • Comment text

    • Author information

    • Creation timestamp

    • Resolution status

  • Supports pagination

  • Optional filtering of resolved comments

  • SSL verification control

Related MCP server: GitLab Code Review MCP

Installation

npm install
npm run build

Configuration

Set the following environment variables:

Required

  • GITLAB_HOST or GITLAB_BASE_URL: Your GitLab instance URL (e.g., https://gitlab.com)

  • GITLAB_TOKEN or GITLAB_PERSONAL_ACCESS_TOKEN: Your GitLab personal access token

Optional

  • GITLAB_SSL_VERIFY: SSL certificate verification. Set to 0, false, or no to disable (default: enabled)

Usage

As an MCP Server

Add to your MCP client configuration (e.g., Claude Desktop, Cline):

{
  "mcpServers": {
    "gitlab-mr-comments": {
      "command": "node",
      "args": ["/path/to/gitlab-mr-comments/dist/index.js"],
      "env": {
        "GITLAB_HOST": "https://gitlab.com",
        "GITLAB_TOKEN": "your-gitlab-token-here"
      }
    }
  }
}

Using with AI Assistants

When you paste a GitLab merge request URL to an AI assistant that has this MCP server configured, the AI should automatically:

  1. Parse the URL to extract the project path and MR IID

  2. Call the tool with the correct parameters

  3. Return the comments in a readable format

Example prompt:

Show me the comments from this merge request:
https://mars-gitlab.systemgroup.net/mars/general-market/-/merge_requests/7380

The AI will extract:

  • Project: mars/general-market

  • MR IID: 7380

And call the tool accordingly.

Tool: gitlab.get_merge_request_comments

Fetches comments for a specific merge request.

Parameters

  • project_id (string): Numeric project ID or full path (e.g., "123" or "mygroup/myproject")

  • merge_request_iid (string): Internal IID of the merge request (e.g., "456")

  • per_page (number, optional): Number of discussions per page (1-100, default: GitLab default of 20)

  • page (number, optional): Page of discussions to fetch (default: 1)

  • include_resolved (boolean, optional): Include resolved comments (default: false)

Extracting Parameters from a GitLab URL

Given a merge request URL like:

https://mars-gitlab.systemgroup.net/mars/general-market/-/merge_requests/7380

Extract the parameters as:

  • project_id: "mars/general-market" (the path between the domain and /-/merge_requests/)

  • merge_request_iid: "7380" (the number after /merge_requests/)

Example:

{
  "project_id": "mars/general-market",
  "merge_request_iid": "7380"
}

Example Response

[
  {
    "file": "src/index.ts",
    "line": 42,
    "text": "Consider refactoring this function for better readability",
    "author": "john.doe",
    "created_at": "2024-11-08T10:30:00.000Z",
    "resolved": false
  },
  {
    "file": "README.md",
    "line": 10,
    "text": "This documentation needs to be updated",
    "author": "jane.smith",
    "created_at": "2024-11-07T14:20:00.000Z",
    "resolved": true
  },
  {
    "file": null,
    "line": null,
    "text": "Overall, this looks good to merge!",
    "author": "bob.wilson",
    "created_at": "2024-11-08T09:00:00.000Z",
    "resolved": false
  }
]

Development

Build

npm run build

Run

npm start

API Details

This server uses the GitLab REST API v4:

  • Endpoint: /api/v4/projects/{project_id}/merge_requests/{merge_request_iid}/discussions

  • Authentication: Personal Access Token via PRIVATE-TOKEN header

Debugging & Troubleshooting

Viewing Logs

All logs are written to stderr with the prefix [MCP]. When running in an MCP client, these logs will typically appear in the client's log file or console.

Example logs on startup:

[MCP] ====================================
[MCP] GitLab MR Comments MCP Server
[MCP] Version: 0.1.0
[MCP] ====================================
[MCP] Node version: v20.x.x
[MCP] Platform: linux
[MCP] CWD: /path/to/project
[MCP] Creating stdio transport...
[MCP] Connecting server to transport...
[MCP] ====================================
[MCP] Server successfully connected!
[MCP] Ready to receive tool calls
[MCP] ====================================

Example logs when tool is called:

[MCP] Tool called with args: {
  "project_id": "mygroup/myproject",
  "merge_request_iid": 123
}
[MCP] Starting fetchMergeRequestComments
[MCP] Resolving GitLab host from environment
[MCP] Resolved host: https://gitlab.com
[MCP] Resolving GitLab token from environment
[MCP] Token found (length: 20)
[MCP] SSL verification: enabled (default)
[MCP] Project ID: mygroup%2Fmyproject
[MCP] MR IID: 123
[MCP] Request URL: https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/merge_requests/123/discussions
[MCP] Sending request to GitLab API...
[MCP] Response status: 200 OK
[MCP] Parsing response JSON...
[MCP] Received 5 discussions
[MCP] Include resolved: false
[MCP] Processed 12 comments
[MCP] Successfully fetched 12 comments

Common Issues

1. Environment Variables Not Set

Symptom:

[MCP] ERROR: GITLAB_HOST environment variable not set
[MCP] Available env vars: []

Solution: Make sure to set GITLAB_HOST and GITLAB_TOKEN in your MCP client configuration:

{
  "env": {
    "GITLAB_HOST": "https://gitlab.com",
    "GITLAB_TOKEN": "your-token-here"
  }
}

2. Authentication Error

Symptom:

[MCP] Response status: 401 Unauthorized
[MCP] Error response body: {"message":"401 Unauthorized"}

Solution:

  • Check that your GitLab token is valid

  • Ensure the token has api or read_api scope

  • Verify you're using the correct token for your GitLab instance

3. Project Not Found

Symptom:

[MCP] Response status: 404 Not Found
[MCP] Error response body: {"message":"404 Project Not Found"}

Solution:

  • Verify the project ID or path is correct

  • Ensure you have access to the project

  • For project paths with special characters, they will be automatically URL-encoded

4. SSL Certificate Issues

Symptom:

Error: self signed certificate in certificate chain

Solution: Disable SSL verification (for development/testing only):

{
  "env": {
    "GITLAB_SSL_VERIFY": "0"
  }
}

Testing Locally

Use the included test script to verify your configuration:

# Set environment variables
export GITLAB_HOST="https://gitlab.com"
export GITLAB_TOKEN="your-token-here"

# Run test
./test-mcp.sh

The server will start and show you all initialization logs. Press Ctrl+C to stop.

Checking MCP Client Logs

Different MCP clients store logs in different locations:

Claude Desktop (macOS):

tail -f ~/Library/Logs/Claude/mcp*.log

Claude Desktop (Linux):

tail -f ~/.config/Claude/logs/mcp*.log

Cline (VS Code):

  • Check the VS Code Output panel

  • Select "Cline" from the dropdown

License

MIT

Available Tools

1 tool
gitlab.get_merge_request_commentsB

Fetch comments for a GitLab merge request and return filename, line, and text. Provide the project path (e.g., "mars/general-market") and merge request IID (e.g., "7380").

Inputs: project_id (required), merge_request_iid (required), page, per_page, +1 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 1 tool

    Disambiguation5/5

    There is only one tool, so there is no possibility of confusing it with a sibling. Its purpose (fetch comments for a specific MR by project path and IID) is stated unambiguously.

    Naming Consistency5/5

    The single name gitlab.get_merge_request_comments follows a clean namespace + verb_noun pattern in snake_case. No competing conventions exist to clash with.

    Tool Count3/5

    The count matches the very narrow stated scope (reading MR comments), but a one-tool server is thin; even a read-only comments domain would normally include listing merge requests or fetching a single discussion thread.

    Completeness2/5

    The surface is read-only and has no way to post a reply, resolve a discussion, or list MRs to find the IID in the first place. Agents will frequently hit a dead end after retrieving the comments.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to review GitLab merge requests by fetching changes, analyzing diffs, adding comments, and managing approvals through the GitLab API. Supports complete merge request analysis, file-specific reviews, and version comparisons.
      12
      4
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      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.
      3
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables 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.
      94
      MIT