gitlab-mcp-code-review CLAUDE.md

An MCP server that connects an AI assistant to GitLab merge requests, which are proposed code changes awaiting review. It can retrieve changes and manage comments, discussions, approvals, and review rules.

In plain words
What is it for?
Use it to inspect merge requests, compare branches or commits, add or resolve review discussions, approve changes, search projects, or fetch team review rules.
Why use it?
It removes the need to switch between an assistant and GitLab while reviewing and discussing code changes.

Instructions file

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/ffpy/gitlab-mcp-code-review/claude-md
Clone the repo
git clone --depth 1 https://github.com/ffpy/gitlab-mcp-code-review
Per session 1,145 This file is loaded in full into every session.
When invoked 1,145 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01145 $0.01145
Opus 5 $0.00573 $0.00573
Sonnet 5 $0.00229 $0.00229
Haiku 4.5 $0.00114 $0.00114

Measured 2d ago against content hash ebaede9ff504, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

gitlab-mcp-code-review CLAUDE.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

CLAUDE.md · 102 lines

How it starts

The opening of the file, as written. The whole thing — 102 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

项目概述

这是一个 MCP (Model Context Protocol) 服务器,用于将 AI 助手与 GitLab 的合并请求集成。它允许 AI 助手通过 GitLab API 直接审查代码变更、添加评论和管理审批流程。

核心架构

主要文件

  • server.py: MCP 服务器的主入口文件,包含所有工具定义和 GitLab API 集成逻辑
  • config.toml: 配置文件,定义代码审查时需要忽略的文件模式
  • pyproject.toml: Python 项目配置,包含依赖和工具配置

关键组件

  1. FastMCP 服务器: 使用 mcp.server.fastmcp.FastMCP 创建 MCP 服务器
  2. GitLab 客户端: 通过 python-gitlab 库与 GitLab API 交互
  3. 生命周期管理: 使用 gitlab_lifespan 异步上下文管理器管理 GitLab 连接

MCP 工具列表

服务器暴露以下工具(位于 server.py):

  • fetch_merge_request: 获取合并请求的完整信息(包括变更、提交和讨论)
  • compare_versions: 比较两个提交/分支/标签之间的差异
  • add_merge_request_comment: 添加常规评论到合并请求
  • add_merge_request_discussion: 在文件特定位置添加讨论
  • reply_to_merge_request_discussion: 回复讨论
  • resolve_merge_request_discussion: 解决或取消解决讨论
  • delete_merge_request_discussion: 删除讨论
  • approve_merge_request: 批准合并请求
  • unapprove_merge_request: 取消批准合并请求
  • get_project_merge_requests: 获取项目的合并请求列表
  • search_projects: 按名称搜索 GitLab 项目
  • fetch_code_review_rules: 通过 SSH 从远程服务器获取团队的代码审查规范

数据过滤机制

fetch_merge_request 工具实现了智能数据过滤:

  • 使用 config.toml 中的 exclude_patterns 过滤不需要审查的文件
  • 精简 API 响应数据,只返回必要字段,减少 token 使用
  • 支持通配符模式和目录模式匹配(见 is_path_excluded 函数)

环境变量

必需的环境变量(可以在 .env 文件中设置):

  • GITLAB_HOST: GitLab 实例的主机名(默认: gitlab.com)
  • GITLAB_TOKEN: GitLab 个人访问令牌(必需,需要 api 和 read_api 权限)

可选的环境变量(用于代码审查规范功能):

  • CODE_REVIEW_SSH_HOST: SSH 服务器地址
  • CODE_REVIEW_SSH_PORT: SSH 端口(默认: 22)
  • CODE_REVIEW_SSH_USERNAME: SSH 用户名
  • CODE_REVIEW_SSH_PASSWORD: SSH 密码
  • CODE_REVIEW_RULE_FILE: 规范文件在服务器上的绝对路径

常用命令

运行服务器

uv run server.py

安装依赖

uv sync

开发依赖(可选)

uv sync --extra dev

修改代码时的注意事项

  1. 添加新的 MCP 工具: 使用 @mcp.tool() 装饰器,第一个参数必须是 ctx: Context
  2. 访问 GitLab 客户端: 通过 ctx.request_context.lifespan_context 获取 GitLab 客户端实例
  3. 数据精简: 当从 GitLab API 获取数据时,应该只返回必要的字段以减少响应大小
  4. 文件过滤: 修改 config.toml 中的 exclude_patterns 来调整忽略的文件类型
  5. 错误处理: 使用 logger 记录错误,遵循现有的日志模式
  6. 返回类型: 所有工具函数都应该返回可序列化的 Dict 或 List

Read the full file on GitHub · 102 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 102 lines · 1,145 tokens per session scan A ebaede9ff504

Subscribe to this mod's changes

gitlab-mcp-code-review CLAUDE.md is an instructions file published in the GitHub repository ffpy/gitlab-mcp-code-review (4 stars, last pushed 9mo ago), licensed MIT. It adds 1,145 tokens to every session, about $0.0057 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other instructions, from other repositories

spec-kit AGENTS.md

AGENTS.md instructions for github/spec-kit, covering agents.md, about spec kit and specify, quickstart — add a new integration in 5 steps, integration architecture and integrationmanifest — file tracking.

github/spec-kit · 7,104 tokens

codex AGENTS.md

AGENTS.md instructions for openai/codex, covering rust/codex-rs, the codex-core crate, code review rules, crate api surface and model visible context.

openai/codex · 5,182 tokens

vscode buildNext.instructions.md

Working notes and architecture documentation for the new esbuild-based build system in build/next. Use when making changes to the new build pipeline (transpile/bundle commands, NLS plugin, source-map handling, resource copying, or self-hosting watch tasks).

microsoft/vscode · 6,785 tokens

langchain AGENTS.md

AGENTS.md instructions for langchain-ai/langchain, covering global development guidelines for the langchain monorepo, corridor security analysis, project architecture and context, monorepo structure and development tools & commands.

langchain-ai/langchain · 4,345 tokens

vscode oss-third-party-notices.instructions.md

Instructions for microsoft/vscode, covering vs code oss third-party-notices pipeline, architecture, pipeline flow in ci, applying the notice (cutover) and fallback chain (never fail the build).

microsoft/vscode · 5,001 tokens

next.js AGENTS.md

Instructions for vercel/next.js, covering next.js development guide, codebase structure, monorepo overview, core package: packages/next and other important packages.

vercel/next.js · 7,296 tokens