GitLab代码审查MCP服务

GitLab MCP Server 是通过 Model Context Protocol 将 AI 助手连接到自托管 GitLab 实例的服务器,提供合并请求管理、代码差异查看、仓库浏览与代码搜索等功能,用于在 GitLab 上实现 AI 辅助代码评审和开发协作。

  • by SynclyAI
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 SynclyAI/gitlab-mcp

使用说明

GitLab MCP Server

MCP (Model Context Protocol) server for AI-assisted code review with GitLab on-premise instances.

Features

Merge Request Tools

  • List, get, create, update merge requests
  • Set MR draft status
  • List changed files, get one file's diff or all MR changes
  • Get MR commits and pipelines
  • Get notes and discussions, add notes, start discussions on the MR or on a diff line
  • Reply to, resolve, edit and delete comments
  • Approve, unapprove, merge MRs

Repository Tools

  • List projects
  • Browse repository tree
  • Get file content, whole or by line range, and blame
  • Search code
  • List branches and commits

Security Model

Uses OAuth with intersection-based access control:

  • User authenticates via GitLab OAuth
  • AI access limited to repos both user AND service account can access
  • All API calls made with service account token for audit trail

Prerequisites

  • Python 3.11+
  • GitLab instance with OAuth application configured
  • SSL certificate for HTTPS

Setup

1. GitLab OAuth Application

Create in GitLab Admin > Applications:

  • Redirect URI: https://<server-host>:<port>/oauth/callback
  • Scopes: read_user, read_api, read_repository, api (for write operations)
  • Confidential: Yes

2. Secrets File

Create a JSON file with credentials:

{
  "oauth_client_id": "<gitlab-oauth-app-id>",
  "oauth_client_secret": "<gitlab-oauth-app-secret>",
  "service_token": "<service-account-personal-access-token>"
}

3. Environment Variables

Variable Required Description
GITLAB_URL yes GitLab instance URL
GITLAB_SECRETS_PATH yes Path to secrets JSON file
MCP_SERVER_BIND_URL yes Bind URL with protocol and port (e.g., https://0.0.0.0:8443 or http://0.0.0.0:8080)
MCP_SERVER_ADVERTISED_URL yes Client-facing URL (e.g., https://mcp.example.com:8443)
MCP_SSL_CERT_PATH when bind uses https Path to SSL certificate
MCP_SSL_KEY_PATH when bind uses https Path to SSL private key
SSL_CERT_FILE no CA certificate for GitLab (self-signed certs)

4. Install

pip install .

Running

gitlab-mcp

Docker

Each release is published to the GitHub Container Registry:

docker pull ghcr.io/synclyai/gitlab-mcp:1.1.1
docker pull ghcr.io/synclyai/gitlab-mcp:latest

To build locally instead, the image installs a pre-built wheel and dist/ is the build context:

make image

Equivalent to building the wheel into an emptied dist/ and running docker build -f Dockerfile -t ghcr.io/synclyai/gitlab-mcp:<version> dist/, so a local build carries the same name as the published image. The wheel is built with venv/bin/python, so the dev extra must be installed.

Development

pip install -e ".[dev]"
pytest