mcpField
G
git-commit-aider MCP Server

git-commit-aider MCP Server

ローカル
github.com/MrOrzバージョン管理876 週間前に更新

git-commit-aider MCP Server について

git-commit-aider MCP Serverは、Gitのステージ済み変更をAIに代わってコミットし、コミッター名に「(aider)」を付けます。リポジトリ内でAIの貢献を識別したい、AIコーディングツールを使う開発者向けです。

主な機能

  1. 01ステージ済み変更のコミット
  2. 02コミットメッセージと作業ディレクトリの指定
  3. 03「(aider)」マーカーの追加
  4. 04環境変数またはGitユーザー設定の読み取り

活用シーン

  1. 01AI生成コードを含むコミットの識別
  2. 02コミット履歴に基づくAI貢献の集計

MCP 対応

クライアント向けに`commit_staged`ツールを公開し、Gitのステージ済み変更をコミットしてコミッター名に印を付けます。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

mcp.json · 共通設定
{
"mcpServers": {
"git-commit-aider": {
"command": "npx",
"args": [
"-y",
"mcp-git-commit-aider"
]
}
}
}
起動コマンドnpx -y mcp-git-commit-aider

ローカルサーバーにはマシン上の実行環境(Node.js 18 以上など)が必要です。設定ファイルの場所はクライアントごとに異なります。

パッケージ
npmmcp-git-commit-aider

ツール

1

掲載時のツール一覧 · 3 週間前に更新

パラメーター型必須説明
messagestringはいコミットメッセージ。
cwdstringいいえ任意:git コマンドの作業ディレクトリ(デフォルトはワークスペースのルート)。

詳細

git-commit-aider MCP サーバー

AI の代わりに Git コミットを行い、コードベースへの AI の貢献を追跡できるようにします。

これは TypeScript ベースの MCP サーバーで、Git リポジトリ内のステージ済みの変更をコミットするツールを提供します。コミッター名には「(aider)」が追加されます。

機能

この MCP サーバーが提供するツールは 1 つだけです。

commit_staged - 指定したメッセージで、ステージ済みの変更をコミットします。

  • コミットメッセージとして message(文字列、必須)を受け取ります。
  • git コマンドの作業ディレクトリを指定する cwd(文字列、任意)を受け取ります。
  • コミッター名に「(aider)」を自動的に追加します。
  • コミッター名とメールアドレスは、環境変数(GIT_COMMITTER_NAME、GIT_COMMITTER_EMAIL)が設定されていればそこから取得し、設定されていなければ git config user.name と git config user.email にフォールバックします。

このツールをコードエディターにインストールすると、次のように AI に指示できます。

変更をコミットしてください

通常、これは AI がコードベースに変更を加えた後に行います。そのため、AI は多くの場合、コンテキストに基づいた適切なコミットメッセージを提示できます。

インストール

このサーバーを使用するには、MCP 設定ファイルに設定を追加します。

{
  "mcpServers": {
    "git-commit-aider": {
      "command": "npx",
      "args": ["mcp-git-commit-aider"]
    }
  }
}

コミッター情報は、次の場所から取得されます。

  1. git の慣例に従った環境変数 GIT_COMMITTER_NAME と GIT_COMMITTER_EMAIL(git の慣例)。
  2. git config user.name および git config user.email コマンドの出力。
代替方法:コミット後に作成者を変更する

この MCP サーバーを使用したくない場合は、ターミナルで git コマンドを直接使用することもできます。

まず通常どおりコミットし、次に以下の git コマンドを実行して、直近のコミットの作成者を変更します。

git commit --amend --author="$(git config user.name) (aider) <$(git config user.email)>"

これにより、直近のコミットの作成者が、名前の末尾に「(aider)」を追加したあなたの名前に変更されます。

手順を簡略化するには、Git エイリアスを設定できます。ターミナルで次のコマンドを実行します。

git config --global alias.aimend '!git commit --amend --author="$(git config user.name) (aider) <$(git config user.email)>"'

