M

MCP-GitLab管理器

一种模型上下文协议服务器,通过自然语言与GitLab账户进行交互,以管理仓库、合并请求、代码审查和CI/CD管道。

version-controldeveloper-tools

727 查看 · 2026-07-07 更新

简介

一种模型上下文协议服务器,通过自然语言与GitLab账户进行交互,以管理仓库、合并请求、代码审查和CI/CD管道。

简介

一种模型上下文协议服务器,通过自然语言与GitLab账户进行交互,以管理仓库、合并请求、代码审查和CI/CD管道。

GitLab MCP 服务器

这是一个模型上下文协议 (MCP) 服务器,它使您能够与您的 GitLab 账户进行交互。获取差异、分析合并请求、审查代码、挑选更改等。这是从 Model Context Protocol 项目中的 MCP GitLab 服务器 扩展而来的版本。

GitLab 服务器 MCP 服务器

功能

此 MCP 服务器提供了与 GitLab 仓库互动的全面工具,包括:

核心仓库功能

  • 列出项目并检索详细信息
  • 管理分支和仓库
  • 处理合并请求和差异
  • 向合并请求添加评论和内部注释
  • 更新合并请求属性
  • 列出和处理问题
  • 获取和比较仓库文件内容

项目设置与集成

  • 管理项目集成和服务
  • 配置和控制 Slack 集成
  • 设置、更新和测试 Webhook

CI/CD 管理

  • 处理管道触发令牌
  • 管理 CI/CD 变量
  • 触发和控制管道

用户与组管理

  • 列出和管理用户
  • 处理组和组成员资格
  • 管理项目成员和访问级别

安装

先决条件

  • Node.js(v16 或更高版本)
  • npm
  • 一个带有 API 令牌的 GitLab 账户

设置

  1. 克隆仓库:
git clone https://github.com/rifqi96/mcp-gitlab.git cd mcp-gitlab
  1. 安装依赖项:
npm install
  1. 构建服务器:
npm run build
  1. 安装 git 钩子(可选,但推荐给贡献者):
npm run install-hooks

这将安装一个 pre-commit 钩子,当 src/utils/tools-data.ts 发生变化时自动重新生成 TOOLS.md。

  1. 配置您的 GitLab API 令牌:

您需要在 MCP 设置配置文件中提供您的 GitLab API 令牌。该令牌用于与 GitLab API 进行身份验证。

对于 Cursor/Roo Cline,在您的 MCP 设置文件 (~/Library/Application Support/Cursor/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json) 中添加以下内容:

{ "mcpServers": { "gitlab": { "command": "node", "args": [ "/path/to/mcp-gitlab/build/index.js" ], "env": { "GITLAB_API_TOKEN": "YOUR_GITLAB_API_TOKEN", "GITLAB_API_URL": "https://gitlab.com/api/v4" } } } }

对于 Claude Desktop,在您的 MCP 设置文件 (~/Library/Application Support/Claude/claude_desktop_config.json) 中添加以下内容:

{ "mcpServers": { "gitlab": { "command": "node", "args": [ "/path/to/mcp-gitlab/build/index.js" ], "env": { "GITLAB_API_TOKEN": "YOUR_GITLAB_API_TOKEN", "GITLAB_API_URL": "https://gitlab.com/api/v4" } } } }

YOUR_GITLAB_API_TOKEN 替换为您的实际 GitLab API 令牌。您可以在您的 GitLab 账户下的设置 > 访问令牌中生成一个令牌。

可用工具

有关可用工具及其参数的完整列表,请参阅 TOOLS.md

示例用法

这里是一些如何使用这些工具的例子,这些工具支持 MCP 的 AI 助手:

列出您的项目

Could you list my GitLab projects?

获取特定合并请求的信息

Can you show me the details of merge request with ID 123 in the project 'mygroup/myproject'?

向合并请求添加评论

Please add a comment to merge request 123 in project 'mygroup/myproject' saying "This looks good, but please add more tests."

向合并请求添加内部注释

Add an internal note to merge request 123 in project 'mygroup/myproject' that says "Needs security review before merging." Make sure it's only visible to team members.

更新合并请求的标题和描述

Update the title of merge request 123 in project 'mygroup/myproject' to "Fix login page performance issues" and update the description to include "This PR addresses the slow loading times on the login page by optimizing database queries."

比较分支

Compare the 'feature-branch' with 'main' in the project 'mygroup/myproject' and show me the differences.

实用工作流程

审查合并请求

1. Show me merge request 123 in project 'mygroup/myproject' 2. Show me the changes for this merge request 3. Add an internal note with my review comments 4. Update the merge request title to better reflect the changes

