使用说明
GitLab MCP
模型上下文协议 GitLab的MCP服务器。将GitLab项目、提交、文件、合并请求、问题和wiki页面作为MCP工具公开,供Cursor、Claude Desktop或其他MCP客户端使用。
特性
- list_项目 --列出所有GitLab项目(基于会员,最多100个)
- 创建项目 --创建一个新的GitLab项目
- update_项目 --更新现有的GitLab项目
- list_commits --列出项目的存储库提交
- get_贡献_活动 --获取按天汇总的用户贡献热图活动
- 获取文件 --在给定的ref(branch/tag/commit)处从项目中获取文件内容
- list_merge_requests --列出项目的合并请求
- create_merge_request --创建/提交合并请求
- get_merge_request --按项目和MR IID获取单个合并请求
- update_merge_request --更新合并请求
- 合并_目标_请求 --接受/合并合并请求
- add_merge_request_note --在合并请求中添加注释/备注
- list_merge_request_notes --列出合并请求的注释/评论
- list_issues --列出项目的问题(可选:状态、标签、iid)
- 创建_发行 --在项目中创建问题
- 获取问题 --按项目获取单个问题并发布IID
- update_issue --更新问题(标题、描述、状态事件、标签、受让人等)
- 删除_问题 --从项目中删除问题
- add_issue_note --为问题添加评论/注释
- list_issue_notes --列出问题的注释/评论
- list_wiki_pages --列出项目的所有wiki页面
- get_wiki_page --通过slug获取单个wiki页面
- create_wiki_page --创建新的wiki页面
- update_wiki_page --更新现有wiki页面
- delete_wiki_page --删除wiki页面
需求
- Node.js 18+
- GitLab实例(自托管或GitLab.com)
- GitLab 个人访问令牌 或 项目/组访问令牌 随着
read_api对于读取操作,read_user或api用于捐款活动,以及api用于创建/更新项目(目标命名空间或项目上的Maintainer+)、创建/更新/合并合并请求、创建/升级/删除问题、添加注释和管理wiki页面
安装
来自npm:
npm install -g @butterfly-liu/gitlab-mcp
# or as project dependency
npm install @butterfly-liu/gitlab-mcp
或者克隆并在本地安装:
git clone https://github.com/9527crazy/gitlab-mcp.git && cd gitlab-mcp && npm install
配置
必修的: 集 GITLAB_TOKEN 在您的环境或MCP客户端配置中。如果服务器丢失,它将退出并显示错误。
| 变量 | 描述 | 默认值 |
|---|---|---|
GITLAB_URL |
GitLab基本URL(无尾随斜线) | https://gitlab.com |
GITLAB_TOKEN |
API令牌(例如。 glpat-xxxx) |
必需的 |
例子:
export GITLAB_URL="https://gitlab.com"
export GITLAB_TOKEN="glpat-your-token-here"
安全: 不要提交真正的代币。使用环境变量或机密管理器。
用法
直接运行
node server.js
# or if installed globally
gitlab-mcp
或者在一个项目中 npm start 或 npx gitlab-mcp.
服务器使用stdio传输,旨在由MCP客户端启动(例如Cursor MCP设置)。
光标配置
添加到光标MCP设置(例如。 ~/.cursor/mcp.json 或项目MCP配置)。
从npm(全局或本地)安装时 node_modules):
{
"mcpServers": {
"gitlab": {
"command": "npx",
"args": ["@butterfly-liu/gitlab-mcp"],
"env": {
"GITLAB_URL": "https://gitlab.com",
"GITLAB_TOKEN": "glpat-your-token"
}
}
}
}
或者通过明确的路径 server.js:
{
"mcpServers": {
"gitlab": {
"command": "node",
"args": ["/path/to/gitlab-mcp/server.js"],
"env": {
"GITLAB_URL": "https://gitlab.com",
"GITLAB_TOKEN": "glpat-your-token"
}
}
}
}
工具参考
| 工具 | 参数 | 说明 |
|---|---|---|
list_projects |
-- | 列出项目(成员资格,每页=100) |
create_project |
name, 可选: path, namespace_id, description, visibility, initialize_with_readme, default_branch, topics, import_url |
创建一个新项目。不设置 import_url 和 initialize_with_readme 一起 |
update_project |
project_id (编号或路径), 可选: name, path, description, visibility, default_branch, topics, archived |
更新项目(至少一个可选字段)。需要维护者或所有者 |
list_commits |
project_id (数量) |
列出项目的承诺 |
get_contribution_activity |
可选: user_id, after, before, action, target_type, include_events, max_pages |
获取按天汇总的贡献热图活动。默认为经过身份验证的用户和过去12个月 |
get_file |
project_id, file_path, ref |
在ref处获取文件内容 |
list_merge_requests |
project_id (数字), 可选: state, source_branch, target_branch, author_id, assignee_id, reviewer_id, labels, search, iids |
列出项目的MR |
create_merge_request |
project_id, source_branch, target_branch, title, 可选: description, target_project_id, assignee_id, assignee_ids, reviewer_ids, labels, milestone_id, remove_source_branch, squash, allow_collaboration, draft |
创建/提交合并请求 |
get_merge_request |
project_id, merge_request_iid |
获取一个MR |
update_merge_request |
project_id, merge_request_iid, 可选: target_branch, title, description, state_event, assignee_id, assignee_ids, reviewer_ids, labels, add_labels, remove_labels, milestone_id, remove_source_branch, squash, discussion_locked, allow_collaboration |
更新MR |
merge_merge_request |
project_id, merge_request_iid, 可选: merge_commit_message, squash_commit_message, squash, should_remove_source_branch, auto_merge, merge_when_pipeline_succeeds, sha |
接受/合并MR。 merge_when_pipeline_succeeds GitLab 17.11已弃用;更喜欢 auto_merge 在较新的GitLab版本上 |
add_merge_request_note |
project_id, merge_request_iid, body |
在MR中添加评论/注释 |
list_merge_request_notes |
project_id, merge_request_iid |
列出MR的注释/评论 |
list_issues |
project_id (数字), 可选: state, labels, iids |
列出项目问题 |
create_issue |
project_id, title, 可选: description, labels, assignee_ids, due_date, confidential, issue_type |
创建问题 |
get_issue |
project_id, issue_iid |
获取一个问题 |
update_issue |
project_id, issue_iid, 可选: title, description, state_event, labels, add_labels, remove_labels, assignee_ids, due_date, milestone_id, confidential, discussion_locked, issue_type |
更新问题 |
delete_issue |
project_id, issue_iid |
删除问题 |
add_issue_note |
project_id, issue_iid, body |
为问题添加评论/注释 |
list_issue_notes |
project_id, issue_iid |
列出问题的注释/评论 |
list_wiki_pages |
project_id (数字), 可选: with_content |
列出项目的所有wiki页面 |
get_wiki_page |
project_id, slug, 可选: render_html, version |
通过slug获取单个wiki页面 |
create_wiki_page |
project_id, title, content, 可选: format |
创建新的wiki页面 |
update_wiki_page |
project_id, slug, 可选: title, content, format |
更新现有的wiki页面(至少是标题或内容) |
delete_wiki_page |
project_id, slug |
删除wiki页面 |
项目ID是数字。Wiki页面slug是URL友好的标识符(例如,来自标题;使用create/list/get返回的slug)。问题IID和合并请求IID是项目内部编号(例如问题 #3 -> issue_iid: 3先生 !7 -> merge_request_iid: 7).
发布到npm(维护者)
注: 未限定范围的名称 gitlab-mcp 已经在npm上使用了。以限定范围的名称发布,例如。 @butterfly-liu/gitlab-mcp.
首次发布前:
- 设置包名称 在
package.json:包名称为@butterfly-liu/gitlab-mcp(如果不同,请使用您的npm用户名作为作用域)。 - 填写仓库URL 在
package.json:替换your-username在repository,bugs,以及homepage使用您的GitHub/GitLab用户名或组织。 - 登录:
npm login(在以下位置创建帐户 npmjs.com 如果需要)。 - 预览tarball:
npm pack --dry-run--只有server.js和README.md包括(参见files在package.json中)。 - 发布:
npm publish --access public(每个人都可以安装作用域包所必需的)。
代码更改后:bump version (例如。 npm version patch)那么 npm publish --access public.
许可证
国际学生委员会
