git-context-mcp
git-context-mcp
一个 MCP 服务器,回答每个开发者都会问的问题:“这段代码为什么存在?”
git blame 告诉你 谁 写了这行代码。而这个工具告诉你 为什么。
给定一个文件和行范围,git-context-mcp 会追溯提交记录,找到引入该代码的拉取请求 (PR),读取 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 日志、搜索 GitHub 以及交叉比对问题追踪器。Claude 一步即可完成。
Related MCP server: Selvedge
工具
工具 | 功能 |
| 文件 + 行范围 → 提交 + 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 (安装) +gh auth login用于 GitHub PR/Issue 查询没有
gh也可以运行 — 只是会跳过 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
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityDmaintenanceThe 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.46MIT
- AlicenseAqualityAmaintenanceChange tracking for AI-era codebases. AI agents call it to log structured change events (entity + diff + reasoning) before the session ends, then query history with diff, blame, history, changeset, and search. Captures the intent that would otherwise evaporate.819MIT
- AlicenseAqualityCmaintenanceSemantic git queries via MCP. Beyond git log — answer who/what/why about any line, file, or branch with blame, co-change, PR linkage.6242MIT
- Alicense-qualityBmaintenanceIndexes commit history to create a queryable expert, providing insights into code evolution, developer intent, and hidden patterns beyond static code analysis.MIT
Related MCP Connectors
Memory for coding agents: the decisions, the dead ends, and where the last session stopped.
Individual-analyst context layer: recall, remember, and reconcile your data and engineering context.
Independent static verification for exact immutable public GitHub commits.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/muhannad-hash/git-context-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server