GitLab MCP server

Control repositories, merge requests, and issues via GitLab API.
Back to servers
Provider
Anthropic
Release date
Nov 19, 2024
Language
TypeScript
Package
Stats
12.8K downloads
43.7K stars

The GitLab MCP Server enables interaction with GitLab's API through the Model Context Protocol, allowing you to manage projects, manipulate files, and perform various GitLab operations directly from compatible clients like Claude Desktop or VS Code.

Installation

Prerequisites

You'll need a GitLab Personal Access Token with appropriate permissions:

  1. Go to User Settings > Access Tokens in GitLab
  2. Select the required scopes:
    • api for full API access
    • read_api for read-only access
    • read_repository and write_repository for repository operations
  3. Create the token and save it securely

Setup with Claude Desktop

Add the following to your claude_desktop_config.json:

Option 1: Using Docker

{
  "mcpServers": { 
    "gitlab": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        "GITLAB_PERSONAL_ACCESS_TOKEN",
        "-e",
        "GITLAB_API_URL",
        "mcp/gitlab"
      ],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>",
        "GITLAB_API_URL": "https://gitlab.com/api/v4"
      }
    }
  }
}

Option 2: Using NPX

{
  "mcpServers": {
    "gitlab": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-gitlab"
      ],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>",
        "GITLAB_API_URL": "https://gitlab.com/api/v4"
      }
    }
  }
}

Setup with VS Code

For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code:

Option 1: Using Docker

{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "gitlab_token",
        "description": "GitLab Personal Access Token",
        "password": true
      },
      {
        "type": "promptString",
        "id": "gitlab_url",
        "description": "GitLab API URL (optional)",
        "default": "https://gitlab.com/api/v4"
      }
    ],
    "servers": {
      "gitlab": {
        "command": "docker",
        "args": [
          "run",
          "--rm",
          "-i",
          "mcp/gitlab"
        ],
        "env": {
          "GITLAB_PERSONAL_ACCESS_TOKEN": "${input:gitlab_token}",
          "GITLAB_API_URL": "${input:gitlab_url}"
        }
      }
    }
  }
}

Option 2: Using NPX

{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "gitlab_token",
        "description": "GitLab Personal Access Token",
        "password": true
      },
      {
        "type": "promptString",
        "id": "gitlab_url",
        "description": "GitLab API URL (optional)",
        "default": "https://gitlab.com/api/v4"
      }
    ],
    "servers": {
      "gitlab": {
        "command": "npx",
        "args": [
          "-y",
          "@modelcontextprotocol/server-gitlab"
        ],
        "env": {
          "GITLAB_PERSONAL_ACCESS_TOKEN": "${input:gitlab_token}",
          "GITLAB_API_URL": "${input:gitlab_url}"
        }
      }
    }
  }
}

Using the GitLab MCP Server

The server provides several tools to interact with GitLab:

File Operations

Create or Update a File

Tool: create_or_update_file
Inputs:
- project_id: Project ID or URL-encoded path
- file_path: Path where to create/update the file
- content: Content of the file
- commit_message: Commit message
- branch: Branch to create/update the file in
- previous_path (optional): Path of the file to move/rename

Push Multiple Files

Tool: push_files
Inputs:
- project_id: Project ID or URL-encoded path
- branch: Branch to push to
- files: Array of files to push, each with file_path and content
- commit_message: Commit message

Get File Contents

Tool: get_file_contents
Inputs:
- project_id: Project ID or URL-encoded path
- file_path: Path to file/directory
- ref (optional): Branch/tag/commit to get contents from

Repository Management

Search Repositories

Tool: search_repositories
Inputs:
- search: Search query
- page (optional): Page number for pagination
- per_page (optional): Results per page (default 20)

Create Repository

Tool: create_repository
Inputs:
- name: Project name
- description (optional): Project description
- visibility (optional): 'private', 'internal', or 'public'
- initialize_with_readme (optional): Initialize with README

Fork Repository

Tool: fork_repository
Inputs:
- project_id: Project ID or URL-encoded path
- namespace (optional): Namespace to fork to

Create Branch

Tool: create_branch
Inputs:
- project_id: Project ID or URL-encoded path
- branch: Name for new branch
- ref (optional): Source branch/commit for new branch

Issue and Merge Request Management

Create Issue

Tool: create_issue
Inputs:
- project_id: Project ID or URL-encoded path
- title: Issue title
- description (optional): Issue description
- assignee_ids (optional): User IDs to assign
- labels (optional): Labels to add
- milestone_id (optional): Milestone ID

Create Merge Request

Tool: create_merge_request
Inputs:
- project_id: Project ID or URL-encoded path
- title: MR title
- description (optional): MR description
- source_branch: Branch containing changes
- target_branch: Branch to merge into
- draft (optional): Create as draft MR
- allow_collaboration (optional): Allow commits from upstream members

Environment Variables

  • GITLAB_PERSONAL_ACCESS_TOKEN: Your GitLab personal access token (required)
  • GITLAB_API_URL: Base URL for GitLab API (optional, defaults to https://gitlab.com/api/v4)

How to add this MCP server to 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 > MCP and click "Add new global MCP server".

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

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

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