GitLab Pipeline MCP Server

GitLab Pipeline MCP Server

Enables AI clients to manage GitLab pipelines through natural language commands. Supports triggering pipelines, checking status, listing pipelines, viewing jobs, and canceling pipelines across multiple GitLab instances.

Category
Visit Server

README

GitLab Pipeline MCP Server

一个用于 GitLab 流水线操作的 Model Context Protocol (MCP) 服务器。

🎯 项目概述

本项目允许AI客户端(如Cursor、Claude Desktop等)通过自然语言直接操作GitLab流水线。

功能特性

  • 🚀 触发 GitLab 流水线
  • 📊 获取流水线状态
  • 📋 列出流水线
  • 🔧 获取流水线作业
  • ❌ 取消流水线

安装

yarn install

环境变量配置

在使用前,请设置以下环境变量:

export GITLAB_URL="https://gitlab.example.com"
export GITLAB_PROJECT_ID="123"
export GITLAB_TOKEN="your-gitlab-token"

或者创建 .env 文件:

GITLAB_URL=https://gitlab.example.com
GITLAB_PROJECT_ID=123
GITLAB_TOKEN=your-gitlab-token

使用方式

1. STDIO 模式(标准输入输出)

适用于 MCP 客户端直接连接:

# 使用原版实现(支持所有5个工具)
yarn build

MCP 客户端配置示例:

{
  "mcpServers": {
    "gitlab": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/TO/PARENT/FOLDER/mcp-gitlab/build/index.js"],//你的路径
      "env": {
        "GITLAB_URL": "https://gitlab.example.com",
        "GITLAB_PROJECT_ID": "123",
        "GITLAB_TOKEN": "your-gitlab-token"
      }
    }
  }
}

2. Streamable HTTP 模式

适用于开发和调试,支持 HTTP 端点访问:

# 使用原版实现(支持所有5个工具)
yarn dev

MCP 客户端配置示例:

{
  "mcpServers": {
    "gitlab-http": {
      "env": {
        "GITLAB_URL": "https://gitlab.example.com",
        "GITLAB_PROJECT_ID": "123",
        "GITLAB_TOKEN": "your-gitlab-token"
      },
      "url": "http://localhost:3300/mcp"
    }
  }
}

HTTP 端点:

  • 🔗 MCP 端点: http://localhost:3300/mcp
  • 💚 健康检查: http://localhost:3300/health
  • 📋 服务信息: http://localhost:3300/

🔧 使用MCP Inspector调试

# 启动调试界面
./debug-with-inspector.sh

这将打开一个Web界面(通常在 http://localhost:5173),你可以在其中:

  • 查看所有可用工具
  • 测试工具调用
  • 查看请求和响应
  • 调试参数传递

🛠️ 核心功能

动态参数支持

所有工具都支持动态传入以下参数,无需预先配置:

  • gitlabUrl: GitLab基础URL(如:https://gitlab.com
  • projectId: 项目ID或路径(如:123group/project
  • token: GitLab访问令牌(如:glpat-xxxxxxxxxxxx

可用工具列表

工具名称 功能描述 主要参数
trigger_pipeline 触发流水线 gitlabUrl, projectId, ref, token, variables(可选)
get_pipeline_status 获取流水线状态 gitlabUrl, projectId, pipelineId, token
list_pipelines 列出流水线 gitlabUrl, projectId, token, ref(可选), status(可选)
get_pipeline_jobs 获取流水线作业 gitlabUrl, projectId, pipelineId, token
cancel_pipeline 取消流水线 gitlabUrl, projectId, pipelineId, token

💬 使用示例

在支持MCP的AI客户端中,你可以使用自然语言来操作GitLab流水线:

基础操作

"帮我触发 mygroup/myproject 项目的 main 分支流水线,GitLab地址是 https://gitlab.example.com,使用令牌 glpat-xxxxxxxxxxxx"

"查看项目 123 在 https://gitlab.com 上的流水线 456 的状态"

"列出 mygroup/myproject 项目最近的流水线,只显示失败的"

高级操作

"触发流水线时传入环境变量 DEPLOY_ENV=production 和 VERSION=v1.2.3"

"取消正在运行的流水线 789"

"查看流水线 456 的所有作业状态,看看哪个作业失败了"

多环境支持

"在我们的私有GitLab https://gitlab.company.com 上触发项目 team/backend 的 develop 分支流水线"

"检查生产环境流水线状态,项目在 https://gitlab.com/prod/app,流水线ID是 999"

🔐 安全配置

GitLab访问令牌

  1. 登录GitLab
  2. 进入 Settings > Access Tokens
  3. 创建新令牌,需要以下权限:
    • api - 完整API访问权限
    • read_repository - 读取仓库权限
    • write_repository - 写入仓库权限

环境变量安全

  • 永远不要将 .env 文件提交到版本控制
  • 使用不同的令牌用于不同的环境
  • 定期轮换访问令牌
  • 限制令牌的权限范围

📁 项目结构

mcp-gitlab/
├── src/                          # 源代码
│   ├── index.ts                  # 主服务器文件
│   ├── services/
│   │   └── gitlab.ts             # GitLab API服务
│   └── utils/
│       └── logger.ts             # 日志工具
├── dist/                         # 构建输出
├── .env.example                  # 环境变量模板
├── mcp-config-examples.json      # MCP客户端配置示例
├── test-server.js                # 服务器测试脚本
├── debug-with-inspector.sh       # 调试脚本
├── package.json                  # 项目配置
├── tsconfig.json                 # TypeScript配置
└── README.md                     # 项目说明

🐛 常见问题

Q: 服务器启动失败

A: 检查Node.js版本(需要>=18),确保依赖已安装,检查TypeScript编译错误。

Q: GitLab API调用失败

A: 验证访问令牌权限,检查GitLab URL格式,确认项目ID正确。

Q: MCP客户端连接不上

A: 检查配置文件路径,确认服务器已构建,查看客户端日志。

Q: 工具调用参数错误

A: 参考工具定义中的参数要求,使用MCP Inspector测试参数格式。

📚 相关资源

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured