git-context-mcp
git-context-mcp
すべての開発者が抱く疑問、**「なぜこのコードが存在するのか?」**に答えるMCPサーバー
git blameは誰がその行を書いたかを教えてくれます。これは、なぜ書かれたのかを教えてくれます。
ファイルと行範囲を指定すると、git-context-mcpはコミットを遡り、その変更を取り込んだプルリクエストを見つけ、PRの説明を読み、リンクされたすべてのGitHub Issueを抽出します。これらすべてを一度に、Claude内で直接行います。
デモ
You: Why does line 87 of src/auth/session.ts exist?
Claude (using blame_context):
Commit `a3f9c12` by Sarah Chen on 2024-08-14
Message: "fix: rotate session tokens on privilege escalation"
PR #441 — "Security: fix session fixation vulnerability"
Merged: 2024-08-15 | Labels: security, critical
PR Description:
> After the pen test in sprint 22, we found that session tokens
> weren't being rotated when a user's role changed. This allows
> a stolen low-priv token to be used after the account is promoted.
Linked Issue #389 — "Session token not rotated on role change" (closed)
> Reported by @contractor-red: "I was able to reuse a captured
> token after my account was upgraded to admin..."git logを掘り返したり、GitHubを検索したり、Issueトラッカーと照らし合わせたりする必要はもうありません。Claudeがワンステップで解決します。
Related MCP server: Git Insight MCP
ツール
ツール | 機能 |
| ファイル + 行範囲 → コミット + PR説明 + リンクされたIssue |
| コミットハッシュ → 完全なストーリー(メッセージ、差分統計、PR、Issue) |
| ファイル → 直近N件のコミット(それぞれPRとIssueの注釈付き) |
| キーワード → PR/Issueのコンテキストを含む一致するコミット |
| ファイル → 貢献者ランキングテーブル(コミット数、所有行数、活動期間) |
インストール
オプション1 — npx (インストール不要)
claude mcp add git-context -- npx git-context-mcpオプション2 — グローバルインストール
npm install -g git-context-mcp
claude mcp add git-context -- git-context-mcpオプション3 — 手動設定
~/.claude/claude_mcp_config.json に以下を追加します:
{
"mcpServers": {
"git-context": {
"command": "npx",
"args": ["git-context-mcp"]
}
}
}その後、Claude Codeを再起動してください。
要件
Claude Code (またはMCP互換クライアント)
PATH上の
gitghCLI (インストール) + GitHub PR/Issue検索のためのgh auth loginghがなくても動作しますが、PR/Issueのコンテキストはスキップされます
使用例
インストール後、任意のgitリポジトリでClaudeに自然に話しかけてください:
"Why does line 42 of src/db/connection.ts exist?"
"What's the story behind commit d4a8f91?"
"Who owns the most of src/payments/stripe.ts?"
"When was the rate limiting added? Search commits for 'rate limit'"
"Show me the last 5 changes to src/api/auth.ts and why each was made"仕組み
blame_contextが指定された行に対してgit blame -pを実行し、コミットハッシュを見つけます各コミットに対して
git showを呼び出し、完全なメッセージと差分統計を取得しますGitHub API (
gh api /repos/:owner/:repo/commits/:hash/pulls) を叩いてPRを見つけますPR本文から
#NNNや/issues/NNNの参照を解析し、各Issueを取得しますすべてが構造化されたMarkdownとして返され、Claudeが推論を行います
トークンは保存されません。GitHub自身のAPI以外(gh CLIと同じ)にはデータは送信されません。
コントリビューション
PRを歓迎します。サーバー全体は src/index.ts にあります。
git clone https://github.com/muhannad-hash/git-context-mcp
cd git-context-mcp
npm install
npm run dev # watch modeライセンス
MIT
Available Tools
5 toolsblame_contextA
Given a file and line range, returns who wrote those lines, when, the commit message, the associated pull request (title + description), and any linked issues. Answers the question: why does this code exist?
Inputs: file (required), start_line (required), end_line, repo_path.
commit_storyB
Given a commit hash, returns the full story: commit message, files changed, the pull request that landed it, the PR description, and all linked GitHub issues.
Inputs: hash (required), repo_path.
file_contributorsA
Shows every author who has ever committed to a file, ranked by number of commits. Includes current line ownership, commit percentage, and the date range they were active on the file.
Inputs: file (required), repo_path.
file_historyA
Returns the N most recent commits that touched a file, each annotated with its associated pull request and linked issues.
Inputs: file (required), limit, repo_path.
search_commitsA
Search commits by keyword across commit messages (and optionally code changes). Returns matching commits annotated with their pull requests and linked issues. Useful for finding when a feature was added, a bug was fixed, or a dependency was changed.
Inputs: query (required), repo_path, limit, search_code.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a clearly distinct purpose with no overlap: blame_context focuses on line-level authorship and rationale, commit_story provides comprehensive commit details, file_contributors shows author statistics, file_history gives recent commit timeline, and search_commits enables keyword-based discovery. The descriptions clearly differentiate their scopes and use cases.
All tools follow a consistent snake_case naming pattern with clear, descriptive compound names (e.g., blame_context, commit_story, file_contributors). The naming convention is uniform throughout, making the tool set predictable and easy to understand at a glance.
With 5 tools, this server is well-scoped for its purpose of providing Git context and history insights. Each tool serves a specific, valuable function in the domain, and the count is neither too sparse nor bloated, allowing comprehensive coverage without overwhelming complexity.
The tool set offers complete coverage for exploring Git history and context: from line-level blame and commit details to file authorship, recent changes, and commit search. There are no obvious gaps; agents can navigate from high-level searches to detailed investigations seamlessly, covering the full lifecycle of code changes.
Related MCP Connectors
Deterministic context layer for your codebase: change impact, blast radius, answers with receipts.
Codebase intelligence for AI coding agents: graph, git history, docs, decisions, code health.
One memory for every AI you work with: your rules, notes and decisions in your own Git repo.
Ask a codebase what calls what: search, blast radius, paths between symbols, and diffs.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceThe shared AI context engine for git — save, search, and share the reasoning behind code changes. Captures the why behind every commit and slide on PRs for coding agents.MIT
- AlicenseAqualityDmaintenanceSemantic git queries via MCP. Beyond git log — answer who/what/why about any line, file, or branch with blame, co-change, PR linkage.614 npm2MIT
- AlicenseNot gradedqualityDmaintenanceAnswers why code exists by tracing file:line or natural-language questions through git blame, commits, PRs, and linked issues, providing cited evidence from history.MIT
- FlicenseNot gradedqualityDmaintenanceEnables tracing any line in a local git repository back to the commit that actually introduced it and the PR/review discussion behind it, overcoming git blame's misleading last-touch attribution.-