GitLab MCP Server

GitLab MCP Server

A Model Context Protocol (MCP) server for GitLab integration, written in TypeScript. This server allows you to interact with GitLab merge requests, commits, pipelines, and jobs through MCP tools.

Category
访问服务器

README

GitLab MCP Server

A Model Context Protocol (MCP) server for GitLab integration, written in TypeScript. This server allows you to interact with GitLab merge requests, commits, pipelines, and jobs through MCP tools.

Features

  • 🔍 Get merge request details (title, description, metadata)
  • 📝 Create merge requests in GitLab projects
  • 📄 Retrieve merge request diffs
  • 📋 List merge requests for a project
  • 🔀 Get pipelines for a merge request
  • 🧰 Get jobs for a pipeline
  • 🚨 Get failed jobs by pipeline or merge request
  • 📜 Retrieve job logs (trace)
  • 📦 Retrieve job artifacts metadata and download links
  • 🔐 Supports self-hosted GitLab instances
  • 🔑 Token-based authentication via environment variables

Installation

  1. Clone or download this repository
  2. Install dependencies:
    npm install
    
  3. Build the project:
    npm run build
    

Configuration

Set the following environment variables:

Required

  • GITLAB_HOST: Your GitLab instance URL (e.g., https://gitlab.example.com or https://gitlab.com)
  • GITLAB_API_TOKEN: Your GitLab access token

Optional (for multiple instances)

  • MCP_INSTANCE_ID: Unique identifier for the server instance (useful for logging and identification)

You can copy .env.example to .env and fill in your values:

cp .env.example .env
# Edit .env with your GitLab configuration

Getting a GitLab Access Token

  1. Go to your GitLab instance
  2. Navigate to User Settings → Access Tokens
  3. Create a new token with api scope
  4. Copy the token and set it as GITLAB_API_TOKEN

Usage

Running the Server

Single Instance

# Development mode
npm run dev

# Production mode
npm run build && npm start

Multiple Instances

Each instance runs as a separate process with its own configuration:

# Build first
npm run build

# Instance 1 (in terminal 1)
GITLAB_HOST=https://gitlab.example.com GITLAB_API_TOKEN=token1 MCP_INSTANCE_ID=instance1 npm start

# Instance 2 (in terminal 2)
GITLAB_HOST=https://gitlab.com GITLAB_API_TOKEN=token2 MCP_INSTANCE_ID=instance2 npm start

# Instance 3 (in terminal 3)
GITLAB_HOST=https://gitlab.internal.com GITLAB_API_TOKEN=token3 MCP_INSTANCE_ID=instance3 npm start

Each instance can connect to different GitLab hosts with different tokens, allowing multiple tools to work with different GitLab environments simultaneously.

Available Tools

get_merge_request

Get detailed information about a specific merge request, optionally including the diff/changes.

Parameters:

  • projectId (string): GitLab project ID or path (e.g., "group/project" or "123")
  • mergeRequestIid (number): Merge request internal ID (IID)
  • includeDiff (optional boolean): Whether to include the diff/changes in the response (default: false)

The response includes automation-friendly metadata such as id, iid, draft, source_project_id, target_project_id, labels, assignees, reviewers, diff_refs, and sha. When includeDiff is enabled, the response also includes diff_overflow.

create_merge_request

Create a merge request in a GitLab project.

Parameters:

  • projectId (string): GitLab project ID or path
  • sourceBranch (string): Source branch name
  • targetBranch (string): Target branch name
  • title (string): Merge request title
  • description (optional string): Merge request description
  • labels (optional string[]): Labels to apply
  • assigneeId / assigneeIds (optional number / number[]): Assignee user IDs
  • reviewerId / reviewerIds (optional number / number[]): Reviewer user IDs
  • removeSourceBranch (optional boolean): Remove the source branch on merge
  • allowCollaboration (optional boolean): Allow upstream members to push
  • allowMaintainerToPush (optional boolean): Allow maintainers to push
  • squash (optional boolean): Suggest squashing commits on merge
  • targetProjectId (optional number): Target project ID for cross-project MRs
  • draft (optional boolean): Prefix the title with Draft:

list_merge_requests

List merge requests for a project.

Parameters:

  • projectId (string): GitLab project ID or path
  • state (optional string): Filter by state ("opened", "closed", "merged", "all"). Default: "opened"

get_commit_diff

Get commit details and diff using a full GitLab commit URL.

Parameters:

  • commitUrl (string): Full GitLab commit URL

get_merge_request_pipelines

Get pipelines for a merge request.

Parameters:

  • projectId (string): GitLab project ID or path
  • mergeRequestIid (number): Merge request internal ID (IID)

get_pipeline_jobs

Get jobs for a pipeline.

Parameters:

  • projectId (string): GitLab project ID or path
  • pipelineId (number): Pipeline ID

get_failed_jobs

Get failed jobs either directly by pipeline ID or from the latest pipeline of a merge request.

Parameters:

  • projectId (string): GitLab project ID or path
  • pipelineId (optional number): Pipeline ID
  • mergeRequestIid (optional number): Merge request internal ID (IID)

Provide either pipelineId or mergeRequestIid.

get_job_log

Get job log (trace) for a job.

Parameters:

  • projectId (string): GitLab project ID or path
  • jobId (number): Job ID

get_job_artifacts

Get job artifacts metadata and download links for a job.

Parameters:

  • projectId (string): GitLab project ID or path
  • jobId (number): Job ID

Example Usage with MCP Client

// Get merge request details only
await callTool("get_merge_request", {
  projectId: "mygroup/myproject",
  mergeRequestIid: 42
});

// Get merge request details with diff
await callTool("get_merge_request", {
  projectId: "123",
  mergeRequestIid: 42,
  includeDiff: true
});

// Create a merge request
await callTool("create_merge_request", {
  projectId: "mygroup/myproject",
  sourceBranch: "feature/new-e2e-test",
  targetBranch: "main",
  title: "Add login dashboard E2E coverage",
  description: "## Summary\n- add a generated Playwright test\n- validate the scenario locally",
  labels: ["qa", "e2e"],
  removeSourceBranch: true
});

// List open merge requests
await callTool("list_merge_requests", {
  projectId: "mygroup/myproject",
  state: "opened"
});

// List pipelines for an MR
await callTool("get_merge_request_pipelines", {
  projectId: "mygroup/myproject",
  mergeRequestIid: 42
});

// Get jobs from pipeline
await callTool("get_pipeline_jobs", {
  projectId: "mygroup/myproject",
  pipelineId: 123456
});

// Get failed jobs from latest MR pipeline
await callTool("get_failed_jobs", {
  projectId: "mygroup/myproject",
  mergeRequestIid: 42
});

// Get raw CI job log
await callTool("get_job_log", {
  projectId: "mygroup/myproject",
  jobId: 987654
});

// Get artifact metadata and links
await callTool("get_job_artifacts", {
  projectId: "mygroup/myproject",
  jobId: 987654
});

Multiple Instance Setup

When running multiple instances, each tool/client can connect to a different instance:

MCP Client Configuration Example

{
  "mcpServers": {
    "gitlab-company": {
      "command": "node",
      "args": ["path/to/gitlab-mcp/dist/index.js"],
      "env": {
        "GITLAB_HOST": "https://gitlab.example.com",
        "GITLAB_API_TOKEN": "company_token",
        "MCP_INSTANCE_ID": "company"
      }
    },
    "gitlab-personal": {
      "command": "node",
      "args": ["path/to/gitlab-mcp/dist/index.js"],
      "env": {
        "GITLAB_HOST": "https://gitlab.com",
        "GITLAB_API_TOKEN": "personal_token",
        "MCP_INSTANCE_ID": "personal"
      }
    },
    "gitlab-internal": {
      "command": "node",
      "args": ["path/to/gitlab-mcp/dist/index.js"],
      "env": {
        "GITLAB_HOST": "https://gitlab.internal.company.com",
        "GITLAB_API_TOKEN": "internal_token",
        "MCP_INSTANCE_ID": "internal"
      }
    }
  }
}

This allows different tools to connect to different GitLab instances simultaneously, each with their own authentication and configuration.

Development

The project uses TypeScript and the MCP SDK. Key files:

  • src/index.ts: Main MCP server implementation
  • src/gitlab-client.ts: GitLab API client wrapper
  • package.json: Dependencies and scripts
  • tsconfig.json: TypeScript configuration

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选