Skip to main content

GitLab MCP Server

一个用于 GitLab 集成的 Model Context Protocol (MCP) 服务器。

功能特性

  • 🚀 基于 FastMCP 构建的高性能 MCP 服务器
  • 🔧 支持创建 GitLab 合并请求(Merge Request)
  • 🔐 安全的环境变量配置管理
  • 🛠 支持多种安装和运行方式

环境要求

  • Python 3.12+
  • 有效的 GitLab 访问权限(GitLab URL 和用户访问令牌)

安装

方法一:使用 uvx(推荐)

# 临时运行
uvx gitlab-helper-mcp

# 或永久安装
uv tool install gitlab-helper-mcp

方法二:使用 pip

pip install gitlab-helper-mcp

方法三:开发安装

git clone <repository-url>
cd gitlab-helper-mcp
uv sync
uv run python main.py

配置

在运行之前,需要设置以下环境变量:

export GITLAB_URL=https://gitlab.example.com
export GITLAB_USER_ACCESS_TOKEN=your_gitlab_access_token_here

或者创建 .env 文件:

GITLAB_URL=https://gitlab.example.com
GITLAB_USER_ACCESS_TOKEN=your_gitlab_access_token_here

获取 GitLab 访问凭据

  1. 登录你的 GitLab 实例
  2. 进入 User Settings > Access Tokens
  3. 创建一个新的个人访问令牌,选择以下权限:
    • api - 完整的 API 访问权限
    • read_user - 读取用户信息
    • read_repository - 读取仓库
    • write_repository - 写入仓库(用于创建 MR)
  4. 复制生成的访问令牌

使用方法

作为独立服务器运行

# 使用 uvx
uvx gitlab-helper-mcp

# 或使用已安装的命令
gitlab-helper-mcp

# 或使用 Python 模块
python -m gitlab_helper_mcp

# 或直接运行
uv run python main.py

在 Claude Desktop 中使用

在 Claude Desktop 的配置文件中添加:

{
  "mcpServers": {
    "gitlab-helper": {
      "command": "uvx",
      "args": ["gitlab-helper-mcp"],
      "env": {
        "GITLAB_URL": "https://gitlab.example.com",
        "GITLAB_USER_ACCESS_TOKEN": "your_gitlab_access_token_here"
      }
    }
  }
}

可用工具

create_merge_request

创建 GitLab 合并请求(Merge Request)。

参数:

  • project_name (string): 项目名称,格式为 group/project
  • source_branch (string): 源分支名称
  • target_branch (string): 目标分支名称
  • title (string): 合并请求标题
  • description (string): 合并请求描述

返回:

  • 合并请求的 Web URL

示例使用:

# 创建一个新的合并请求
create_merge_request(
    project_name="mygroup/myproject",
    source_branch="feature/new-feature",
    target_branch="main",
    title="Add new feature",
    description="This MR adds a new feature to improve user experience."
)

开发

环境设置

# 克隆仓库
git clone <repository-url>
cd gitlab-helper-mcp

# 创建虚拟环境并安装依赖
uv venv
uv sync

# 运行开发服务器
uv run python main.py

代码质量检查

# 运行 linter
ruff check

# 格式化代码
ruff format

构建和发布

# 构建包
uv build

# 发布到 PyPI(需要配置 PyPI 凭据)
twine upload dist/*

许可证

MIT License - 详见 LICENSE 文件。

贡献

欢迎提交 Issue 和 Pull Request!

支持

如有问题,请在 GitHub Issues 中提出。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitlab_helper_mcp-0.1.3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitlab_helper_mcp-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file gitlab_helper_mcp-0.1.3.tar.gz.

File metadata

  • Download URL: gitlab_helper_mcp-0.1.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for gitlab_helper_mcp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 42e5dd6c3d494e70d4f829021907784289f641065efff022c60d5e834790fe35
MD5 63e4c2063d680a5c9eb0b7a3fadac715
BLAKE2b-256 8a4442f2f11f8ba55cc4c2d7466eb81f241e7f1edabb5785ac9ddc2288205318

See more details on using hashes here.

File details

Details for the file gitlab_helper_mcp-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gitlab_helper_mcp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 815af41b6415e17720b340e8da2dcdaa6132d27bbbe71b60721a6648043f138c
MD5 014a71c3e5a685c525b8264607edb567
BLAKE2b-256 b7a3a861e15345ec13221fb13051de9df2a7645b98d69091bdf6af81368a130a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 files

0.1.2

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page