Skip to main content

A Model Context Protocol (MCP) server for GitLab integration

Project description

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 中提出。

Project details


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.2.tar.gz (8.6 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.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gitlab_helper_mcp-0.1.2.tar.gz
  • Upload date:
  • Size: 8.6 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.2.tar.gz
Algorithm Hash digest
SHA256 61b5169af96e043b3e4fd02e0aded6dbf3b91a27d3dd14958c892a2427694689
MD5 06fcfbb3cd17aa9bcf12aa9bdf1fb1cb
BLAKE2b-256 55f962b0d57cccb3d55f0165e4cd132edc62c5c145da369ab0c2c91d590bd531

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gitlab_helper_mcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f1686e1fbead7d341f56cad9f1209030d768efe9b6cec973e8fae0de55a4b78
MD5 9e57dc7221b39b20f17f493e6e473f20
BLAKE2b-256 82b0cf0315358cd392148424a14540bde6178579ac657ce0bd4a574ab42b7f34

See more details on using hashes here.

Supported by

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