Git Mcp

io.github.selfagency由 GitHub 账号 selfagency 发布v0.4.2更新于 Oct 24, 2026

A Git MCP server that doesn't suck

已验证STDIO仅桌面效率与工作流开发者工具

概览

AI 生成的概览

本地运行的 Git MCP 服务器,让 AI 编程助手通过 18 组工具查看、提交、分支、推送、改写历史并创建拉取请求。

可以做什么
查看仓库:状态、差异、日志、blame、reflog、配置和提交搜索,并提供状态、日志、分支和差异的只读 MCP 资源。暂存、提交、修补、还原、重置和撤销改动,硬重置和 nuke 需要确认。管理分支、远程、fetch、pull 和 push,并处理 stash、rebase、cherry-pick、merge、bisect、标签、工作树和子模块。驱动 Git Flow、Git LFS 以及带备份和恢复的历史改写。统计仓库分析数据,在 GitHub、GitLab、Forgejo、Gitea 和 Bitbucket 上创建、列出和合并拉取请求,并查询 git-scm 文档和 man 手册。
适用场景
适合希望编程助手通过结构化工具而非原始 shell 命令操作 Git 的场景,涵盖日常提交与分支工作,以及恢复、历史改写、工作树、LFS 和拉取请求。最适合 Claude Desktop、VS Code Copilot 或 Cursor 等桌面助手在本地仓库上使用。
运行要求
以 npm 包形式通过 stdio 在本地运行,需要 Node.js 以及 npx 或全局安装,还需要 Git 本身。默认仓库通过 GIT_REPO_PATH 或 --repo-path 参数设置,否则每次调用都要传 repo_path。Git Flow 需要 PATH 中有 git-flow-next CLI。拉取请求操作使用 gh、glab 或 tea CLI,或使用 GITHUB_TOKEN、GITLAB_TOKEN、FORGEJO_TOKEN、BITBUCKET_TOKEN 等令牌。
安装前请注意
变更类工具被标记为破坏性,可能修改、丢弃或删除工作:硬重置、nuke、restore、删除分支和历史改写都会改动仓库,部分需要 confirm=true。除非设置 GIT_ALLOW_FORCE_PUSH 或 GIT_ALLOW_NO_VERIFY,否则强制推送和跳过钩子不可用;Git Flow 钩子仅在 GIT_ALLOW_FLOW_HOOKS 开启时执行。签名使用 GIT_SIGNING_KEY。代码托管平台令牌可访问远程仓库和拉取请求。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Git Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

git-mcp

[CI] [codecov] [NPM Version]

A Git MCP server that doesn't suck

Exposes the full Git workflow to any MCP-compatible AI agent — inspect, write, branch, remote, stash, rebase, LFS, git-flow, documentation lookup, and more. Designed to be safe by default, composable, and fast. Powered by simple-git.

Built for coding agents in tools like GitHub Copilot, Claude Code, Cursor, and OpenAI Codex, while remaining compatible with any MCP client that can call tools and resources.


