Labsco
cyanheads logo

Git MCP Server

β˜… 226

from cyanheads

An MCP server that allows AI agents to interact with Git repositories, supporting a wide range of operations like clone, commit, branch, and push.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeQuick setup

@cyanheads/git-mcp-server

A Git MCP server for AI agents. STDIO & Streamable HTTP.

28 Tools Β· 1 Resource Β· 1 Prompt

Tools

28 git operations organized into seven categories:

Category Tools Description Repository Management git_init, git_clone, git_status, git_clean Initialize repos, clone from remotes, check status, clean untracked files Staging & Commits git_add, git_commit, git_diff Stage changes, create commits, compare changes History & Inspection git_log, git_show, git_blame, git_reflog View commit history, inspect objects, trace authorship, view ref logs Analysis git_changelog_analyze Gather git context and instructions for LLM-driven changelog analysis Branching & Merging git_branch, git_checkout, git_merge, git_rebase, git_cherry_pick Manage branches, switch contexts, integrate changes, apply specific commits Remote Operations git_remote, git_fetch, git_pull, git_push Configure remotes, fetch updates, synchronize repositories, publish changes Advanced Workflows git_tag, git_stash, git_reset, git_worktree, git_set_working_dir, git_clear_working_dir, git_wrapup_instructions Tag releases (list/create/delete/verify), stash changes, reset state, manage worktrees, set/clear session directory

Resources

Resource URI Description Git Working Directory git://working-directory The current session working directory, set via git_set_working_dir.

Prompts

Prompt Description Parameters Git Wrap-up Workflow protocol for completing git sessions: review, document, commit, and tag changes. changelogPath, createTag.

Features

Built on mcp-ts-template.

Feature Details Declarative tools Define capabilities in single, self-contained files. The framework handles registration, validation, and execution. Error handling Unified McpError system for consistent, structured error responses. Authentication Supports none, jwt, and oauth modes. Pluggable storage Swap backends (in-memory, filesystem, Supabase, Cloudflare KV/R2) without changing business logic. Observability Structured logging (Pino) and optional auto-instrumented OpenTelemetry for traces and metrics. Dependency injection Built with tsyringe for decoupled, testable architecture. Cross-runtime Auto-detects Bun or Node.js and uses the appropriate process spawning method. Provider architecture Pluggable git provider system. Current: CLI. Planned: isomorphic-git for edge deployment. Working directory management Session-specific directory context for multi-repo workflows. Configurable git identity Override author/committer info via environment variables, with fallback to global git config. Commit signing GPG/SSH signing (enabled by default) for commits, merges, rebases, cherry-picks, and tags. Silent fallback to unsigned on failure with signed/signingWarning fields in responses. Safety Destructive operations (git clean, git reset --hard) require explicit confirmation flags.

Security

  • All file paths are validated and sanitized to prevent directory traversal.

  • Optional GIT_BASE_DIR restricts operations to a specific directory tree for multi-tenant sandboxing.

  • Git commands use validated arguments via process spawning β€” no shell interpolation.

  • JWT and OAuth support for authenticated deployments.

  • Optional rate limiting via the DI-managed RateLimiter service.

  • All operations are logged with request context for auditing.

Project structure

Directory Purpose src/mcp-server/tools Tool definitions (*.tool.ts). Git capabilities live here. src/mcp-server/resources Resource definitions (*.resource.ts). Git context data sources. src/mcp-server/transports HTTP and STDIO transport implementations, including auth. src/storage StorageService abstraction and provider implementations. src/services Git service provider (CLI-based git operations). src/container DI container registrations and tokens. src/utils Logging, error handling, performance, security utilities. src/config Environment variable parsing and validation (Zod). tests/ Unit and integration tests, mirroring src/ structure.

Response format

Configure output format and verbosity via MCP_RESPONSE_FORMAT and MCP_RESPONSE_VERBOSITY.

JSON format (default, optimized for LLM consumption):

Copy & paste β€” that's it
{
 "success": true,
 "branch": "main",
 "staged": ["src/index.ts", "README.md"],
 "unstaged": ["package.json"],
 "untracked": []
}

Markdown format (human-readable):

Copy & paste β€” that's it
# Git Status: main

## Staged (2)

- src/index.ts
- README.md

## Unstaged (1)

- package.json

The LLM always receives the complete structured data via responseFormatter β€” full file lists, metadata, timestamps β€” regardless of what the client displays. Verbosity controls how much detail is included: minimal (core fields only), standard (balanced), or full (everything).

Development guide

See AGENTS.md for architecture, tool development patterns, and contribution rules.

Testing

Tests use Bun's test runner with Vitest compatibility.

Copy & paste β€” that's it
bun test # Run all tests
bun test --coverage # With coverage
bun run devcheck # Lint, format, typecheck, audit

Roadmap

The server uses a provider-based architecture for git operations:

  • CLI provider (current) β€” Full 28-tool coverage via native git CLI. Requires local git installation.

  • Isomorphic git provider (planned) β€” Pure JS implementation for edge deployment (Cloudflare Workers, Vercel Edge, Deno Deploy). Uses isomorphic-git.

  • GitHub API provider (maybe) β€” Cloud-native operations via GitHub REST/GraphQL APIs, no local repo required.

Contributing

Issues and pull requests are welcome. Run checks before submitting:

Copy & paste β€” that's it
npm run devcheck
npm test

License

Apache 2.0. See LICENSE.

Built with the mcp-ts-template

Sponsor this project Β· Buy me a coffee