mcpField
G
git-mcp-server

git-mcp-server

本地服务
github.com/Ray0907版本控制046 周前更新

关于 git-mcp-server

git-mcp-server 为使用托管或自托管仓库的团队提供 GitHub 和 GitLab 的仓库、议题、合并请求及 CI/CD 操作。其与平台无关的工具覆盖读写任务,并可关闭写入操作。

主要功能

  1. 01支持 GitHub 与 GitLab
  2. 02浏览和修改仓库
  3. 03议题与合并请求操作
  4. 04检查 CI/CD 流水线和任务
  5. 05只读模式

适用场景

  1. 01查看仓库文件与历史
  2. 02创建或更新议题和合并请求
  3. 03检查流水线状态与任务日志
  4. 04将连接的服务限制为只读

MCP 相关

该项目是 MCP 服务,向 MCP 客户端提供 GitHub 和 GitLab 的仓库、议题、合并请求、评论、用户及 CI/CD 工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"ray0907-git": {
"command": "npx",
"args": [
"-y",
"@raytien/git-mcp-server"
],
"env": {
"GIT_PROVIDER": "<GIT_PROVIDER>",
"GIT_TOKEN": "<GIT_TOKEN>",
"GIT_API_URL": "<GIT_API_URL>",
"GIT_READ_ONLY": "<GIT_READ_ONLY>"
}
}
}
}
启动命令npx -y @raytien/git-mcp-server
需要配置的环境变量
GIT_PROVIDERProvider type: gitlab or github
GIT_TOKEN密钥Personal Access Token for GitHub or GitLab
GIT_API_URLAPI URL for self-hosted instances
GIT_READ_ONLYDisable write operations (true/false)

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@raytien/git-mcp-server0.2.3

工具

23

收录的工具列表 · 更新于 2 周前

参数类型必填说明
refstring否分支名称、标签或提交 SHA(默认:默认分支)
pathstring是仓库中的文件或目录路径
repostring是仓库标识符(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
  1. 前往 GitHub > Settings > Developer settings > Personal access tokens > Tokens (classic)
  2. 生成一个具有以下作用域的新令牌:repo、read:org、workflow
  3. 复制令牌(以 ghp_ 开头)
GitLab
  1. 前往 GitLab > Settings > Access Tokens
  2. 创建一个具有以下作用域的新令牌:api、read_api、read_repository、write_repository
  3. 复制令牌(以 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

添加新工具

  1. 创建文件: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, ...);
    },
});
  1. 从类别索引导出:src/tools/{category}/index.ts
  2. 添加到 allTools:src/tools/index.ts

灵感来源

许可证

MIT

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。