### [GitLab项目管理服务器](https://s.ddm.chat/link/688) **Published:** 2026-07-23T02:00:23 **Author:** 颠倒梦 **Excerpt:** GitLab MCP服务器提供项目管理和文件操作功能,支持自动分支创建、批量操作和全面的错误处理。 # GitLab MCP服务器 用于GitLab API的MCP服务器,实现项目管理、文件操作等。 ### 特性 - **自动创建分支**:在创建/更新文件或推送更改时,如果分支不存在,则会自动创建分支 - **全面的错误处理**:清除常见问题的错误消息 - **Git历史保存**:操作维护正确的Git历史记录,无需强制推送 - **批量操作**:支持单文件和多文件操作 ## 工具 1. `create_or_update_file` - 在项目中创建或更新单个文件 - 输入: - `project_id` (string):项目ID或URL编码路径 - `file_path` (string):创建/更新文件的路径 - `content` (string):文件内容 - `commit_message` (string):提交消息 - `branch` (string):创建/更新文件的分支 - `previous_path` (可选字符串):要移动/重命名的文件的路径 - 返回:文件内容和提交详细信息 2. `push_files` - 在一次提交中推送多个文件 - 输入: - `project_id` (string):项目ID或URL编码路径 - `branch` (string):要推送的分支 - `files` (array):要推送的文件,每个文件都有 `file_path` 和 `content` - `commit_message` (string):提交消息 - 返回:更新了分支引用 3. `search_repositories` - 搜索GitLab项目 - 输入: - `search` (string):搜索查询 - `page` (可选编号):分页页码 - `per_page` (可选数字):每页结果(默认值20) - 返回:项目搜索结果 4. `create_repository` - 创建一个新的GitLab项目 - 输入: - `name` (string):项目名称 - `description` (可选字符串):项目描述 - `visibility` (可选字符串):“private”、“internal”或“public” - `initialize_with_readme` (可选布尔值):使用README进行初始化 - 返回:已创建项目详细信息 5. `get_file_contents` - 获取文件或目录的内容 - 输入: - `project_id` (string):项目ID或URL编码路径 - `file_path` (string):文件/目录的路径 - `ref` (可选字符串):从Branch/tag/commit获取内容 - 返回:文件/目录内容 6. `create_issue` - 创建新问题 - 输入: - `project_id` (string):项目ID或URL编码路径 - `title` (string):发行标题 - `description` (可选字符串):问题描述 - `assignee_ids` (可选编号\[\]):要分配的用户ID - `labels` (可选字符串\[\]):要添加的标签 - `milestone_id` (可选编号):里程碑ID - 退货:已创建问题详细信息 7. `create_merge_request` - 创建新的合并请求 - 输入: - `project_id` (string):项目ID或URL编码路径 - `title` (字符串):MR标题 - `description` (可选字符串):MR描述 - `source_branch` (string):包含更改的分支 - `target_branch` (string):要合并的分支 - `draft` (可选布尔值):创建为草稿MR - `allow_collaboration` (可选布尔值):允许来自上游成员的提交 - 返回:已创建合并请求详细信息 8. `fork_repository` - 分叉项目 - 输入: - `project_id` (string):项目ID或URL编码路径 - `namespace` (可选字符串):要分叉到的命名空间 - 返回:分叉项目详细信息 9. `create_branch` - 创建新分支 - 输入: - `project_id` (string):项目ID或URL编码路径 - `branch` (string):新分支的名称 - `ref` (可选字符串):源分支/新分支的提交 - 返回:已创建分支引用 ## 设置 ### 个人访问令牌 [创建GitLab个人访问令牌](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) 具有适当的权限: - 转到用户设置>访问GitLab中的令牌 - 选择所需的范围: - `api` 用于API的完全访问 - `read_api` 用于只读访问 - `read_repository` 和 `write_repository` 用于存储库操作 - 创建令牌并安全保存 ### 使用Claude Desktop 将以下内容添加到您的 `claude_desktop_config.json`: #### 码头工人 ```json { "mcpServers": { "gitlab": { "command": "docker", "args": [ "run", "--rm", "-i", "-e", "GITLAB_PERSONAL_ACCESS_TOKEN", "-e", "GITLAB_API_URL", "mcp/gitlab" ], "env": { "GITLAB_PERSONAL_ACCESS_TOKEN": "", "GITLAB_API_URL": "https://gitlab.com/api/v4" // Optional, for self-hosted instances } } } } ``` #### NPX ```json { "mcpServers": { "gitlab": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-gitlab" ], "env": { "GITLAB_PERSONAL_ACCESS_TOKEN": "", "GITLAB_API_URL": "https://gitlab.com/api/v4" // Optional, for self-hosted instances } } } } ``` ### 使用VS代码 为了快速安装,请使用下面的一键安装按钮之一。.. [](https://insiders.vscode.dev/redirect/mcp/install?name=gitlab&inputs=%5B%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_token%22%2C%22description%22%3A%22GitLab%20Personal%20Access%20Token%22%2C%22password%22%3Atrue%7D%2C%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_url%22%2C%22description%22%3A%22GitLab%20API%20URL%20\(optional%2C%20default%3A%20https%3A%2F%2Fgitlab.com%2Fapi%2Fv4\)%22%2C%22default%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%7D%5D&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40modelcontextprotocol%2Fserver-gitlab%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab_token%7D%22%2C%22GITLAB_API_URL%22%3A%22%24%7Binput%3Agitlab_url%7D%22%7D%7D)[](https://insiders.vscode.dev/redirect/mcp/install?name=gitlab&inputs=%5B%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_token%22%2C%22description%22%3A%22GitLab%20Personal%20Access%20Token%22%2C%22password%22%3Atrue%7D%2C%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_url%22%2C%22description%22%3A%22GitLab%20API%20URL%20\(optional%2C%20default%3A%20https%3A%2F%2Fgitlab.com%2Fapi%2Fv4\)%22%2C%22default%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%7D%5D&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40modelcontextprotocol%2Fserver-gitlab%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab_token%7D%22%2C%22GITLAB_API_URL%22%3A%22%24%7Binput%3Agitlab_url%7D%22%7D%7D&quality=insiders) [](https://insiders.vscode.dev/redirect/mcp/install?name=gitlab&inputs=%5B%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_token%22%2C%22description%22%3A%22GitLab%20Personal%20Access%20Token%22%2C%22password%22%3Atrue%7D%2C%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_url%22%2C%22description%22%3A%22GitLab%20API%20URL%20\(optional%2C%20default%3A%20https%3A%2F%2Fgitlab.com%2Fapi%2Fv4\)%22%2C%22default%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%7D%5D&config=%7B%22command%22%3A%22docker%22%2C%22args%22%3A%5B%22run%22%2C%22--rm%22%2C%22-i%22%2C%22mcp%2Fgitlab%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab_token%7D%22%2C%22GITLAB_API_URL%22%3A%22%24%7Binput%3Agitlab_url%7D%22%7D%7D)[](https://insiders.vscode.dev/redirect/mcp/install?name=gitlab&inputs=%5B%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_token%22%2C%22description%22%3A%22GitLab%20Personal%20Access%20Token%22%2C%22password%22%3Atrue%7D%2C%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22gitlab_url%22%2C%22description%22%3A%22GitLab%20API%20URL%20\(optional%2C%20default%3A%20https%3A%2F%2Fgitlab.com%2Fapi%2Fv4\)%22%2C%22default%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%7D%5D&config=%7B%22command%22%3A%22docker%22%2C%22args%22%3A%5B%22run%22%2C%22--rm%22%2C%22-i%22%2C%22mcp%2Fgitlab%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab_token%7D%22%2C%22GITLAB_API_URL%22%3A%22%24%7Binput%3Agitlab_url%7D%22%7D%7D&quality=insiders) 对于手动安装,请将以下JSON块添加到VS Code中的用户设置(JSON)文件中。您可以按 `Ctrl + Shift + P` 和打字 `Preferences: Open User Settings (JSON)`. 您可以选择将其添加到名为的文件中 `.vscode/mcp.json` 在您的工作空间中。这将允许您与他人共享配置。 > 请注意 `mcp` 中不需要密钥 `.vscode/mcp.json` 文件。 #### 码头工人 ```json { "mcp": { "inputs": [ { "type": "promptString", "id": "gitlab_token", "description": "GitLab Personal Access Token", "password": true }, { "type": "promptString", "id": "gitlab_url", "description": "GitLab API URL (optional)", "default": "https://gitlab.com/api/v4" } ], "servers": { "gitlab": { "command": "docker", "args": [ "run", "--rm", "-i", "mcp/gitlab" ], "env": { "GITLAB_PERSONAL_ACCESS_TOKEN": "${input:gitlab_token}", "GITLAB_API_URL": "${input:gitlab_url}" } } } } } ``` #### NPX ```json { "mcp": { "inputs": [ { "type": "promptString", "id": "gitlab_token", "description": "GitLab Personal Access Token", "password": true }, { "type": "promptString", "id": "gitlab_url", "description": "GitLab API URL (optional)", "default": "https://gitlab.com/api/v4" } ], "servers": { "gitlab": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-gitlab" ], "env": { "GITLAB_PERSONAL_ACCESS_TOKEN": "${input:gitlab_token}", "GITLAB_API_URL": "${input:gitlab_url}" } } } } } ``` ## 构建 Docker构建: ```bash docker build -t vonwig/gitlab:mcp -f src/gitlab/Dockerfile . ``` ## 环境变量 - `GITLAB_PERSONAL_ACCESS_TOKEN`:您的GitLab个人访问令牌(必填) - `GITLAB_API_URL`:GitLab API的基本URL(可选,默认为 `https://gitlab.com/api/v4`) ## 许可证 此MCP服务器根据MIT许可证获得许可。这意味着您可以根据MIT许可证的条款和条件自由使用、修改和分发软件。有关更多详细信息,请参阅项目存储库中的LICENSE文件。 ---