Features

  • 18 tools with 80+ actions covering everyday Git workflows, advanced recovery, history rewriting, repository analytics, forge pull requests, and external VCS awareness
  • Safety-first — destructive operations require explicit confirmation; force push and hook bypass are opt-in via server config
  • GPG/SSH signing for commits and tags, with server-level auto-sign support
  • Git LFS — track patterns, manage objects, install hooks, migrate history
  • Git Flow — drives the git-flow-next CLI, so the finish state machine, conflict recovery, and worktree lifecycle stay correct as the CLI evolves. Preset init, overview, config CRUD, generalized topic actions, and classic feature/release/hotfix/support aliases
  • Documentation lookup — search git-scm.com and fetch man pages directly from the LLM
  • MCP Resources — URI-addressable read-only views of status, log, branches, and diff
  • Bundled agent skill — skills/git-mcp-workflow/ documents MCP-first Git workflows, recovery, worktrees, releases, and advanced operations for AI agents and coding agents; installable via skills-npm and skill.sh
  • External VCS awareness — git_but_check / git_jj_check detect GitButler and Jujutsu and guide agents to prefer their native CLIs/MCP (with but teardown guidance) over git-mcp tools when appropriate
  • History rewrite — git_rewrite: reword, squash, rewrite-messages, and backup/restore for safe commit-history rewriting
  • Repository analytics — git_analytics: contributors, churn, activity, summary, and file-stats computed from local git history
  • Pull requests — git_pr: create/list/merge PRs/MRs on GitHub, GitLab, Forgejo, Gitea, and Bitbucket via provider CLI or REST API
  • Tangled & Entire awareness — git_tangled_check / git_entire_check detect Tangled hosting and Entire session/context management
  • Multi-repo — pass repo_path per-call or configure a server-level default
  • Worktrees — git_worktree: plain git worktree by path, or branch-addressed worktrees via git flow worktree with path templates and provenance-aware cleanup
  • Cross-platform — macOS, Linux, Windows (Git for Windows), all covered by CI

Quick Start

npx (no install)

bash
npx @selfagency/git-mcp --repo-path /path/to/your/repo

Install globally

bash
npm install -g @selfagency/git-mcpgit-mcp --repo-path /path/to/your/repo

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

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

VS Code (Copilot)

Add to .vscode/mcp.json in your project:

json
{  "servers": {    "git": {      "command": "npx",      "args": ["-y", "@selfagency/git-mcp", "--repo-path", "${workspaceFolder}"]    }  }}

Configuration

All configuration is via environment variables. Pass them in your MCP client config:

VariableDefaultDescription
GIT_REPO_PATH—Default repository path (also: --repo-path CLI arg)
GIT_ALLOW_NO_VERIFYfalseAllow --no-verify on commit/push (bypasses hooks)
GIT_ALLOW_FORCE_PUSHfalseAllow --force on push
GIT_ALLOW_FLOW_HOOKSfalseAllow git_flow hooks and filters to execute
GIT_AUTO_SIGN_COMMITSfalseAutomatically sign every commit
GIT_AUTO_SIGN_TAGSfalseAutomatically sign every tag
GIT_SIGNING_KEY—Default GPG key ID or SSH key path
GIT_SIGNING_FORMAT—Signing format: openpgp, ssh, or x509
GIT_ALLOW_BUTfalseEnable GitButler awareness (git_but_check)
GIT_ALLOW_JJfalseEnable Jujutsu awareness (git_jj_check)
GIT_ALLOW_TANGLEDfalseEnable Tangled awareness (git_tangled_check)
GIT_ALLOW_ENTIREfalseEnable Entire awareness (git_entire_check)
BUT_BINARYbutOverride the but executable path
JJ_BINARYjjOverride the jj executable path
ENTIRE_BINARYentireOverride the entire executable path
GITHUB_TOKEN—GitHub token for git_pr REST fallback
GITLAB_TOKEN—GitLab token for git_pr REST fallback
FORGEJO_TOKEN—Forgejo/Gitea token for git_pr REST fallback
BITBUCKET_TOKEN—Bitbucket token for git_pr REST fallback
GIT_FORGE_PROVIDER—Explicit forge provider for self-hosted instances

Tool Reference

Tools are grouped by domain. Each root tool takes an action parameter that selects the operation. Where an action is marked as default, omitting action will use it.

Context (git_context)

ActionDescription
summary(default) Full repo snapshot: branch, upstream, pending changes, in-progress operations
searchSearch commit history and working tree content
get_configRead a Git config value
set_configWrite a Git config value
aliasesList all configured git aliases

Status (git_status)

ActionDescription
status(default) Working tree and branch status
diffUnstaged, staged, or ref-to-ref diff
diff_mainChanges from branch divergence point vs main (or configurable base branch)

History (git_history)