项目探索

1. List all my GitLab projects 2. Show me the details of project 'mygroup/myproject' 3. List all branches in this project 4. Show me the content of the README.md file in the main branch

可用资源

gitlab://projects

使用您的 API 令牌可访问的 GitLab 项目列表。

与 AI 助手集成

GitLab MCP 服务器与支持模型上下文协议 (MCP) 的 AI 助手集成。

功能

当连接到 AI 助手时,此服务器使助手能够:

  1. 查看和分析代码:助手可以获取文件内容、查看分支差异并检查合并请求更改以更好地理解代码。
  2. 提供代码审查:助手可以分析合并请求并通过评论或内部笔记提供反馈。
  3. 管理项目工作流程:助手可以更新合并请求属性、添加评论并帮助完成仓库管理工作任务。
  4. 探索项目结构:助手可以浏览项目、分支和文件以了解代码库结构。
  5. 配置 CI/CD 和集成:助手可以帮助设置 Webhook、管理 CI/CD 变量并配置项目集成。

充分利用 AI 助手集成

  • 在询问有关项目、合并请求或文件的问题时要具体明确
  • 尽可能提供项目 ID 或路径
  • 通过让助手分析特定的合并请求来进行代码审查
  • 让助手帮助进行仓库配置和管理工作任务
  • 使用内部笔记为团队成员提供仅限团队的合并请求反馈

许可证

MIT

工具列表

  • gitlab_list_projects: List GitLab projects accessible to the user

  • gitlab_get_project: Get details of a specific GitLab project

  • gitlab_list_branches: List branches of a GitLab project

  • gitlab_list_merge_requests: List merge requests in a GitLab project

  • gitlab_get_merge_request: Get details of a specific merge request

  • gitlab_get_merge_request_changes: Get changes (diff) of a specific merge request

  • gitlab_create_merge_request_note: Add a comment to a merge request

  • gitlab_create_merge_request_note_internal: Add a comment to a merge request with option to make it an internal note

  • gitlab_update_merge_request: Update a merge request title and description

  • gitlab_list_issues: List issues in a GitLab project

  • gitlab_get_repository_file: Get content of a file in a repository

  • gitlab_compare_branches: Compare branches, tags or commits

  • gitlab_list_integrations: List all available project integrations/services

  • gitlab_get_integration: Get integration details for a project

  • gitlab_update_slack_integration: Update Slack integration settings for a project

  • gitlab_disable_slack_integration: Disable Slack integration for a project

  • gitlab_list_webhooks: List webhooks for a project

  • gitlab_get_webhook: Get details of a specific webhook

  • gitlab_add_webhook: Add a new webhook to a project

  • gitlab_update_webhook: Update an existing webhook

  • gitlab_delete_webhook: Delete a webhook

  • gitlab_test_webhook: Test a webhook

  • gitlab_list_trigger_tokens: List pipeline trigger tokens

  • gitlab_get_trigger_token: Get details of a pipeline trigger token

  • gitlab_create_trigger_token: Create a new pipeline trigger token

  • gitlab_update_trigger_token: Update a pipeline trigger token

  • gitlab_delete_trigger_token: Delete a pipeline trigger token

  • gitlab_trigger_pipeline: Trigger a pipeline run

  • gitlab_list_cicd_variables: List CI/CD variables for a project

  • gitlab_get_cicd_variable: Get a specific CI/CD variable

  • gitlab_create_cicd_variable: Create a new CI/CD variable

  • gitlab_update_cicd_variable: Update a CI/CD variable

  • gitlab_delete_cicd_variable: Delete a CI/CD variable

  • gitlab_list_users: List GitLab users

  • gitlab_get_user: Get details of a specific user

  • gitlab_list_groups: List GitLab groups

  • gitlab_get_group: Get details of a specific group

  • gitlab_list_group_members: List members of a group

  • gitlab_add_group_member: Add a user to a group

  • gitlab_list_project_members: List members of a project

  • gitlab_add_project_member: Add a user to a project

服务配置

[{'mcpServers': {'gitlab': {'args': ['/path/to/mcp-gitlab/build/index.js'], 'command': 'node', 'env': {'GITLAB_API_TOKEN': 'YOUR_GITLAB_API_TOKEN', 'GITLAB_API_URL': 'https://gitlab.com/api/v4'}}}}, {'mcpServers': {'gitlab': {'args': ['/path/to/mcp-gitlab/build/index.js'], 'command': 'node', 'env': {'GITLAB_API_TOKEN': 'YOUR_GITLAB_API_TOKEN', 'GITLAB_API_URL': 'https://gitlab.com/api/v4'}}}}]

来源