GitLab MCP Server
Enables AI assistants to interact with GitLab repositories, manage branches, create merge requests, and perform file operations through natural language.
README
GitLab MCP Server
A Model Context Protocol (MCP) server that provides GitLab API integration for AI assistants like Claude. This server enables AI agents to interact with GitLab repositories, manage branches, create merge requests, and perform file operations.
Features
- Repository Management: List and get details of GitLab projects
- Branch Operations: Create, list, and delete branches
- Merge Requests: Create, list, and merge pull requests
- File Operations: Read, create, update, and delete repository files
- Secure Authentication: Token-based authentication with GitLab API
Installation
- Clone the repository:
git clone <repository-url>
cd gitlab-mcp-server
- Install dependencies:
npm install
- Set up environment variables:
cp .env.example .env
# Edit .env with your GitLab credentials
Configuration
Create a .env file with the following variables:
GITLAB_TOKEN=your_gitlab_personal_access_token
GITLAB_URL=https://gitlab.com/api/v4
DEFAULT_PROJECT_ID=your_default_project_id
Environment Variables
GITLAB_TOKEN: Your GitLab personal access token (required)GITLAB_URL: GitLab API base URL (defaults to https://gitlab.com/api/v4)DEFAULT_PROJECT_ID: Default project ID for operations (optional)
Claude Code Configuration
To use this MCP server with Claude Code, you need to configure it in your MCP settings. Create or update the MCP configuration file:
Option 1: Project-specific configuration
Create an mcp.json file in your project directory:
{
"mcpServers": {
"gitlab": {
"command": "node",
"args": ["/path/to/gitlab-mcp-server/dist/index.js"],
"env": {
"GITLAB_TOKEN": "your_gitlab_personal_access_token",
"GITLAB_URL": "https://gitlab.com/api/v4",
"DEFAULT_PROJECT_ID": "your_project_id"
}
}
}
}
Option 2: Global configuration
Add to your global Claude Code configuration file (usually in ~/.config/claude-code/mcp.json or similar):
{
"mcpServers": {
"gitlab": {
"command": "node",
"args": ["/path/to/gitlab-mcp-server/dist/index.js"],
"env": {
"GITLAB_TOKEN": "your_gitlab_personal_access_token",
"GITLAB_URL": "https://gitlab.com/api/v4"
}
}
}
}
Note: Replace /path/to/gitlab-mcp-server with the actual path where you cloned this repository.
Using environment variables instead
For better security, you can reference environment variables in your mcp.json:
{
"mcpServers": {
"gitlab": {
"command": "node",
"args": ["/path/to/gitlab-mcp-server/dist/index.js"],
"env": {
"GITLAB_TOKEN": "${GITLAB_TOKEN}",
"GITLAB_URL": "${GITLAB_URL}",
"DEFAULT_PROJECT_ID": "${DEFAULT_PROJECT_ID}"
}
}
}
}
Then set these environment variables in your shell profile (~/.bashrc, ~/.zshrc, etc.).
Usage
Development Mode
npm run dev
Production Mode
npm run build
npm start
Watch Mode (Auto-restart on changes)
npm run watch
Available Tools
Repository Tools
list_projects: List accessible GitLab projectsget_project: Get detailed information about a specific project
Branch Tools
list_branches: List all branches in a repositorycreate_branch: Create a new branch from an existing onedelete_branch: Delete a branch from the repository
Merge Request Tools
create_merge_request: Create a new merge requestlist_merge_requests: List merge requests with filtering optionsmerge_merge_request: Merge an approved merge request
File Tools
get_file: Read file content from a repositorycreate_file: Create a new file in the repositoryupdate_file: Update existing file contentdelete_file: Delete a file from the repository
Usage with Claude Code
This MCP server is designed to work seamlessly with Claude Code and other MCP-compatible AI assistants. Here are some example use cases:
Example 1: Creating a Feature Branch and Merge Request
You: "Create a new feature branch called 'add-user-auth' from main, then create a merge request for it"
Claude (using this MCP server):
1. Uses create_branch tool to create 'add-user-auth' branch from 'main'
2. Uses create_merge_request tool to create a merge request
3. Provides you with the merge request URL and details
Example 2: File Operations
You: "Add a new configuration file config/database.yml to the repository"
Claude (using this MCP server):
1. Uses create_file tool to add the new file
2. Commits the change with an appropriate message
3. Confirms the file was created successfully
Example 3: Code Review Workflow
You: "List all open merge requests and show me the files changed in MR #42"
Claude (using this MCP server):
1. Uses list_merge_requests tool to get open MRs
2. Uses get_file tool to show changed files in the specific MR
3. Provides a summary of the changes for review
Architecture
The server follows a modular architecture:
src/index.ts: Main server entry point and MCP setupsrc/gitlab-client.ts: GitLab API client wrappersrc/tools/: Individual tool implementationsrepository.ts: Project management toolsbranches.ts: Branch operation toolsmerge-requests.ts: Merge request toolsfiles.ts: File operation tools
Development
Project Structure
├── src/
│ ├── index.ts # Main server entry point
│ ├── gitlab-client.ts # GitLab API client
│ └── tools/ # MCP tool implementations
│ ├── repository.ts
│ ├── branches.ts
│ ├── merge-requests.ts
│ └── files.ts
├── dist/ # Compiled JavaScript output
├── package.json
├── tsconfig.json
└── README.md
Building
npm run build
Testing
The server can be tested by connecting it to any MCP-compatible client or by using the MCP debugging tools.
Authentication
This server uses GitLab Personal Access Tokens for authentication. To create a token:
- Go to your GitLab profile settings
- Navigate to "Access Tokens"
- Create a new token with appropriate scopes:
api: Full access to the APIread_user: Read user informationread_repository: Read repository contentwrite_repository: Write to repositories
Security Notes
- Store your GitLab token securely in environment variables
- Never commit tokens to version control
- Use minimal required permissions for your token
- Regularly rotate your access tokens
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a merge request
License
MIT License - see LICENSE file for details.
Support
For issues and feature requests, please create an issue in the GitLab repository.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。