用于 GitLab API 的 MCP 服务器,支持项目管理、文件操作等功能。
create_or_update_file
project_id (字符串):项目ID或URL编码路径。file_path (字符串):创建或更新文件的路径。content (字符串):文件内容。commit_message (字符串):提交信息。branch (字符串):要创建或更新文件的分支。previous_path (可选字符串):要移动或重命名的文件路径。push_files
project_id (字符串):项目ID或URL编码路径。branch (字符串):要推送的分支。files (数组):要推送的文件,每个文件包含 file_path 和 content。commit_message (字符串):提交信息。search_repositories
search (字符串):搜索查询。page (可选数字):分页的页面编号。per_page (可选数字):每页的结果数(默认20)。create_repository
name (字符串):项目名称。description (可选字符串):项目描述。visibility (可选字符串):'private'、'internal' 或 'public'。initialize_with_readme (可选布尔值):初始化时是否包含 README。get_file_contents
project_id (字符串):项目ID或URL编码路径。file_path (字符串):文件/目录路径。ref (可选字符串):获取内容的分支/标签/提交。create_issue
project_id (字符串):项目ID或URL编码路径。title (字符串):问题标题。description (可选字符串):问题描述。assignee_ids (可选数字数组):分配给用户的ID。labels (可选字符串数组):添加的标签。milestone_id (可选数字):里程碑ID。create_merge_request
project_id (字符串):项目ID或URL编码路径。title (字符串):MR 标题。description (可选字符串):MR 描述。source_branch (字符串):包含更改的分支。target_branch (字符串):要合并到的分支。draft (可选布尔值):作为草稿 MR 创建。allow_collaboration (可选布尔值):允许上游成员提交。fork_repository
project_id (字符串):项目ID或URL编码路径。namespace (可选字符串):要分叉到的命名空间。create_branch
project_id (字符串):项目ID或URL编码路径。branch (字符串):新分支的名称。ref (可选字符串):新分支的源分支/提交。创建一个 GitLab 个人访问令牌,并赋予适当的权限:
api:完整的 API 访问权限。read_api:只读访问权限。read_repository 和 write_repository:仓库操作权限。在你的 claude_desktop_config.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": "<YOUR_TOKEN>",
"GITLAB_API_URL": "https://gitlab.com/api/v4" // 可选,用于自托管实例
}
}
}
}
{
"mcpServers": {
"gitlab": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-gitlab"
],
"env": {
"GITLAB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>",
"GITLAB_API_URL": "https://gitlab.com/api/v4" // 可选,用于自托管实例
}
}
}
}
快速安装,请使用以下一键安装按钮之一...
手动安装,请在 VS Code 的用户设置(JSON)文件中添加以下 JSON 块。你可以通过按 Ctrl + Shift + P 并键入 Preferences: Open User Settings (JSON) 来完成此操作。
可选地,你可以将其添加到名为 .vscode/mcp.json 的工作区文件中。这将允许你与他人共享配置。
注意,在
.vscode/mcp.json文件中不需要mcp键。
{
"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}"
}
}
}
}
}
{
"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 构建:
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 文件。