返回市场
MCP GitLab 服务器

MCP GitLab 服务器

作者:yoda-digital29 星标更新:2025-08-05

项目介绍

技术文档摘要

GitLab MCP 服务器

<p align="center"> <img src="./assets/repo-logo.png" alt="GitLab MCP 服务器 Logo" width="200"> </p> <p align="center"> <a href="https://www.npmjs.com/package/@yoda.digital/gitlab-mcp-server"> <img alt="npm" src="https://img.shields.io/npm/v/@yoda.digital/gitlab-mcp-server?color=blue"> </a> <a href="https://github.com/yoda-digital/mcp-gitlab-server/blob/main/LICENSE"> <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg"> </a> <a href="https://github.com/yoda-digital/mcp-gitlab-server/issues"> <img alt="GitHub issues" src="https://img.shields.io/github/issues/yoda-digital/mcp-gitlab-server"> </a> <a href="https://github.com/yoda-digital/mcp-gitlab-server/stargazers"> <img alt="GitHub stars" src="https://img.shields.io/github/stars/yoda-digital/mcp-gitlab-server"> </a> </p> <p align="center"> <b>一个强大的模型上下文协议(MCP)服务器,用于与GitLab集成,使AI助手能够与您的GitLab资源进行交互。</b> </p>

✨ 特性

  • 全面的GitLab API集成 - 访问仓库、问题、合并请求、维基等
  • 支持两种传输方式 - 使用stdio或服务端发送事件(SSE)
  • 一致的响应格式化 - 标准化的分页和响应结构
  • 强类型安全 - 使用MCP SDK构建以确保类型安全
  • 完整的文档 - 提供所有可用工具的示例

🔍 支持的操作

  • 仓库管理 - 搜索、创建、分叉仓库
  • 文件处理 - 读取、创建、更新文件
  • 分支操作 - 创建和管理分支
  • 问题跟踪 - 创建、列出、筛选问题
  • 合并请求 - 创建、列出、审查合并请求
  • 组管理 - 列出组项目和成员
  • 项目活动 - 跟踪事件和提交历史
  • 维基管理 - 完整支持带有附件的项目和组维基
  • 成员管理 - 列出并管理项目/组成员

🚀 快速开始

安装

从npm安装(推荐)

npm install @yoda.digital/gitlab-mcp-server

从源代码安装

# 克隆仓库
git clone https://github.com/yoda-digital/mcp-gitlab-server.git
cd mcp-gitlab-server

# 安装依赖
npm install

# 构建项目
npm run build

配置

环境变量

服务器需要以下环境变量:

变量必需默认值描述
GITLAB_PERSONAL_ACCESS_TOKEN-您的GitLab个人访问令牌
GITLAB_API_URLhttps://gitlab.com/api/v4GitLab API URL
PORT3000SSE传输使用的端口
USE_SSEfalse设置为'true'以使用SSE传输
GITLAB_READ_ONLY_MODEfalse设置为'true'以启用只读模式(见下文)

只读模式

GITLAB_READ_ONLY_MODE设置为true时,服务器将仅暴露读取操作。这对于不应具有写入权限的客户端应用程序非常有用。在只读模式下,将提供以下工具:

  • search_repositories
  • get_file_contents
  • list_group_projects
  • get_project_events
  • list_commits
  • list_issues
  • list_merge_requests
  • list_project_wiki_pages
  • get_project_wiki_page
  • list_group_wiki_pages
  • get_group_wiki_page
  • list_project_members
  • list_group_members

任何尝试使用写操作(创建、更新、删除)的行为将在只读模式下导致错误。

MCP设置配置

将GitLab MCP服务器添加到您的MCP设置文件中:

{
  "mcpServers": {
    "gitlab": {
      "command": "npx",
      "args": ["-y", "@yoda.digital/gitlab-mcp-server"],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "your_token_here",
        "GITLAB_API_URL": "https://gitlab.com/api/v4"
      },
      "alwaysAllow": [],
      "disabled": false
    }
  }
}

对于只读模式,添加GITLAB_READ_ONLY_MODE环境变量:

{
  "mcpServers": {
    "gitlab-readonly": {
      "command": "npx",
      "args": ["-y", "@yoda.digital/gitlab-mcp-server"],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "your_token_here",
        "GITLAB_API_URL": "https://gitlab.com/api/v4",
        "GITLAB_READ_ONLY_MODE": "true"
      },
      "alwaysAllow": [],
      "disabled": false
    }
  }
}

