mcpField
G
git-history

git-history

本地服务
github.com/tonyweckstrom1987版本控制01 周前更新

关于 git-history

git-history 是 MCP 服务,为 AI Agent 提供只读的 Git 历史访问能力。开发者可用它查明代码何时、为何变更,谁编写了指定行,以及不同引用之间的差异。

主要功能

  1. 01按提交说明搜索提交
  2. 02查看近期提交和差异
  3. 03追踪文件历史及行作者
  4. 04列出仓库贡献者
  5. 05比较引用,可限定文件

适用场景

  1. 01查找导致行为变化的提交
  2. 02确认文件或代码行的最近修改者
  3. 03审查分支或标签之间的差异

MCP 相关

该服务通过 stdio 向 MCP 客户端提供 Git 历史工具。所有操作均使用只读 Git 命令,不会修改仓库。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"tonyweckstrom1987-git-history": {
"command": "npx",
"args": [
"-y",
"mcp-server-git-history"
]
}
}
}
启动命令npx -y mcp-server-git-history

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmmcp-server-git-history1.1.1

工具

7

收录的工具列表 · 更新于 2 周前

参数类型必填说明
limitinteger否最多返回的结果数(默认 20)
querystring是提交说明中的搜索词或短语

详细介绍

mcp-server-git-history

npm version CI License: MIT

最新发布版本:1.1.2 — https://www.npmjs.com/package/mcp-server-git-history

一个 MCP 服务(Model Context Protocol),为 AI Agent(Claude Desktop、Cursor、Windsurf)提供读取和搜索 Git 仓库历史记录的工具。

它解决了这样一个问题:AI 能看到当前代码,却不知道某项变更为何发生,或谁最近做了这项变更。

技术栈: Node.js 18/20/22/24、Model Context Protocol(stdio)、simple-git、zod。许可证:LICENSE。

目录: 快速开始 · 工具 · 响应示例 · 安装到 Claude Desktop · 安装到 Cursor · 本地开发与测试 · 结构

快速开始

一个 MCP 服务,为 AI Agent(Claude Desktop、Cursor、Windsurf)提供读取和搜索 Git 历史记录的工具,包括搜索提交、查看文件历史、blame、贡献者,以及比较不同引用之间的差异。

可直接使用 npx 运行(无需安装):

npx -y mcp-server-git-history /path/to/your/repo

将其添加到 Claude Desktop 的配置文件(claude_desktop_config.json)中:

{
  "mcpServers": {
    "git-history": {
      "command": "npx",
      "args": ["-y", "mcp-server-git-history", "/path/to/your/repo"]
    }
  }
}

重启 Claude Desktop,然后询问类似这样的问题:"src/index.js 上次是什么时候修改的?为什么?"

工具

  • search_commits(query, limit?) — 按提交消息中的关键词搜索提交
  • get_recent_commits(limit?) — 获取最新提交(概览近期变更)
  • get_commit_diff(commitHash) — 获取某次提交的完整差异
  • get_file_history(filePath, limit?) — 获取文件变更历史(谁、何时、为何)
  • blame_file(filePath, startLine?, endLine?) — 逐行执行 git blame:查看每一行由谁在哪次提交中编写
  • get_contributors(limit?) — 汇总提交者及其提交次数(git shortlog -sn)
  • get_diff_between_refs(fromRef, toRef, filePath?) — 比较两个提交/分支/标签之间的差异,可选将范围限定为单个文件
调用示例
{ "name": "search_commits", "arguments": { "query": "login-bugi", "limit": 10 } }
{ "name": "get_recent_commits", "arguments": { "limit": 5 } }
{ "name": "get_commit_diff", "arguments": { "commitHash": "a1b2c3d" } }
{ "name": "get_file_history", "arguments": { "filePath": "src/index.js", "limit": 10 } }
{ "name": "blame_file", "arguments": { "filePath": "src/index.js", "startLine": 10, "endLine": 25 } }
{ "name": "get_contributors", "arguments": { "limit": 10 } }
{ "name": "get_diff_between_refs", "arguments": { "fromRef": "main", "toRef": "HEAD", "filePath": "src/index.js" } }

**只读:**所有工具仅使用只读 Git 命令(log、show、blame、shortlog、diff)。服务不会修改仓库。

响应示例

get_recent_commits 返回一个 JSON 列表(实际结果来自 npm test):

[
  {
    "hash": "bc3338e",
    "date": "2026-10-05T14:29:43+03:00",
    "author": "tonyweckstrom1987",
    "message": "Upgrade GitHub Actions to latest versions"
  }
]

安装到 Claude Desktop

将以下内容添加到 claude_desktop_config.json 文件中:

{
  "mcpServers": {
    "git-history": {
      "command": "npx",
      "args": ["-y", "mcp-server-git-history", "/polku/repositorioosi"]
    }
  }
}

也可以通过 GIT_REPO_PATH 环境变量指定仓库路径;如果不指定,则使用服务的启动目录。

重启 Claude Desktop,然后询问例如:"src/index.js 上次是什么时候修改的?为什么?"

安装到 Cursor

将以下内容添加到项目的 .cursor/mcp.json 文件中(或全局 ~/.cursor/mcp.json 文件中):

{
  "mcpServers": {
    "git-history": {
      "command": "npx",
      "args": ["-y", "mcp-server-git-history", "/polku/repositorioosi"]
    }
  }
}

在 Cursor 设置中打开 MCP 标签页,并确认 git-history 服务正在运行(绿色圆点)。与 Claude Desktop 一样,GIT_REPO_PATH 环境变量和命令行参数也适用。

本地开发与测试

git clone <repo>
cd mcp-server-git-history
npm install
npm test                                        # testaa tätä samaa repoa
node test/manual-test.js /polku/johonkin/git-repoon   # tai jotain muuta repoa

测试脚本会以子进程方式启动服务,并通过真正的 MCP 协议(使用 @modelcontextprotocol/sdk 的 Client + StdioClientTransport)调用所有工具,而不只是直接调用函数——这与 Claude Desktop 实际调用服务的方式相同。

为什么维护成本为零

服务本身不会调用 AI——它只读取 Git 数据并返回。AI(例如 Claude Desktop)会调用服务,而不是反过来。无需 API 密钥,也没有费用。

结构

  • bin/server.js — MCP 服务、工具注册(McpServer + StdioServerTransport)
  • lib/git-tools.js — Git 逻辑(simple-git)
  • test/manual-test.js — 使用真实 MCP 客户端进行端到端测试

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。