G

GitLab版本控制工具

GitLab API的MCP服务器,支持项目管理、文件操作等更多功能。

version-control

1.2w 查看 · 2026-07-07 更新

简介

GitLab API的MCP服务器,支持项目管理、文件操作等更多功能。

简介

GitLab API的MCP服务器,支持项目管理、文件操作等更多功能。

GitLab MCP 服务器

用于 GitLab API 的 MCP 服务器,支持项目管理、文件操作等功能。

功能

  • 自动创建分支:在创建/更新文件或推送更改时,如果分支不存在则会自动创建
  • 全面的错误处理:针对常见问题提供清晰的错误信息
  • 保留 Git 历史记录:操作过程中保持正确的 Git 历史记录,不会强制推送
  • 批量操作:支持单文件和多文件操作

工具

  1. create_or_update_file

    • 创建或更新项目中的单个文件
    • 输入:
      • project_id (字符串): 项目 ID 或 URL 编码路径
      • file_path (字符串): 要创建/更新文件的路径
      • content (字符串): 文件内容
      • commit_message (字符串): 提交信息
      • branch (字符串): 要创建/更新文件的分支
      • previous_path (可选字符串): 要移动/重命名的文件路径
    • 返回: 文件内容和提交详情
  2. push_files

    • 在单次提交中推送多个文件
    • 输入:
      • project_id (字符串): 项目 ID 或 URL 编码路径
      • branch (字符串): 要推送的分支
      • files (数组): 要推送的文件,每个文件包含 file_pathcontent
      • commit_message (字符串): 提交信息
    • 返回: 更新后的分支引用
  3. search_repositories

    • 搜索 GitLab 项目
    • 输入:
      • search (字符串): 搜索查询
      • page (可选数字): 分页页码
      • per_page (可选数字): 每页结果数(默认 20)
    • 返回: 项目搜索结果
  4. create_repository

    • 创建一个新的 GitLab 项目
    • 输入:
      • name (字符串): 项目名称
      • description (可选字符串): 项目描述
      • visibility (可选字符串): 'private', 'internal' 或 'public'
      • initialize_with_readme (可选布尔值): 初始化时包含 README
    • 返回: 创建的项目详情
  5. get_file_contents

    • 获取文件或目录的内容
    • 输入:
      • project_id (字符串): 项目 ID 或 URL 编码路径
      • file_path (字符串): 文件/目录路径
      • ref (可选字符串): 获取内容的分支/标签/提交
    • 返回: 文件/目录内容
  6. create_issue

    • 创建一个新的 issue
    • 输入:
      • project_id (字符串): 项目 ID 或 URL 编码路径
      • title (字符串): Issue 标题
      • description (可选字符串): Issue 描述
      • assignee_ids (可选数字数组): 分配给用户的 ID
      • labels (可选字符串数组): 添加的标签
      • milestone_id (可选数字): 里程碑 ID
    • 返回: 创建的 issue 详情
  7. create_merge_request

    • 创建一个新的合并请求
    • 输入:
      • project_id (字符串): 项目 ID 或 URL 编码路径
      • title (字符串): 合并请求标题
      • description (可选字符串): 合并请求描述
      • source_branch (字符串): 包含更改的分支
      • target_branch (字符串): 要合并到的分支
      • draft (可选布尔值): 作为草稿创建合并请求
      • allow_collaboration (可选布尔值): 允许上游成员提交
    • 返回: 创建的合并请求详情
  8. fork_repository

    • 叉一个项目
    • 输入:
      • project_id (字符串): 项目 ID 或 URL 编码路径
      • namespace (可选字符串): 叉到的命名空间
    • 返回: 叉出的项目详情
  9. create_branch

    • 创建一个新的分支
    • 输入:
      • project_id (字符串): 项目 ID 或 URL 编码路径
      • branch (字符串): 新分支的名称
      • ref (可选字符串): 新分支的源分支/提交
    • 返回: 创建的分支引用

设置

个人访问令牌

创建一个具有适当权限的 GitLab 个人访问令牌

  • 进入 GitLab 的用户设置 > 访问令牌
  • 选择所需的作用域:
    • api 用于完全 API 访问
    • read_api 用于只读访问
    • read_repositorywrite_repository 用于仓库操作- 创建令牌并安全保存

与 Claude Desktop 一起使用

将以下内容添加到您的 claude_desktop_config.json 中:

Docker

json

{ "mcpServers": { "gitlab": { "command": "docker", "args": [ "run", "--rm", "-i", "-e", "GITLAB_PERSONAL_ACCESS_TOKEN", "-e", "GITLAB_API_URL", "mcp/gitlab" ], "env": { "GITLAB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>", "GITLAB_API_URL": "https://gitlab.com/api/v4" // Optional, for self-hosted instances } } } }

NPX

bash

{ "mcpServers": { "gitlab": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-gitlab" ], "env": { "GITLAB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>", "GITLAB_API_URL": "https://gitlab.com/api/v4" // Optional, for self-hosted instances } } } }

构建

Docker 构建: bash

docker build -t vonwig/gitlab:mcp -f src/gitlab/Dockerfile .

环境变量

  • GITLAB_PERSONAL_ACCESS_TOKEN: 您的 GitLab 个人访问令牌(必需)
  • GITLAB_API_URL: GitLab API 的基础 URL(可选,默认为 https://gitlab.com/api/v4

许可证

此 MCP 服务器依据 MIT 许可证发布。这意味着您可以自由地使用、修改和分发该软件,但需遵守 MIT 许可证的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。

工具列表

  • create_or_update_file: Create or update a single file in a GitLab project

  • search_repositories: Search for GitLab projects

  • create_repository: Create a new GitLab project

  • get_file_contents: Get the contents of a file or directory from a GitLab project

  • push_files: Push multiple files to a GitLab project in a single commit

  • create_issue: Create a new issue in a GitLab project

  • create_merge_request: Create a new merge request in a GitLab project

  • fork_repository: Fork a GitLab project to your account or specified namespace

  • create_branch: Create a new branch in a GitLab project

服务配置

[{'mcpServers': {'gitlab': {'args': ['-y', '@modelcontextprotocol/server-gitlab'], 'command': 'npx', 'env': {'GITLAB_API_URL': 'https://gitlab.com/api/v4', 'GITLAB_PERSONAL_ACCESS_TOKEN': '<YOUR_TOKEN>'}}}}]

来源