GitLab Code Review MCP Server
Enables AI assistants to interact with GitLab merge requests, review code changes, search projects, and create draft comments for code review workflows.
README
GitLab Code Review MCP Server
A Model Context Protocol (MCP) server that provides GitLab code review functionality for AI assistants. This server enables AI assistants to interact with GitLab merge requests, review code changes, and create draft comments.
Features
- Project Discovery: Search and list GitLab projects
- Merge Request Management: List and filter merge requests
- Code Diff Analysis: Retrieve detailed code changes for merge requests
- Draft Comment Creation: Create both general and line-specific draft comments
Quick Start
Prerequisites
- Node.js (ES2022+ support required)
- pnpm package manager (version 10.11.1+ recommended)
- GitLab Personal Access Token with API access
Installation
-
Clone the repository:
git clone <repository-url> cd code-review-mcp -
Install dependencies:
pnpm install -
Configure environment:
cp .env.example .envEdit
.envwith your GitLab configuration:GITLAB_PAT=your_gitlab_personal_access_token_here GITLAB_API_URL=https://gitlab.com GITLAB_PROJECT_ID=your_project_id_here SERVER_NAME=code-review-mcp SERVER_VERSION=1.0.0 -
Build the project:
pnpm run build -
Run the server:
node build/index.js
MCP Tools
The server exposes four main tools for GitLab integration:
get-projects
Search and list GitLab projects.
Parameters:
search(optional): Search term to filter projectsper_page(optional): Number of results per page (default: 20, max: 100)visibility(optional): Filter by visibility ('private', 'internal', 'public')owned(optional): Limit to owned projects (boolean)
get-merge-requests
List merge requests from a project.
Parameters:
state(optional): Filter by state ('opened', 'closed', 'merged', 'all') - default: 'opened'per_page(optional): Number of results per page (default: 20, max: 100)
get-merge-request-diffs
Get detailed code changes for a specific merge request.
Parameters:
mr_iid(optional): Internal ID of the merge requestsource_branch(optional): Source branch name to search formrTitle(optional): Title or partial title to search for
create-draft-note
Create draft comments on merge requests.
Parameters:
project_id(optional): Project ID (uses default if not provided)mr_iid(required): Internal ID of the merge requestnote(required): Content of the draft noteposition_type(optional): Set to 'text' for line-specific commentsold_path,new_path(optional): File paths for line commentsold_line,new_line(optional): Line numbers for line commentsbase_sha,start_sha,head_sha(optional): SHA values for line comments
Configuration
Environment Variables
All environment variables are validated at startup using Zod schemas:
GITLAB_PAT(required): GitLab Personal Access Token with API accessGITLAB_API_URL(required): GitLab instance URL (e.g., https://gitlab.com)GITLAB_PROJECT_ID(required): Default project ID (numeric)SERVER_NAME(required): MCP server name identifierSERVER_VERSION(required): Server version string
GitLab Personal Access Token
Your GitLab PAT needs the following scopes:
api- Full API accessread_user- Read user informationread_repository- Read repository content
Development
Project Structure
├── src/
│ ├── index.ts # Main MCP server implementation
│ └── env.ts # Environment configuration and validation
├── build/ # Compiled output (generated)
├── docs/
│ └── system-prompt.md # AI assistant usage documentation
├── test_mcp_server.js # Comprehensive test suite
├── test_draft_note.js # Example requests for draft note tool
├── test_projects.js # Example data for projects tool
├── .env.example # Environment variable template
├── package.json # Project configuration
└── tsconfig.json # TypeScript configuration
Building
pnpm run build
This compiles TypeScript from src/ to build/ directory and makes the output executable.
Testing
Run the comprehensive test suite:
node test_mcp_server.js
This test verifies:
- Build process functionality
- Output file generation and permissions
- Environment variable validation
- MCP server initialization
Code Architecture
Entry Point: src/index.ts
- Creates MCP server instance
- Registers four GitLab tools
- Handles stdio transport communication
Environment Management: src/env.ts
- Uses Zod for runtime environment validation
- Exports typed environment configuration
- Fails fast on invalid configuration
Key Components:
makeGitLabRequest<T>()- Generic GitLab API client function- Interface definitions for GitLab entities (MergeRequest, Diff, Project, DraftNote)
- MCP tool handlers with Zod schema validation
Usage with AI Assistants
This MCP server is designed to be used with AI assistants that support the Model Context Protocol. See docs/system-prompt.md for detailed instructions on how AI assistants can use this server for code review workflows.
Example Workflow
- Discover Projects: Use
get-projectsto find target repositories - List Merge Requests: Use
get-merge-requeststo see open merge requests - Analyze Code: Use
get-merge-request-diffsto review code changes - Provide Feedback: Use
create-draft-noteto create constructive comments
MCP Client Configuration
To use this MCP server with AI assistants like Claude Code, you need to add the server configuration to your MCP client settings. Here's how to configure it:
For Claude Code
Add the following configuration to your MCP client settings (typically in a JSON configuration file):
{
"mcpServers": {
"code-review": {
"command": "node",
"args": [
"<ABSOLUTE_PATH_TO_code-review-mcp/build/index.js>"
],
"env": {
"GITLAB_PROJECT_ID": "",
"GITLAB_PAT": "",
"GITLAB_API_URL": "",
"SERVER_NAME": "",
"SERVER_VERSION": ""
}
}
}
}
Configuration Steps
-
Build the project first (if not already done):
pnpm run build -
Replace the placeholder values:
<ABSOLUTE_PATH_TO_code-review-mcp/build/index.js>: Replace with the full absolute path to your built server fileGITLAB_PROJECT_ID: Your GitLab project ID (numeric)GITLAB_PAT: Your GitLab Personal Access TokenGITLAB_API_URL: Your GitLab instance URL (e.g.,https://gitlab.com)SERVER_NAME: A name for your server instance (e.g.,code-review-mcp)SERVER_VERSION: Version identifier (e.g.,1.0.0)
-
Example with actual values:
{ "mcpServers": { "code-review": { "command": "node", "args": [ "/Users/yourname/projects/code-review-mcp/build/index.js" ], "env": { "GITLAB_PROJECT_ID": "12345678", "GITLAB_PAT": "glpat-xxxxxxxxxxxxxxxxxxxx", "GITLAB_API_URL": "https://gitlab.com", "SERVER_NAME": "code-review-mcp", "SERVER_VERSION": "1.0.0" } } } } -
Restart your MCP client after adding the configuration.
Security Notes
- Keep your GitLab Personal Access Token secure and never commit it to version control
- Use environment-specific configuration files that are excluded from your repository
- Ensure your GitLab PAT has only the minimum required permissions (api, read_user, read_repository)
API Integration
The server integrates with GitLab's REST API v4:
- Authentication: Uses
PRIVATE-TOKENheader with GitLab PAT - Base URL Pattern:
${GITLAB_API_URL}/api/v4/... - Error Handling: All API calls include comprehensive error handling
- Rate Limiting: Respects GitLab API rate limits
Security Considerations
- Token Security: Store GitLab PAT securely and use minimal required permissions
- Input Validation: All user inputs are validated through Zod schemas
- Error Messages: Sensitive information is not exposed in error responses
- Environment Variables: Never commit actual credentials to version control
License
ISC
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues and questions:
- Check the existing documentation in
docs/ - Review the test files for usage examples
- Open an issue with detailed information about your problem
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。