npm install @yoda.digital/gitlab-mcp-server
# 克隆仓库
git clone https://github.com/yoda-digital/mcp-gitlab-server.git
cd mcp-gitlab-server
# 安装依赖
npm install
# 构建项目
npm run build
服务器需要以下环境变量:
| 变量 | 必需 | 默认值 | 描述 |
|---|---|---|---|
GITLAB_PERSONAL_ACCESS_TOKEN | 是 | - | 您的GitLab个人访问令牌 |
GITLAB_API_URL | 否 | https://gitlab.com/api/v4 | GitLab API URL |
PORT | 否 | 3000 | SSE传输使用的端口 |
USE_SSE | 否 | false | 设置为'true'以使用SSE传输 |
GITLAB_READ_ONLY_MODE | 否 | false | 设置为'true'以启用只读模式(见下文) |
当GITLAB_READ_ONLY_MODE设置为true时,服务器将仅暴露读取操作。这对于不应具有写入权限的客户端应用程序非常有用。在只读模式下,将提供以下工具:
search_repositoriesget_file_contentslist_group_projectsget_project_eventslist_commitslist_issueslist_merge_requestslist_project_wiki_pagesget_project_wiki_pagelist_group_wiki_pagesget_group_wiki_pagelist_project_memberslist_group_members任何尝试使用写操作(创建、更新、删除)的行为将在只读模式下导致错误。
将GitLab MCP服务器添加到您的MCP设置文件中:
{
"mcpServers": {
"gitlab": {
"command": "npx",
"args": ["-y", "@yoda.digital/gitlab-mcp-server"],
"env": {
"GITLAB_PERSONAL_ACCESS_TOKEN": "your_token_here",
"GITLAB_API_URL": "https://gitlab.com/api/v4"
},
"alwaysAllow": [],
"disabled": false
}
}
}
对于只读模式,添加GITLAB_READ_ONLY_MODE环境变量:
{
"mcpServers": {
"gitlab-readonly": {
"command": "npx",
"args": ["-y", "@yoda.digital/gitlab-mcp-server"],
"env": {
"GITLAB_PERSONAL_ACCESS_TOKEN": "your_token_here",
"GITLAB_API_URL": "https://gitlab.com/api/v4",
"GITLAB_READ_ONLY_MODE": "true"
},
"alwaysAllow": [],
"disabled": false
}
}
}
# 设置您的GitLab个人访问令牌
export GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here
# 运行服务器
npm start
# 设置您的GitLab个人访问令牌并启用SSE
export GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here
export GITLAB_READ_ONLY_MODE=false
export USE_SSE=true
export PORT=3000 # 可选,默认为3000
# 运行服务器
npm start
# 直接使用npx运行
GITLAB_PERSONAL_ACCESS_TOKEN=your_token_here npx @yoda.digital/gitlab-mcp-server
{
"search": "项目名称",
"page": 1,
"per_page": 20
}
</details>
<details>
<summary><b>create_repository</b>: 在GitLab中创建一个新的项目</summary>
{
"name": "新项目",
"description": "一个新项目",
"visibility": "private",
"initialize_with_readme": true
}
</details>
<details>
<summary><b>fork_repository</b>: 分叉一个GitLab项目</summary>
{
"project_id": "用户名/项目",
"namespace": "目标命名空间"
}
</details>
<details>
<summary><b>list_group_projects</b>: 列出特定GitLab组内的所有项目</summary>
{
"group_id": "组名",
"archived": false,
"visibility": "public",
"include_subgroups": true,
"page": 1,
"per_page": 20
}
</details>
{
"project_id": "用户名/项目",
"file_path": "路径/to/文件.txt",
"ref": "main"
}
</details>
<details>
<summary><b>create_or_update_file</b>: 在GitLab项目中创建或更新单个文件</summary>
{
"project_id": "用户名/项目",
"file_path": "路径/to/文件.txt",
"content": "文件内容",
"commit_message": "添加/更新文件",
"branch": "main",
"previous_path": "旧路径/to/文件.txt"
}
</details>
<details>
<summary><b>push_files</b>: 将多个文件推送到GitLab项目的单个提交中</summary>
{
"project_id": "用户名/项目",
"files": [
{
"path": "文件1.txt",
"content": "文件1的内容"
},
{
"path": "文件2.txt",
"content": "文件2的内容"
}
],
"commit_message": "添加多个文件",
"branch": "main"
}
</details>
{
"project_id": "用户名/项目",
"branch": "新分支",
"ref": "main"
}
</details>
{
"project_id": "用户名/项目",
"title": "问题标题",
"description": "问题描述",
"assignee_ids": [1, 2],
"milestone_id": 1,
"labels": ["bug", "critical"]
}
</details>
<details>
<summary><b>list_issues</b>: 获取GitLab项目的问题列表,并进行过滤</summary>
{
"project_id": "用户名/项目",
"state": "opened",
"labels": "bug,critical",
"milestone": "v1.0",
"author_id": 1,
"assignee_id": 2,
"search": "关键词",
"created_after": "2023-01-01T00:00:00Z",
"created_before": "2023-12-31T23:59:59Z",
"updated_after": "2023-06-01T00:00:00Z",
"updated_before": "2023-06-30T23:59:59Z",
"page": 1,
"per_page": 20
}
</details>
<details>
<summary><b>list_issue_notes</b>: 获取GitLab问题的所有评论和系统注释</summary>
{
"project_id": "用户名/项目",
"issue_iid": 42,
"sort": "desc",
"order_by": "created_at",
"page": 1,
"per_page": 20
}
响应格式:
{
"count": 15,
"notes": [
{
"id": 123456,
"body": "这是对问题的评论",
"author": {
"id": 1,
"username": "用户名",
"name": "用户姓名"
},
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"system": false,
"type": "comment"
},
{
"id": 123457,
"body": "添加标签~bug",
"author": {
"id": 1,
"username": "用户名",
"name": "用户姓名"
},
"created_at": "2023-01-02T00:00:00Z",
"updated_at": "2023-01-02T00:00:00Z",
"system": true,
"type": "system"
}
// ... 其他注释
]
}
</details>
<details>
<summary><b>list_issue_discussions</b>: 获取GitLab问题的所有讨论(线程式评论)</summary>
{
"project_id": "用户名/项目",
"issue_iid": 42,
"page": 1,
"per_page": 20
}
响应格式:
{
"count": 5,
"discussions": [
{
"id": "discussion-123",
"individual_note": true,
"notes": [
{
"id": 123456,
"body": "这是对问题的评论",
"author": {
"id": 1,
"username": "用户名",
"name": "用户姓名"
},
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"system": false,
"type": "comment"
}
]
},
{
"id": "discussion-124",
"individual_note": false,
"notes": [
{
"id": 123457,
"body": "这是线程的开头",
"author": {
"id": 1,
"username": "用户名",
"name": "用户姓名"
},
"created_at": "2023-01-02T00:00:00Z",
"updated_at": "2023-01-02T00:00:00Z",
"system": false,
"type": "comment"
},
{
"id": 123458,
"body": "这是线程中的回复",
"author": {
"id": 2,
"username": "用户名2",
"name": "用户姓名2"
},
"created_at": "2023-01-03T00:00:00Z",
"updated_at": "2023-01-03T00:00:00Z",
"system": false,
"type": "comment"
}
]
}
// ... 其他讨论
]
}
</details>
{
"project_id": "用户名/项目",
"title": "合并请求标题",
"description": "合并请求描述",
"source_branch": "功能分支",
"target_branch": "main",
"allow_collaboration": true,
"draft": false
}
</details>
<details>
<summary><b>list_merge_requests</b>: 获取GitLab项目中的合并请求列表,并进行过滤</summary>
{
"project_id": "用户名/项目",
"state": "opened",
"order_by": "created_at",
"sort": "desc",
"milestone": "v1.0",
"labels": "feature,enhancement",
"created_after": "2023-01-01T00:00:00Z",
"created_before": "2023-12-31T23:59:59Z",
"updated_after": "2023-06-01T00:00:00Z",
"updated_before": "2023-06-30T23:59:59Z",
"author_id": 1,
"assignee_id": 2,
"search": "关键词",
"source_branch": "功能分支",
"target_branch": "main",
"page": 1,
"per_page": 20
}
</details>
{
"project_id": "用户名/项目",
"action": "pushed",
"target_type": "issue",
"before": "2023-12-31T23:59:59Z",
"after": "2023-01-01T00:00:00Z",
"sort": "desc",
"page": 1,
"per_page": 20
}
</details>
<details>
<summary><b>list_commits</b>: 获取GitLab项目的提交历史</summary>
{
"project_id": "用户名/项目",
"sha": "分支或提交SHA",
"path": "路径/to/文件",
"since": "2023-01-01T00:00:00Z",
"until": "2023-12-31T23:59:59Z",
"all": true,
"with_stats": true,
"first_parent": true,
"page": 1,
"per_page": 20
}
</details>
{
"project_id": "用户名/项目",
"query": "搜索词",
"page": 1,
"per_page": 20
}
响应格式:
{
"count": 3,
"items": [
{
"id": 123,
"username": "用户名",
"name": "用户姓名",
"state": "active",
"avatar_url": "https://gitlab.com/avatar.png",
"web_url": "https://gitlab.com/用户名",
"access_level": 50,
"access_level_description": "