Python package for Git operations via MCP (Model Context Protocol) HTTP API. Provides both sync and async clients for mcp-git-proxy.
- Repository Sync - Clone or sync from local path/URL
- Commit Operations - Create commits with multiple file changes
- Test Runner - Execute tests in repository context
- Push/Pull - Remote operations
- Local Operations (NEW) - Work without commits:
- Worktree read/write/diff
- Patch apply/check
- Staging (git add)
- Stash save/pop
- Draft branches
- Checkpoints (tarball snapshots)
- Git reset (hard/soft/mixed)
- Fragment Transfer - Export repository as fragments for MCP skills
pip install -e .from git2mcp import Git2MCPClient
async with Git2MCPClient("http://localhost:8081") as client:
# Sync from local path
result = await client.sync_repo(
repo_id="team/project",
source_path="/path/to/source",
branch="main"
)
print(f"Synced to: {result['path']}")await client.commit(
repo_id="team/project",
message="feat: add new feature",
changes=[
{"path": "main.py", "content": "print('hello')", "mode": "update"}
]
)# Write file directly to worktree
await client.worktree_write(
repo_id="team/project",
path="notes/todo.txt",
content="- Fix bug"
)
# Apply patch
patch = """diff --git a/main.py b/main.py
--- a/main.py
+++ b/main.py
@@ -1 +1 @@
-print("old")
+print("new")
"""
await client.patch_apply(repo_id="team/project", patch=patch)
# Create checkpoint before changes
ckpt = await client.checkpoint_create(repo_id="team/project", label="before-refactor")
# If something goes wrong, restore checkpoint
await client.checkpoint_restore(repo_id="team/project", checkpoint_id=ckpt["checkpoint_id"])list_repos()- List all managed repositoriessync_repo(repo_id, source_path=None, repo_url=None, branch="main")- Sync repositoryexport_package(repo_id, ref="HEAD")- Export as tar.gzexport_fragments(repo_id, ref="HEAD", max_fragment_bytes=200000)- Export as fragments
commit(repo_id, message, changes=[], author_name="bot", author_email="bot@local")- Create commitpush(repo_id, remote="origin", branch=None)- Push to remotereset(repo_id, ref="HEAD~1", mode="hard")- Reset repository
worktree_read(repo_id, path)- Read file from worktreeworktree_write(repo_id, path, content)- Write file to worktreeworktree_diff(repo_id, staged=False)- Get diffpatch_apply(repo_id, patch, check_only=False)- Apply unified diffstage(repo_id, paths=None)- Stage files (git add)stash_save(repo_id, message="stash")- Save stashstash_pop(repo_id)- Pop stashbranch_draft(repo_id, name, base=None)- Create draft branchcheckpoint_create(repo_id, label=None)- Create checkpointcheckpoint_restore(repo_id, checkpoint_id)- Restore checkpoint
run_tests(repo_id, command="python3 -m compileall -q .")- Run tests
See examples/ directory:
- 01_sync_and_commit.py - Basic sync and commit
- 02_fragment_sync_to_skills.py - Fragment transfer to MCP skills
- 03_agent_git2mcp.py - Full LLM agent workflow
- 04_dry_run_vs_execute.py - Dry-run vs execute with auto-revert
- 05_local_iterate.py - Local iteration without commits
git2mcp (client) → HTTP → mcp-git-proxy (Docker)
↓
git-repo-storage (volume)
pytest tests/test_git2mcp.py -vLicensed under Apache-2.0.