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
访问服务器

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测试参数格式。

📚 相关资源

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选