設定後、次のコマンドを実行してエイリアスを使用できます。

git aimend

AI の貢献度の計算

「(aider)」が付いたコミットは、aider --stats コマンドで検出でき、コードベースへの AI の貢献度を確認できます。

また、以下のスクリプトを使用して、コード行数(追加、削除、変更の合計)で測定した、コードベースへの AI の貢献度を計算することもできます。

#!/bin/bash

# Script to calculate line changes (added, deleted, total) by AI and human authors
# between two commits.
# Output is in JSON format.
#
# This logic is extracted and altered from git-quick-stats.sh, MIT license.

# --- Configuration ---
# You may change the config to match your repository's convention.

# String to identify AI-generated commits in author names
AI_MATCHER="(aider)"

# Define patterns for files/paths to be excluded from the calculation.
# These will be converted to git pathspecs like ":(exclude)*package-lock.json"
IGNORE_PATTERNS=(
  "*package-lock.json"
  "*.lock"
)

# --- Helper Functions ---
function print_usage() {
  echo "Usage: $0 <REVISION_RANGE>"
  echo "  <REVISION_RANGE>: The revision range to analyze (e.g., HEAD~5..HEAD, my-branch, commit_sha)."
  echo "  Refer to 'git help log' or 'git help revisions' for more range options."
  echo "Example: $0 HEAD~5..HEAD"
  echo "Example: $0 origin..HEAD"
  echo "Example: $0 my-feature-branch"
  echo "Example: $0 abcdef1..fedcba2"
}

# --- Argument Parsing ---
if [ "$#" -ne 1 ]; then
  echo "Error: Incorrect number of arguments. Please provide a single revision range."
  print_usage
  exit 1
fi

REVISION_RANGE="$1"

# --- Main Logic ---

# Construct pathspec arguments for git log
pathspec_args=()
for pattern in "${IGNORE_PATTERNS[@]}"; do
  pathspec_args+=(":(exclude)$pattern")
done

git_log_output=$(git log "$REVISION_RANGE" --numstat --pretty="format:AuthorName:%an" -- "${pathspec_args[@]}")

# DEBUG: Uncomment to check the calculation for each commit.
# echo "$git_log_output"