ActionDescription
log(default) Commit log with filtering, pagination, revision ranges, and pathspecs
showInspect a single commit
blameLine-by-line attribution for a file
reflogFull reflog — the recovery ledger
lgCompact graph log (--oneline --graph --decorate --all)
whoContributor shortlog (supports optional file_path)

Commits (git_commits)

ActionDescription
addStage files or hunks
restoreDiscard working tree changes
unstageRemove files from the staging area
commitCreate a commit with message, signing, and author flags
amendAmend the last commit without editing the message
wipStage all changes and commit with message WIP
revertCreate a revert commit for a given ref
undoSoft-reset the last commit (reset --soft HEAD~1)
resetReset HEAD with configurable mode (soft/mixed/hard)
nukeHard-reset the last commit — requires confirm=true

Branches (git_branches)

ActionDescription
list(default) Local and remote branch listing
createCreate a branch
deleteDelete a branch
renameRename a branch
checkoutSwitch to a branch or ref
set_upstreamSet or update tracking upstream
recentRecent branches sorted by committer date

Remotes (git_remotes)

ActionDescription
list(default) List configured remotes
manageAdd, remove, or rename a remote
fetchFetch from a remote
pullPull (fetch + merge/rebase)
pushPush to a remote; force_with_lease supported

Workspace (git_workspace)

ActionDescription
stashStash and pop/apply/drop/list/show stash entries
stash_allStash tracked and untracked changes in one operation
rebaseStart, continue, abort, or skip a rebase
cherry_pickApply one or more commits; supports continue/abort/skip
mergeMerge branches with full flag control
bisectBinary search for a regression (start, good, bad, reset, log)
tagCreate, list, delete, or push tags; supports GPG/SSH signing
worktreeAdd, list, remove, lock, unlock, prune, or repair linked worktrees
submoduleAdd, update, sync, init, deinit, and list submodules

Git Flow (git_flow)

Drives the git-flow-next CLI, which must be installed and on PATH (brew install git-flow-next, or the releases page). Set GIT_FLOW_BINARY to override the path. When the binary is missing, the tool returns an install hint rather than failing opaquely.

OperationDescription
initInitialize a repository with git-flow branch conventions
overviewShow the current flow state and active branches
configRead or write git-flow configuration values
topicGeneralized topic branch action (start, finish, publish, track)
controlResume or abort an in-progress finish or update

Flags are scoped to the target verb: worktree and worktree_path apply to start and checkout, while keep_worktree and force_worktree apply to finish and delete. A mismatch raises instead of being silently dropped. See the tool reference for the full parameter list.

Worktree (git_worktree)

Two backends. Path-addressed actions drive plain git worktree and need nothing but git; branch-addressed flow_* actions drive git flow worktree, which addresses worktrees by branch name, computes paths from the gitflow.worktreePath template, and tags provenance so cleanup can tell a git-flow-created worktree (removed) from a hand-made one (detached, uncommitted work preserved).

ActionDescription
add, list, remove, lock, unlock, prune, repairPlain git worktree, identified by path
flow_path, flow_add, flow_remove, flow_listgit flow worktree, identified by branch

See the tool reference.

LFS (git_lfs)

ActionDescription
trackAdd a tracking pattern to .gitattributes
untrackRemove a tracking pattern
ls-filesList tracked LFS files
statusShow LFS status
pullPull LFS objects
pushPush LFS objects
installInstall LFS hooks in the repository
migrate-importMigrate existing history to LFS
migrate-exportMigrate LFS history back to plain objects

Documentation (git_docs)

ActionDescription
searchSearch git-scm.com for documentation
manFetch and return a Git man page

History Rewrite (git_rewrite)

ActionDescription
rewordChange one commit's message (HEAD amends in place; arbitrary via filter-branch)
squashCombine the last N commits into one (requires confirm=true)
rewrite-messagesRewrite messages across a range via a SHA→message map (requires confirm=true)
backupCreate a rewrite-backup/<name> branch before rewriting
restoreHard-reset to a backup branch (requires confirm=true)