使用方法

使用stdio传输(默认)

# 设置您的GitLab个人访问令牌
export GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here

# 运行服务器
npm start

使用SSE传输

# 设置您的GitLab个人访问令牌并启用SSE
export GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here
export GITLAB_READ_ONLY_MODE=false
export USE_SSE=true
export PORT=3000  # 可选,默认为3000

# 运行服务器
npm start

使用npx

# 直接使用npx运行
GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here npx @yoda.digital/gitlab-mcp-server

🛠️ 可用工具

仓库操作

<details> <summary><b>search_repositories</b>: 搜索GitLab项目</summary>
{
  "search": "项目名称",
  "page": 1,
  "per_page": 20
}
</details> <details> <summary><b>create_repository</b>: 在GitLab中创建一个新的项目</summary>
{
  "name": "新项目",
  "description": "一个新项目",
  "visibility": "private",
  "initialize_with_readme": true
}
</details> <details> <summary><b>fork_repository</b>: 分叉一个GitLab项目</summary>
{
  "project_id": "用户名/项目",
  "namespace": "目标命名空间"
}
</details> <details> <summary><b>list_group_projects</b>: 列出特定GitLab组内的所有项目</summary>
{
  "group_id": "组名",
  "archived": false,
  "visibility": "public",
  "include_subgroups": true,
  "page": 1,
  "per_page": 20
}
</details>

文件操作

<details> <summary><b>get_file_contents</b>: 获取GitLab项目中的文件内容</summary>
{
  "project_id": "用户名/项目",
  "file_path": "路径/to/文件.txt",
  "ref": "main"
}
</details> <details> <summary><b>create_or_update_file</b>: 在GitLab项目中创建或更新单个文件</summary>
{
  "project_id": "用户名/项目",
  "file_path": "路径/to/文件.txt",
  "content": "文件内容",
  "commit_message": "添加/更新文件",
  "branch": "main",
  "previous_path": "旧路径/to/文件.txt"
}
</details> <details> <summary><b>push_files</b>: 将多个文件推送到GitLab项目的单个提交中</summary>
{
  "project_id": "用户名/项目",
  "files": [
    {
      "path": "文件1.txt",
      "content": "文件1的内容"
    },
    {
      "path": "文件2.txt",
      "content": "文件2的内容"
    }
  ],
  "commit_message": "添加多个文件",
  "branch": "main"
}
</details>

分支操作

<details> <summary><b>create_branch</b>: 在GitLab项目中创建新的分支</summary>
{
  "project_id": "用户名/项目",
  "branch": "新分支",
  "ref": "main"
}
</details>

问题操作

<details> <summary><b>create_issue</b>: 在GitLab项目中创建新的问题</summary>
{
  "project_id": "用户名/项目",
  "title": "问题标题",
  "description": "问题描述",
  "assignee_ids": [1, 2],
  "milestone_id": 1,
  "labels": ["bug", "critical"]
}
</details> <details> <summary><b>list_issues</b>: 获取GitLab项目的问题列表,并进行过滤</summary>
{
  "project_id": "用户名/项目",
  "state": "opened",
  "labels": "bug,critical",
  "milestone": "v1.0",
  "author_id": 1,
  "assignee_id": 2,
  "search": "关键词",
  "created_after": "2023-01-01T00:00:00Z",
  "created_before": "2023-12-31T23:59:59Z",
  "updated_after": "2023-06-01T00:00:00Z",
  "updated_before": "2023-06-30T23:59:59Z",
  "page": 1,
  "per_page": 20
}
</details> <details> <summary><b>list_issue_notes</b>: 获取GitLab问题的所有评论和系统注释</summary>
{
  "project_id": "用户名/项目",
  "issue_iid": 42,
  "sort": "desc",
  "order_by": "created_at",
  "page": 1,
  "per_page": 20
}

响应格式:

