使用说明
GitLab MCP服务器
一 MCP服务器 它为AI助手提供Git工作流自动化和GitLab集成。 https://www.npmjs.com/package/@evalin8/mcp gitlab服务器
特性
- Git操作:通过git CLI创建分支、提交更改和推送
- GitLab集成:通过GitLab REST API创建问题
- 自动化工作流程:在人工智能的帮助下简化开发工作流程
- 灵活的配置:支持GitLab.com和自托管实例
运输:stdio
运行时:Node.js 18+
安装
使用NPX(推荐)
npx @evalin8/mcp-gitlab-server
全球安装
npm install -g @evalin8/mcp-gitlab-server
# or: pnpm add -g @evalin8/mcp-gitlab-server
本地安装
npm install @evalin8/mcp-gitlab-server
npx @evalin8/mcp-gitlab-server
设置
GitLab个人访问令牌
- 转到GitLab→ 设置 → 访问令牌
- 使用以下作用域创建新令牌:
api-API完全访问read_user-读取用户信息read_repository-读取存储库内容
- 复制令牌(以开头
glpat_)
环境配置
创建一个 .env 在项目根目录中创建文件或设置环境变量:
GITLAB_HOST=https://gitlab.com/api/v4
GITLAB_TOKEN=glpat_xxxxxxxxxxxxxxxxx
备注:
GITLAB_HOST应包括以结尾的完整API路径/api/v4对于自托管的GitLab,请使用https://your-gitlab.company.com/api/v4.
MCP客户端集成
将以下配置添加到MCP客户端:
克劳德桌面
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
光标/VCode/其他MCP客户端
添加到MCP设置配置中
{
"mcpServers": {
"gitlab": {
"command": "npx",
"args": ["-y", "@evalin8/mcp-gitlab-server"],
"env": {
"GITLAB_HOST": "https://gitlab.com/api/v4",
"GITLAB_TOKEN": "glpat_your_token_here"
}
}
}
}
备注:保存配置后重新启动MCP客户端。
可用工具
Git操作
git_create_branch
创建并签出新分行
repoPath:string(可选;默认为当前目录)branchName:string(必填)fromRef:string(可选;例如“origin/main”)setUpstream:boolean(可选;默认值:true)
git_commit_push
提交所有更改并推送到分支
repoPath:string(必填)message:string(必填)branch:string(必填)
GitLab运营
gitlab_create_issue
在GitLab项目中创建新问题
project:string(必填;建议使用数字ID)title:string(必填)description:string(可选)labels:string[](可选)assigneeIds:number[](可选)milestoneId:数字(可选)confidential:boolean(可选)
获取项目ID
要查找您的GitLab项目ID:
- 转到您的GitLab项目页面
- 数字ID显示在项目名称下
- 使用该数字ID(例如。,
12345)不是项目路径
示例用法
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { McpClient } from "@modelcontextprotocol/sdk/client/mcp.js";
async function example() {
const transport = new StdioClientTransport({
command: "npx",
args: ["-y", "@evalin8/mcp-gitlab-server"],
});
const client = new McpClient(transport);
await client.connect();
// Create a feature branch
await client.callTool("git_create_branch", {
repoPath: "/path/to/repo",
branchName: "feat/ai-integration",
fromRef: "origin/main",
});
// Make changes, then commit and push
await client.callTool("git_commit_push", {
repoPath: "/path/to/repo",
message: "feat: add AI integration",
branch: "feat/ai-integration",
});
// Create a GitLab issue
await client.callTool("gitlab_create_issue", {
project: "12345",
title: "Review AI integration feature",
description: "Please review the new AI integration implementation",
});
await client.close();
}
故障排除
GitLab API问题
- 404错误:确保
GITLAB_HOST包括完整的API路径(例如。,https://gitlab.com/api/v4)并使用数字项目ID - 401错误:验证您的令牌是否具有
api范围和设置正确 - 403错误:检查您是否有足够的项目权限
Git操作
- 推吊:设置
setUpstream: false或配置Git凭据/SSH - 需要认证:此服务器设置
GIT_TERMINAL_PROMPT=0避免交互式提示
一般问题
- 服务器未响应:检查服务器进程是否正在运行
- 环境变量:确保
.env文件位于正确的位置 - Node.js版本:需要Node.js 18或更高版本
发展
构建
npm run build
发展模式
npm run dev
观看模式
npm run start
环境变量
GITLAB_HOST:GitLab API URL,包括/api/v4路径(例如。,https://gitlab.com/api/v4或https://gitlab.company.com/api/v4)-默认为https://gitlab.com/api/v4GITLAB_TOKEN:您的GitLab个人访问令牌(必填)
许可证
麻省理工学院许可证-版权所有(c)2025 Eva
此MCP服务器根据MIT许可证获得许可。您可以根据许可条款自由使用、修改和分发。