关于 git-mcp-server
git-mcp-server 为使用托管或自托管仓库的团队提供 GitHub 和 GitLab 的仓库、议题、合并请求及 CI/CD 操作。其与平台无关的工具覆盖读写任务,并可关闭写入操作。
主要功能
- 01支持 GitHub 与 GitLab
- 02浏览和修改仓库
- 03议题与合并请求操作
- 04检查 CI/CD 流水线和任务
- 05只读模式
适用场景
- 01查看仓库文件与历史
- 02创建或更新议题和合并请求
- 03检查流水线状态与任务日志
- 04将连接的服务限制为只读
MCP 相关
该项目是 MCP 服务,向 MCP 客户端提供 GitHub 和 GitLab 的仓库、议题、合并请求、评论、用户及 CI/CD 工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
mcp.json · 通用配置
启动命令
npx -y @raytien/git-mcp-server需要配置的环境变量
GIT_PROVIDERProvider type: gitlab or githubGIT_TOKEN密钥Personal Access Token for GitHub or GitLabGIT_API_URLAPI URL for self-hosted instancesGIT_READ_ONLYDisable write operations (true/false)本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。
工具
23收录的工具列表 · 更新于 2 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| ref | string | 否 | 分支名称、标签或提交 SHA(默认:默认分支) |
| path | string | 是 | 仓库中的文件或目录路径 |
| repo | string | 是 | 仓库标识符(GitLab:"group/project" 或 ID;GitHub:"owner/repo") |
详细介绍
Git MCP Server
简洁、模块化的 Git MCP 服务,支持 GitHub 和 GitLab。
快速开始
Claude Desktop 配置
添加到 claude_desktop_config.json:
macOS:~/Library/Application Support/Claude/claude_desktop_config.json
Windows:%APPDATA%\Claude\claude_desktop_config.json
GitHub
{
"mcpServers": {
"git": {
"command": "npx",
"args": ["-y", "@raytien/git-mcp-server"],
"env": {
"GIT_PROVIDER": "github",
"GIT_TOKEN": "ghp_xxxxxxxxxxxxxxxxxxxx"
}
}
}
}
GitHub Enterprise
{
"mcpServers": {
"git": {
"command": "npx",
"args": ["-y", "@raytien/git-mcp-server"],
"env": {
"GIT_PROVIDER": "github",
"GIT_API_URL": "https://github.your-company.com/api/v3",
"GIT_TOKEN": "ghp_xxxxxxxxxxxxxxxxxxxx"
}
}
}
}
GitLab.com(SaaS)
{
"mcpServers": {
"git": {
"command": "npx",
"args": ["-y", "@raytien/git-mcp-server"],
"env": {
"GIT_PROVIDER": "gitlab",
"GIT_TOKEN": "glpat-xxxxxxxxxxxxxxxxxxxx"
}
}
}
}
自托管 GitLab
{
"mcpServers": {
"git": {
"command": "npx",
"args": ["-y", "@raytien/git-mcp-server"],
"env": {
"GIT_PROVIDER": "gitlab",
"GIT_API_URL": "https://gitlab.your-company.com/api/v4",
"GIT_TOKEN": "glpat-xxxxxxxxxxxxxxxxxxxx"
}
}
}
}
只读模式
{
"mcpServers": {
"git": {
"command": "npx",
"args": ["-y", "@raytien/git-mcp-server"],
"env": {
"GIT_PROVIDER": "github",
"GIT_TOKEN": "ghp_xxxxxxxxxxxxxxxxxxxx",
"GIT_READ_ONLY": "true"
}
}
}
}
获取令牌
GitHub
- 前往 GitHub > Settings > Developer settings > Personal access tokens > Tokens (classic)
- 生成一个具有以下作用域的新令牌:
repo、read:org、workflow - 复制令牌(以
ghp_开头)
GitLab
- 前往 GitLab > Settings > Access Tokens
- 创建一个具有以下作用域的新令牌:
api、read_api、read_repository、write_repository - 复制令牌(以
glpat-开头)
可用工具
仓库
| 工具 | 描述 |
|---|---|
get_file_contents | 读取仓库中的文件内容 |
get_repository_tree | 列出目录结构 |
push_files | 在单次提交中推送文件更改 |
create_branch | 创建新分支 |
list_branches | 列出仓库分支 |
list_commits | 列出提交历史 |
search_code | 在仓库中搜索代码 |
问题
| 工具 | 描述 |
|---|---|
get_issue | 获取单个问题 |
list_issues | 列出问题 |
create_issue | 创建新问题 |
update_issue | 更新问题 |
拉取请求/合并请求
| 工具 | 描述 |
|---|---|
get_pull_request | 获取合并请求 |
list_pull_requests | 列出合并请求 |
create_pull_request | 创建合并请求 |
get_pull_request_diffs | 获取合并请求的更改 |
merge_pull_request | 合并合并请求 |
CI/CD(管道 / 工作流运行)
| 工具 | 描述 |
|---|---|
get_pipeline | 获取管道/工作流运行状态 |
list_pipelines | 列出管道/工作流运行 |
list_pipeline_jobs | 列出管道作业/工作流作业 |
get_job_log | 获取作业日志输出 |
注意:GitHub Actions 工作流运行会映射到 GitLab 管道。同一组工具适用于两个平台。
评论
| 工具 | 描述 |
|---|---|
create_comment | 为问题/MR 添加评论 |
list_comments | 列出评论 |
用户
| 工具 | 描述 |
|---|---|
get_me | 获取当前已认证用户 |
配置
| 环境变量 | 必需 | 默认值 | 描述 |
|---|---|---|---|
GIT_PROVIDER | 否 | gitlab | 提供商类型:gitlab 或 github |
GIT_TOKEN | 是 | - | 个人访问令牌 |
GIT_API_URL | 否 | 提供商默认值 | API URL(根据提供商自动检测) |
GIT_AUTH_TYPE | 否 | bearer | 认证类型:bearer 或 private-token |
GIT_READ_ONLY | 否 | false | 禁用写入操作 |
LOG_LEVEL | 否 | info | 日志级别:debug、info、warn、error |
架构
src/
├── index.ts # Entry point
├── server.ts # MCP server (provider-agnostic)
├── config.ts # Configuration (multi-provider)
├── providers/ # Platform abstraction
│ ├── interface.ts # GitProvider interface
│ ├── types.ts # Platform-agnostic types
│ ├── config.ts # Provider configuration
│ ├── factory.ts # Provider Factory (creates GitLab/GitHub)
│ ├── gitlab/ # GitLab implementation
│ └── github/ # GitHub implementation
├── tools/ # Tool definitions
│ ├── define.ts # defineTool helper
│ ├── registry.ts # Tool registry
│ ├── repository/ # Repository tools
│ ├── issues/ # Issue tools
│ ├── merge-requests/ # PR/MR tools
│ ├── pipelines/ # CI/CD tools
│ ├── notes/ # Comment tools
│ └── users/ # User tools
├── gitlab/ # GitLab API client
│ ├── client.ts # HTTP client
│ └── types.ts # GitLab API types
├── github/ # GitHub API client
│ ├── client.ts # HTTP client
│ └── types.ts # GitHub API types
├── auth/ # Authentication
└── lib/ # Utilities
开发
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Run locally
npm start
# Development mode (watch)
npm run dev
添加新工具
- 创建文件:
src/tools/{category}/{action}.ts
import { z } from 'zod';
import { defineTool, repoParam } from '../define.js';
const schema = z.object({
repo: repoParam,
// ... your params
});
export const myTool = defineTool({
name: 'my_tool',
description: 'What this tool does',
schema,
category: 'my-category',
read_only: true,
handler: async (input, ctx) => {
return ctx.provider.repository.someMethod(input.repo, ...);
},
});
- 从类别索引导出:
src/tools/{category}/index.ts - 添加到 allTools:
src/tools/index.ts
灵感来源
- gitlab-mcp - GitLab MCP 服务
- github-mcp-server - 官方 GitHub MCP 服务
许可证
MIT
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。