{
  "count": 15,
  "notes": [
    {
      "id": 123456,
      "body": "这是对问题的评论",
      "author": {
        "id": 1,
        "username": "用户名",
        "name": "用户姓名"
      },
      "created_at": "2023-01-01T00:00:00Z",
      "updated_at": "2023-01-01T00:00:00Z",
      "system": false,
      "type": "comment"
    },
    {
      "id": 123457,
      "body": "添加标签~bug",
      "author": {
        "id": 1,
        "username": "用户名",
        "name": "用户姓名"
      },
      "created_at": "2023-01-02T00:00:00Z",
      "updated_at": "2023-01-02T00:00:00Z",
      "system": true,
      "type": "system"
    }
    // ... 其他注释
  ]
}
</details> <details> <summary><b>list_issue_discussions</b>: 获取GitLab问题的所有讨论(线程式评论)</summary>
{
  "project_id": "用户名/项目",
  "issue_iid": 42,
  "page": 1,
  "per_page": 20
}

响应格式:

{
  "count": 5,
  "discussions": [
    {
      "id": "discussion-123",
      "individual_note": true,
      "notes": [
        {
          "id": 123456,
          "body": "这是对问题的评论",
          "author": {
            "id": 1,
            "username": "用户名",
            "name": "用户姓名"
          },
          "created_at": "2023-01-01T00:00:00Z",
          "updated_at": "2023-01-01T00:00:00Z",
          "system": false,
          "type": "comment"
        }
      ]
    },
    {
      "id": "discussion-124",
      "individual_note": false,
      "notes": [
        {
          "id": 123457,
          "body": "这是线程的开头",
          "author": {
            "id": 1,
            "username": "用户名",
            "name": "用户姓名"
          },
          "created_at": "2023-01-02T00:00:00Z",
          "updated_at": "2023-01-02T00:00:00Z",
          "system": false,
          "type": "comment"
        },
        {
          "id": 123458,
          "body": "这是线程中的回复",
          "author": {
            "id": 2,
            "username": "用户名2",
            "name": "用户姓名2"
          },
          "created_at": "2023-01-03T00:00:00Z",
          "updated_at": "2023-01-03T00:00:00Z",
          "system": false,
          "type": "comment"
        }
      ]
    }
    // ... 其他讨论
  ]
}
</details>

合并请求操作

<details> <summary><b>create_merge_request</b>: 在GitLab项目中创建新的合并请求</summary>
{
  "project_id": "用户名/项目",
  "title": "合并请求标题",
  "description": "合并请求描述",
  "source_branch": "功能分支",
  "target_branch": "main",
  "allow_collaboration": true,
  "draft": false
}
</details> <details> <summary><b>list_merge_requests</b>: 获取GitLab项目中的合并请求列表,并进行过滤</summary>
{
  "project_id": "用户名/项目",
  "state": "opened",
  "order_by": "created_at",
  "sort": "desc",
  "milestone": "v1.0",
  "labels": "feature,enhancement",
  "created_after": "2023-01-01T00:00:00Z",
  "created_before": "2023-12-31T23:59:59Z",
  "updated_after": "2023-06-01T00:00:00Z",
  "updated_before": "2023-06-30T23:59:59Z",
  "author_id": 1,
  "assignee_id": 2,
  "search": "关键词",
  "source_branch": "功能分支",
  "target_branch": "main",
  "page": 1,
  "per_page": 20
}
</details>

项目活动

<details> <summary><b>get_project_events</b>: 获取GitLab项目的最近事件/活动</summary>
{
  "project_id": "用户名/项目",
  "action": "pushed",
  "target_type": "issue",
  "before": "2023-12-31T23:59:59Z",
  "after": "2023-01-01T00:00:00Z",
  "sort": "desc",
  "page": 1,
  "per_page": 20
}
</details> <details> <summary><b>list_commits</b>: 获取GitLab项目的提交历史</summary>
{
  "project_id": "用户名/项目",
  "sha": "分支或提交SHA",
  "path": "路径/to/文件",
  "since": "2023-01-01T00:00:00Z",
  "until": "2023-12-31T23:59:59Z",
  "all": true,
  "with_stats": true,
  "first_parent": true,
  "page": 1,
  "per_page": 20
}
</details>

成员操作

<details> <summary><b>list_project_members</b>: 列出GitLab项目的成员(包括继承成员)</summary>
{
  "project_id": "用户名/项目",
  "query": "搜索词",
  "page": 1,
  "per_page": 20
}

响应格式:

{
  "count": 3,
  "items": [
    {
      "id": 123,
      "username": "用户名",
      "name": "用户姓名",
      "state": "active",
      "avatar_url": "https://gitlab.com/avatar.png",
      "web_url": "https://gitlab.com/用户名",
      "access_level": 50,
      "access_level_description": "