# Process the log output with awk
result_json=$(echo "$git_log_output" | awk -v ai_matcher="$AI_MATCHER" '
BEGIN {
  ai_added = 0
  ai_deleted = 0
  human_added = 0
  human_deleted = 0
  current_author = ""
  is_ai_author = 0
}

/^AuthorName:/ {
  # Extract author name
  current_author = substr($0, length("AuthorName:") + 1)
  if (index(current_author, ai_matcher) > 0) {
    is_ai_author = 1
  } else {
    is_ai_author = 0
  }
  next
}

# Skip empty lines between commit blocks or lines that are not numstat
NF == 0 || !($1 ~ /^[0-9]+$/ && $2 ~ /^[0-9]+$/) {
  next
}

# Process numstat line: <added> <deleted> <file>
{
  added_lines = $1
  deleted_lines = $2

  # Skip binary files where numstat shows "-" for lines
  if (added_lines == "-" || deleted_lines == "-") {
    next
  }

  # Aggregate stats per author and file for details array
  file_name = $3
  # Robust key using File Separator character \034
  key = current_author "\034" file_name

  file_author_added[key] += added_lines
  file_author_deleted[key] += deleted_lines

  if (is_ai_author) {
    ai_added += added_lines
    ai_deleted += deleted_lines
  } else {
    human_added += added_lines
    human_deleted += deleted_lines
  }
}

END {
  ai_total_changed = ai_added + ai_deleted
  human_total_changed = human_added + human_deleted
  overall_total_changed = ai_total_changed + human_total_changed
  ai_percentage = 0.00

  if (overall_total_changed > 0) {
    ai_percentage = (ai_total_changed / overall_total_changed) * 100
  }

  printf "{\n"
  printf "  \"ai_percentage\": %.2f,\n", ai_percentage
  printf "  \"ai_changes\": {\"added\": %d, \"deleted\": %d, \"total\": %d},\n", ai_added, ai_deleted, ai_total_changed
  printf "  \"human_changes\": {\"added\": %d, \"deleted\": %d, \"total\": %d},\n", human_added, human_deleted, human_total_changed

  # Details array
  printf "  \"details\": [\n"
  first_detail = 1
  # Iterate over one of the arrays, keys should be consistent
  for (key in file_author_added) {
    if (!first_detail) {
      printf ",\n"
    }
    first_detail = 0

    # Split key "author\034fileName" into key_parts array
    # key_parts[1] will be author, key_parts[2] will be fileName
    split(key, key_parts, "\034")
    author = key_parts[1]
    fileName = key_parts[2]

    # Escape double quotes for JSON compatibility
    gsub(/"/, "\\\"", author)
    gsub(/"/, "\\\"", fileName)

    detail_added = file_author_added[key] + 0 # Ensure numeric
    detail_deleted = file_author_deleted[key] + 0 # Ensure numeric
    detail_total = detail_added + detail_deleted

    printf "    {\n"
    printf "      \"fileName\": \"%s\",\n", fileName
    printf "      \"author\": \"%s\", \"isAI\": %s,\n", author, (index(author, ai_matcher) > 0 ? "true" : "false")
    printf "      \"added\": %d, \"deleted\": %d, \"total\": %d\n", detail_added, detail_deleted, detail_total
    printf "    }"
  }
  printf "\n  ]\n"
  printf "}\n"
}
')

# --- Output ---
echo "$result_json"

使用例:

# Assume the script is saved as `calculate_ai_contribution.sh` and is executable (chmod +x calculate_ai_contribution.sh)

# Example 1: Analyze the last 5 commits
./calculate_ai_contribution.sh HEAD~5..HEAD

# Example 2: Analyze commits between a specific commit and HEAD
./calculate_ai_contribution.sh 90a5fcd4..HEAD

# Example 3: Analyze all commits on a feature branch not yet in main
./calculate_ai_contribution.sh main..my-feature-branch

# Example 4: Analyze commits between two tags
./calculate_ai_contribution.sh v1.0..v1.1

# Example output (will vary based on your repository and range):
# {
#   "ai_percentage": 48.53,
#   "ai_changes": { "added": 100, "deleted": 32, "total": 132 },
#   "human_changes": { "added": 103, "deleted": 37, "total": 140 },
#   "details": [
#     {
#       "fileName": "src/featureA.js",
#       "author": "Developer One (aider)", "isAI": true,
#       "added": 60, "deleted": 10, "total": 70
#     },
#     {
#       "fileName": "src/featureB.js",
#       "author": "Developer One (aider)", "isAI": true,
#       "added": 40, "deleted": 22, "total": 62
#     },
#     {
#       "fileName": "src/utils.js",
#       "author": "Developer Two", "isAI": false,
#       "added": 80, "deleted": 15, "total": 95
#     },
#     {
#       "fileName": "README.md",
#       "author": "Developer Two", "isAI": false,
#       "added": 23, "deleted": 22, "total": 45
#     }
#   ]
# }
出力フィールドの説明

JSON 出力には、次のフィールドが含まれます。

  • ai_percentage:合計変更行数(追加行数と削除行数の合計)のうち、AI 作成者(AI_MATCHER で識別)が占める割合(数値)。
  • ai_changes:(オブジェクト)AI 作成者による変更行数(added、deleted、およびその total)を集計したオブジェクトです。
  • human_changes:(オブジェクト)人間の作成者による変更行数(added、deleted、およびその total)を集計したオブジェクトです。
  • details:(オブジェクトの配列)変更の詳細な内訳を示します。配列内の各オブジェクトは、特定の author が特定の fileName に加えた貢献を表し、そのファイルにおけるその作成者による変更行数(added、deleted、および変更の total)が含まれます。

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。