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.
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
- Clone or download this repository
- Install dependencies:
npm install - Build the project:
npm run build
Configuration
Set the following environment variables:
Required
GITLAB_HOST: Your GitLab instance URL (e.g.,https://gitlab.example.comorhttps://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
- Go to your GitLab instance
- Navigate to User Settings → Access Tokens
- Create a new token with
apiscope - 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 pathsourceBranch(string): Source branch nametargetBranch(string): Target branch nametitle(string): Merge request titledescription(optional string): Merge request descriptionlabels(optional string[]): Labels to applyassigneeId/assigneeIds(optional number / number[]): Assignee user IDsreviewerId/reviewerIds(optional number / number[]): Reviewer user IDsremoveSourceBranch(optional boolean): Remove the source branch on mergeallowCollaboration(optional boolean): Allow upstream members to pushallowMaintainerToPush(optional boolean): Allow maintainers to pushsquash(optional boolean): Suggest squashing commits on mergetargetProjectId(optional number): Target project ID for cross-project MRsdraft(optional boolean): Prefix the title withDraft:
list_merge_requests
List merge requests for a project.
Parameters:
projectId(string): GitLab project ID or pathstate(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 pathmergeRequestIid(number): Merge request internal ID (IID)
get_pipeline_jobs
Get jobs for a pipeline.
Parameters:
projectId(string): GitLab project ID or pathpipelineId(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 pathpipelineId(optional number): Pipeline IDmergeRequestIid(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 pathjobId(number): Job ID
get_job_artifacts
Get job artifacts metadata and download links for a job.
Parameters:
projectId(string): GitLab project ID or pathjobId(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 implementationsrc/gitlab-client.ts: GitLab API client wrapperpackage.json: Dependencies and scriptstsconfig.json: TypeScript configuration
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.