Analytics (git_analytics)

ActionDescription
contributorsPer-author commits, +/- lines, first/last activity
churnFile hotspots (most commits / most lines changed)
activityCommit frequency per day
summaryBranch/tag counts, total commits, top contributors, oldest/newest commit
file-statsFile-type breakdown, largest files, recently modified

Pull Requests (git_pr)

ActionDescription
createCreate a PR/MR on the detected forge (GitHub, GitLab, Forgejo, Gitea, Bitbucket)
listList PRs/MRs (state filter)
mergeMerge a PR/MR (method: merge/squash/rebase)

Uses the provider CLI (gh/glab/tea) when installed locally, otherwise the REST API with a *_TOKEN env var. Provider auto-detected from the origin remote; self-hosted instances use GIT_FORGE_PROVIDER.

External VCS Awareness

ToolDescription
git_but_checkDetect GitButler but CLI; prefer but mcp/but, run but teardown before git-mcp tools
git_jj_checkDetect Jujutsu jj CLI and .jj/ management; prefer jj CLI for jj-managed repos
git_tangled_checkDetect Tangled hosting; git transport works, PRs via web UI
git_entire_checkDetect Entire CLI and .entire/ management; use entire for session/context queries

Health Check (git_ping)

Returns server status. Useful for confirming the server is reachable.


MCP Resources

URI-addressable read-only snapshots (subscribe-capable):

Resource URIContent
git+repo://status/{repo_path}Working tree status (JSON)
git+repo://log/{repo_path}Recent commit log (JSON)
git+repo://branches/{repo_path}Branch list (JSON)
git+repo://diff/{repo_path}Unstaged + staged diff (JSON)

Bundled Agent Skill

git-mcp ships a bundled agent skill at skills/git-mcp-workflow/ that teaches any skills-npm-compatible agent to use the MCP tool surface instead of running raw git CLI commands. The skill covers:

  • Why LLMs must not use the Git CLI (quoting hazards, silent failures)
  • Inspect-before-mutate workflow rules
  • Safety order for undo and recovery operations
  • Full registered tool surface with action reference
  • Workflow playbooks: feature branch, rebase, recovery, worktree, backport, release tagging, Git Flow, merge
  • Git concept explanations anchored to MCP tools

Installing the skill

If your agent supports skills-npm:

bash
npm install @selfagency/git-mcp   # or pnpm/yarnnpx skills-npm

Or add to your project's package.json so it runs automatically:

json
{  "scripts": {    "prepare": "skills-npm"  }}

Then add to .gitignore:

txt
skills/npm-*

Safety

  • All mutating tools have destructiveHint: true in their MCP annotations
  • git_commits action=reset mode=hard requires confirm=true
  • git_commits action=nuke requires confirm=true
  • Force push (--force) is disabled unless GIT_ALLOW_FORCE_PUSH=true; force_with_lease is always available
  • Hook bypass (--no-verify) is disabled unless GIT_ALLOW_NO_VERIFY=true
  • git_flow hook and filter execution is disabled unless GIT_ALLOW_FLOW_HOOKS=true
  • Paths are validated against the repository root — traversal attempts are rejected
  • Credentials and tokens are never included in responses

Development

bash
# Clone and installgit clone https://github.com/selfagency/git-mcp.gitcd git-mcppnpm install
# Run in development mode (hot reload)pnpm dev
# Buildpnpm build
# Run testspnpm test
# Type checkpnpm typecheck
# Lintpnpm lint
# Docs (dev server)pnpm docs:dev
# Docs (build)pnpm docs:build

License

MIT © Daniel Sieradski

来源:README.md,提交 e96db03

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.4.2最新Oct 14, 2026

评分

已满足适用检查项的 40%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

    请在仓库或注册中心条目中声明许可证。