Git MCP Server

by cyanheads
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Provides comprehensive Git operations including repository initialization, cloning, file staging, committing, branch management, tag operations, remote repository handling, and stash management, enabling LLMs to interact with Git repositories.

  • Supports interactions with GitHub repositories through Git operations like cloning from GitHub URLs, pushing to and pulling from GitHub remotes, enabling LLMs to manage code on GitHub.

GIT MCP サーバー

Gitリポジトリを操作するためのツールを提供するモデルコンテキストプロトコル(MCP)サーバー。このサーバーにより、AIアシスタントやLLMエージェントは、ファイルシステムやコマンドラインへの直接アクセスを必要とせずに、標準化されたインターフェースを介してリポジトリ、ブランチ、コミット、ファイルを管理できます。適切なセキュリティ境界を維持しながら、コア機能にはsimple-gitライブラリを活用し、Git操作をMCPのリソースおよびツールとして公開します。

目次

概要

主な機能:

  • リポジトリ管理: リポジトリの初期化、クローン作成、ステータスの確認
  • ブランチ操作: ブランチの作成、一覧表示、チェックアウト、削除、マージ
  • 作業ディレクトリ: ファイルのステージング、変更のコミット、差分の作成
  • リモート操作: リモートの追加、フェッチ、プル、プッシュ
  • 高度な Git コマンド: タグの管理、変更のスタッシュ、チェリーピック、リベース

アーキテクチャとコンポーネント

コアシステムアーキテクチャ:

コアコンポーネント:

  • MCP サーバー ( server.ts ) : @modelcontextprotocol/sdkを使用して、リソースとツールを公開するサーバーを作成します。
  • Git サービス ( services/git-service.ts ) : Git 操作用のクリーンなインターフェイスを提供するsimple-gitライブラリの抽象化レイヤー。
  • リソース ( resources/ ) : 一貫した URI テンプレートを使用して、MCP リソースを通じて Git データ (ステータス、ログ、ファイル コンテンツなど) を公開します。
  • ツール ( tools/ ) : 明確に定義された入力スキーマ (Zod を使用して検証済み) を使用して、MCP ツールを通じて Git アクション (コミット、プッシュ、プルなど) を公開します。
  • エラー処理 ( services/error-service.ts ) : Git および MCP 操作の標準化されたエラー処理とレポート。
  • エントリ ポイント ( index.ts ) : サーバーを初期化して起動し、標準 I/O トランスポートに接続します。

特徴

リソースアクセス

MCP リソースを通じて Git リポジトリ情報を公開します。

  • リポジトリ情報: 現在のブランチ、ステータス、参照の詳細など、Git リポジトリの基本的な情報にアクセスします。
  • リポジトリブランチ: 現在のブランチインジケーターとともにリポジトリ内のすべてのブランチを一覧表示します
  • リポジトリリモート: 設定されたすべてのリモートリポジトリとそのURLを一覧表示します
  • リポジトリタグ: リポジトリ内のすべてのタグとその参照を一覧表示します
  • ファイルコンテンツ: 指定された Git 参照の特定のファイルの内容にアクセスします
  • ディレクトリ一覧: 特定のパスと参照にあるファイルとディレクトリの一覧を表示します。
  • 差分: 参照、ステージングされていない変更、ステージングされた変更間の差分を取得します
  • コミット履歴: 作成者、日付、メッセージ情報を含む詳細なコミットログを表示します。
  • ファイルの責任: 各行を最後に変更したコミットを示す行ごとの属性を表示します。
  • コミットの詳細: 差分の変更を含む特定のコミットの詳細情報にアクセスします

Git操作

MCP ツールを通じて Git コマンドを実行します。

  • リポジトリ操作: リポジトリの初期化、リモートからのクローン作成、リポジトリのステータスの確認
  • ブランチ操作: ブランチの作成、ブランチの一覧表示、チェックアウト、ブランチの削除、マージ
  • 作業ディレクトリの操作: ファイルのステージング、ファイルのステージング解除、変更のコミット、差分の作成
  • リモート操作: リモートの追加、リモートの一覧表示、フェッチ、プル、プッシュ
  • 高度な操作: タグの管理、変更のスタッシュ、チェリーピックコミット、ブランチのリベース、リセット、クリーン

インストール

前提条件

  • Node.js 16以上
  • Gitがインストールされ、PATHで利用可能

NPMからインストール

npm install -g @cyanheads/git-mcp-server

ソースからインストール

git clone https://github.com/cyanheads/git-mcp-server.git cd git-mcp-server npm install npm run build

使用法

サーバーの実行

NPM 経由でグローバルにインストールした場合:

git-mcp-server

ソースから実行する場合:

node build/index.js

サーバーはモデル コンテキスト プロトコルを使用して stdin/stdout を介して通信し、あらゆる MCP クライアントと互換性があります。

クロードとの統合

Claude 構成ファイル (例: cline_mcp_settings.jsonまたはclaude_desktop_config.json ) に追加します。

{ "mcpServers": { "git": { "command": "git-mcp-server", // Or the full path to build/index.js if not installed globally "args": [], "env": {}, "disabled": false, "autoApprove": [] // Configure auto-approval rules if desired } } }

他のMCPクライアントとの統合

MCP インスペクタを使用してサーバーをテストします。

# If installed globally npx @modelcontextprotocol/inspector git-mcp-server # If running from source npx @modelcontextprotocol/inspector build/index.js

プロジェクト構造

コードベースはモジュール構造に従います。

git-mcp-server/ ├── src/ │ ├── index.ts # Entry point: Initializes and starts the server │ ├── server.ts # Core MCP server implementation and setup │ ├── resources/ # MCP Resource implementations │ │ ├── descriptors.ts # Resource URI templates and descriptions │ │ ├── diff.ts # Diff-related resources (staged, unstaged, commit) │ │ ├── file.ts # File content and directory listing resources │ │ ├── history.ts # Commit history and blame resources │ │ ├── index.ts # Aggregates and registers all resources │ │ └── repository.ts # Repository info, branches, remotes, tags resources │ ├── services/ # Core logic and external integrations │ │ ├── error-service.ts # Centralized error handling utilities │ │ └── git-service.ts # Abstraction layer for simple-git operations │ ├── tools/ # MCP Tool implementations │ │ ├── advanced.ts # Advanced Git tools (tag, stash, cherry-pick, rebase, log, show) │ │ ├── branch.ts # Branch management tools (list, create, checkout, delete, merge) │ │ ├── index.ts # Aggregates and registers all tools │ │ ├── remote.ts # Remote interaction tools (add, list, fetch, pull, push) │ │ ├── repository.ts # Repository level tools (init, clone, status) │ │ └── workdir.ts # Working directory tools (add, reset, commit, diff, reset-commit, clean) │ ├── types/ # TypeScript type definitions │ │ └── git.ts # Custom types related to Git operations │ └── utils/ # Shared utility functions │ ├── global-settings.ts # Manages global working directory setting │ └── validation.ts # Input validation schemas (Zod) and helpers ├── build/ # Compiled JavaScript output ├── docs/ # Documentation files ├── logs/ # Log files (if any) ├── scripts/ # Helper scripts for development (e.g., clean, tree) ├── .env.example # Example environment variables ├── .gitignore # Git ignore rules ├── LICENSE # Project license file ├── package.json # Project metadata and dependencies ├── package-lock.json # Lockfile for dependencies ├── README.md # This file └── tsconfig.json # TypeScript compiler configuration

ツール

Git MCP サーバーは、Git 操作用の包括的なツール スイートを提供します。

リポジトリ操作

道具説明
git_initベア リポジトリのオプションを使用して、指定されたパスに新しい Git リポジトリを初期化します。
git_cloneブランチと深さのオプションを使用して、リモート URL からローカル パスに Git リポジトリのクローンを作成します。
git_status作業ディレクトリやステージング領域の変更など、Git リポジトリの現在のステータスを取得します。

支店運営

道具説明
git_branch_listリモート ブランチを含めるオプションを使用して、リポジトリ内のすべてのブランチを一覧表示します。
git_branch_create開始点と自動チェックアウトを指定するためのオプションを使用して、新しいブランチを作成します。
git_checkoutチェックアウト中に新しいブランチを作成するオプションを使用して、ブランチ、タグ、またはコミットをチェックアウトします。
git_branch_deleteマージされていないブランチを強制的に削除するオプションを使用してブランチを削除します。
git_mergeカスタマイズ可能なコミット メッセージとマージ戦略を使用して、ブランチを現在のブランチにマージします。

作業ディレクトリの操作

道具説明
git_add個々のファイルまたはディレクトリ全体のサポートを使用して、コミット用にファイルをステージングします。
git_reset特定のファイルまたはステージングされたすべての変更のオプションを使用して、ステージング領域からファイルをステージング解除します。
git_commitカスタマイズ可能なコミット メッセージ、作成者情報、修正オプションを使用して、ステージングされた変更をコミットします。
git_diff_unstaged特定のファイルのオプションを使用して、作業ディレクトリ内のステージングされていないすべての変更の差分を取得します。
git_diff_staged特定のファイルのオプションを使用して、インデックス内のすべてのステージングされた変更の差分を取得します。
git_reset_commitハード、ソフト、または混合モードのオプションを使用して、リポジトリを特定の参照にリセットします。
git_cleanディレクトリのオプションを使用して、作業ツリーから追跡されていないファイルを削除し、強制的にクリーンアップします。

リモート操作

道具説明
git_remote_add名前と URL を指定して新しいリモート リポジトリを追加します。
git_remote_list設定されているすべてのリモート リポジトリとその URL を一覧表示します。
git_fetch特定のブランチのオプションを使用して、リモート リポジトリから更新を取得します。
git_pullリベース戦略のオプションを使用して、リモート リポジトリから変更をプルします。
git_push強制プッシュとアップストリーム トラッキングのオプションを使用して、ローカルの変更をリモート リポジトリにプッシュします。

高度な操作

道具説明
git_tag_createメッセージ付きの注釈付きタグのオプションを使用して、新しいタグを作成します。
git_tag_listリポジトリ内のすべてのタグとその参照を一覧表示します。
git_stash_create追跡されていないファイルと説明のオプションを使用して、作業ディレクトリ内の変更を保存します。
git_stash_listリポジトリ内のすべてのスタッシュをその説明とともに一覧表示します。
git_stash_applyスタッシュリストから削除せずにスタッシュされた変更を適用します。
git_stash_popスタッシュされた変更を適用し、スタッシュ リストから削除します。
git_cherry_pick特定のコミットからの変更を現在のブランチに適用します。
git_rebase対話型モード オプションを使用して、現在のブランチを別のブランチにリベースします。
git_logカスタマイズ可能な出力形式と深度でコミット履歴を取得します。
git_show差分の変更を含む特定のコミットの詳細情報を表示します。

リソース

Git MCP サーバーは、標準の MCP リソースを通じて Git データを公開します。

リポジトリリソース

リソース説明
git://repo/{repoPath}/info現在のブランチ、ステータス、参照の詳細を含む基本的な Git リポジトリ情報
git://repo/{repoPath}/branches現在のブランチインジケーター付きのリポジトリ内のすべてのブランチのリスト
git://repo/{repoPath}/remotes設定されているすべてのリモートリポジトリとその URL のリスト
git://repo/{repoPath}/tagsリポジトリ内のすべてのタグとその参照のリスト
git://repo/{repoPath}/file/{filePath}?ref={ref}指定されたGit参照の特定のファイルの内容を返します
git://repo/{repoPath}/ls/{dirPath}?ref={ref}特定のパスと参照にあるファイルとディレクトリのリストを返します
git://repo/{repoPath}/diff/{fromRef}/{toRef}?path={path}2つのGit参照(コミット、ブランチ、タグ)間の差分を返します
git://repo/{repoPath}/diff-unstaged?path={path}作業ディレクトリ内のステージングされていないすべての変更の差分を返します
git://repo/{repoPath}/diff-staged?path={path}インデックス内のすべてのステージングされた変更の差分を返します
git://repo/{repoPath}/log?maxCount={maxCount}&file={file}作成者、日付、メッセージの詳細を含むコミット履歴ログを返します。
git://repo/{repoPath}/blame/{filePath}各行を最後に変更したコミットを示す行ごとの属性を返します。
git://repo/{repoPath}/commit/{commitHash}特定のコミットに関する詳細情報(差分の変更を含む)を返します。

発達

ビルドとテスト

# Build the project npm run build # Watch for changes and rebuild automatically npm run watch # Test the server locally using the MCP inspector tool npm run inspector # Clean build artifacts npm run clean # Generate a file tree representation for documentation npm run tree # Clean and rebuild the project completely npm run rebuild

ライセンス

Apache License 2.0 - 詳細についてはLICENSE を参照してください。


You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

大規模言語モデルが堅牢な API を介して Git リポジトリと対話できるようにし、リポジトリの初期化、クローン作成、ファイルのステージング、コミット、ブランチ管理などの操作をサポートするモデル コンテキスト プロトコル サーバー。

  1. Table of Contents
    1. Overview
      1. Architecture & Components
    2. Features
      1. Resource Access
      2. Git Operations
    3. Installation
      1. Prerequisites
      2. Install from NPM
      3. Install from Source
    4. Usage
      1. Running the Server
      2. Integration with Claude
      3. Integration with Other MCP Clients
    5. Project Structure
      1. Tools
        1. Repository Operations
        2. Branch Operations
        3. Working Directory Operations
        4. Remote Operations
        5. Advanced Operations
      2. Resources
        1. Repository Resources
      3. Development
        1. Build and Test
      4. License
        ID: e0hyslgby6