Git多平台服务器

一个支持GitHub和GitLab的模块化Git服务器,提供代码仓库管理、问题跟踪、合并请求和CI/CD等功能。

  • by Ray0907
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Ray0907/git-mcp-server

使用说明

Git MCP服务器

一个干净、模块化的Git MCP服务器,支持GitHub和GitLab。

快速开始

Claude桌面配置

添加到您的 claude_desktop_config.json:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %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企业版

{
  "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>设置>开发者设置>个人访问令牌>令牌(经典)
  2. 生成具有作用域的新令牌: repo, read:org, workflow
  3. 复制令牌(以开头 ghp_)

GitLab

  1. 转到GitLab>设置>访问令牌
  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. 添加到所有工具: src/tools/index.ts

灵感

许可证

麻省理工学院