The Git MCP Server enables programmatic interaction with Git repositories for AI agents, IDE extensions, and other MCP-compatible applications.
Capabilities include:
Repository Operations: Initialize, clone, and check repository status
Version Control: Stage files, commit changes, push/pull from remotes
Branch Management: Create, list, delete, and switch branches
Tag Handling: Create, list, and delete tags (including signed/annotated tags)
Remote Management: Add, remove, and list remote repositories
Stash Operations: Save, apply, pop, and remove stashed changes
Advanced Operations: Merge branches, rebase commits, reset HEAD, show diffs
Bulk Actions: Execute multiple Git operations in sequence
Safety Features: Includes safeguards for destructive operations
Note: Most operations require absolute paths for precise repository and file targeting.
Provides comprehensive Git operations including repository initialization, cloning, file staging, committing, branch management, tag operations, remote repository handling, and stash management, enabling LLMs to interact with Git repositories.
Supports interactions with GitHub repositories through Git operations like cloning from GitHub URLs, pushing to and pulling from GitHub remotes, enabling LLMs to manage code on GitHub.
🛠️ Tools Overview
This server provides 27 comprehensive Git operations organized into six functional categories:
Category | Tools | Description |
Repository Management |
,
,
,
| Initialize repos, clone from remotes, check status, and clean untracked files |
Staging & Commits |
,
,
| Stage changes, create commits, and compare changes |
History & Inspection |
,
,
,
| View commit history, inspect objects, trace line-by-line authorship, and view ref logs |
Branching & Merging |
,
,
,
,
| Manage branches, switch contexts, integrate changes, and apply specific commits |
Remote Operations |
,
,
,
| Configure remotes, download updates, synchronize repositories, and publish changes |
Advanced Workflows |
,
,
,
,
,
,
| Tag releases, stash changes, reset state, manage worktrees, set/clear session directory, and access workflow guidance |
Related MCP server: GitHub MCP Server
📦 Resources Overview
The server provides resources that offer contextual information about the Git environment:
Resource | URI | Description |
Git Working Directory |
| Provides the current session working directory for git operations. This is the directory set via
and used as the default. |
🎯 Prompts Overview
The server provides structured prompt templates that guide AI agents through complex workflows:
Prompt | Description | Parameters |
Git Wrap-up | A systematic workflow protocol for completing git sessions. Guides agents through reviewing, documenting, committing, and tagging changes. |
,
,
, and
. |
🚀 Getting Started
Runtime Compatibility
This server works with both Bun and Node.js runtimes:
Runtime | Command | Minimum Version | Notes |
Node.js |
| ≥ 20.0.0 | Universal compatibility |
Bun |
| ≥ 1.2.0 | Alternative runtime option |
The server automatically detects the runtime and uses the appropriate process spawning method for git operations.
MCP Client Settings/Configuration
Add the following to your MCP Client configuration file (e.g., cline_mcp_settings.json). Clients have different ways to configure servers, so refer to your client's documentation for specifics.
Be sure to update environment variables as needed (especially your Git information!)
Using npx (Node.js)
Using bunx (Bun)
Streamable HTTP Configuration
✨ Server Features
This server is built on the mcp-ts-template and inherits its rich feature set:
Declarative Tools: Define agent capabilities in single, self-contained files. The framework handles registration, validation, and execution.
Robust Error Handling: A unified
McpErrorsystem ensures consistent, structured error responses.Pluggable Authentication: Secure your server with zero-fuss support for
none,jwt, oroauthmodes.Abstracted Storage: Swap storage backends (
in-memory,filesystem,Supabase,Cloudflare KV/R2) without changing business logic.Full-Stack Observability: Deep insights with structured logging (Pino) and optional, auto-instrumented OpenTelemetry for traces and metrics.
Dependency Injection: Built with
tsyringefor a clean, decoupled, and testable architecture.Edge-Ready Architecture: Built on an edge-compatible framework that runs seamlessly on local machines or Cloudflare Workers. Note: Current git operations use the CLI provider which requires local git installation. Edge deployment support is planned through the isomorphic-git provider integration.
Plus, specialized features for Git integration:
Cross-Runtime Compatibility: Works seamlessly with both Bun and Node.js runtimes. Automatically detects the runtime and uses optimal process spawning (Bun.spawn in Bun, child_process.spawn in Node.js).
Provider-Based Architecture: Pluggable git provider system with current CLI implementation and planned isomorphic-git provider for edge deployment.
Optimized Git Execution: Direct git CLI interaction with cross-runtime support for high-performance process management, streaming I/O, and timeout handling (current CLI provider).
Comprehensive Coverage: 27 tools covering all essential Git operations from init to push.
Working Directory Management: Session-specific directory context for multi-repo workflows.
Configurable Git Identity: Override author/committer information via environment variables with automatic fallback to global git config.
Safety Features: Explicit confirmations for destructive operations like
git cleanandgit reset --hard.Commit Signing: Optional GPG/SSH signing support for all commit-creating operations (commits, merges, rebases, cherry-picks, and tags).
Development Environment Setup
Prerequisites
Node.js v20.0.0+ (or Bun v1.2.0+ as an alternative)
Git installed and accessible in your system PATH
Installation
Clone the repository:
Navigate into the directory:
Install dependencies:
⚙️ Configuration
All configuration is centralized and validated at startup in src/config/index.ts. Key environment variables in your .env file include:
Variable | Description | Default |
| The transport to use:
or
. |
|
| Session mode for HTTP transport:
,
, or
. |
|
| Response format:
(LLM-optimized),
(human-readable), or
. |
|
| Response detail level:
,
, or
. |
|
| The port for the HTTP server. |
|
| The hostname for the HTTP server. |
|
| The endpoint path for MCP requests. |
|
| Authentication mode:
,
, or
. |
|
| Storage backend:
,
,
,
,
. |
|
| Set to
to enable OpenTelemetry. |
|
| The minimum level for logging (
,
,
,
). |
|
| Set to
to enable GPG/SSH signing for all commits, merges, rebases, cherry-picks, and tags. Requires GPG/SSH configuration. |
|
| Git author name. Aliases:
,
. Falls back to global git config if not set. |
|
| Git author email. Aliases:
,
. Falls back to global git config if not set. |
|
| Optional absolute path to restrict all git operations to a specific directory tree. Provides security sandboxing for multi-tenant or shared environments. |
|
| Optional path to custom markdown file with Git workflow instructions. |
|
| Required for A 32+ character secret key. |
|
| Required for URL of the OIDC provider. |
|
▶️ Running the Server
For End Users (via Package Manager)
The easiest way to use the server is via npx (no installation required):
Configured through environment variables or your MCP client configuration. Bun users can alternatively use bunx @cyanheads/git-mcp-server@latest.
Local Development
Build and run the production version:
# One-time build npm run rebuild # Run the built server npm run start:http # or npm run start:stdioDevelopment mode with hot reload:
npm run dev:http # or npm run dev:stdioRun checks and tests:
npm run devcheck # Lints, formats, type-checks, and more npm test # Runs the test suite
Cloudflare Workers
Build the Worker bundle:
Run locally with Wrangler:
Deploy to Cloudflare:
📂 Project Structure
Directory | Purpose & Contents |
| Your tool definitions (
). This is where Git capabilities are defined. |
| Your resource definitions (
). Provides Git context data sources. |
| Implementations for HTTP and STDIO transports, including auth middleware. |
|
abstraction and all storage provider implementations. |
| Integrations with external services (LLMs, Speech, etc.). |
| Dependency injection container registrations and tokens. |
| Core utilities for logging, error handling, performance, and security. |
| Environment variable parsing and validation with Zod. |
| Unit and integration tests, mirroring the
directory structure. |
📤 Understanding Tool Responses
This server follows MCP's dual-output architecture for all tools (MCP Tools Specification):
Response Format Options
Configure response format and verbosity via environment variables (see Configuration):
Variable | Values | Description |
|
(default),
,
| Output format: JSON for LLM parsing, Markdown for human UIs |
|
,
(default),
| Detail level: minimal (core only), standard (balanced), full (everything) |
What Users See (Human-Readable)
When you invoke a tool through your MCP client, you see a formatted summary designed for human consumption. For example, git_status might show:
Markdown Format:
JSON Format (LLM-Optimized):
What the LLM Sees (Complete Structured Data)
Behind the scenes, the LLM receives complete structured data as content blocks via the responseFormatter function. This includes:
All metadata (commit hashes, timestamps, authors)
Full file lists and change details (never truncated - LLMs need complete context)
Structured JSON or formatted markdown based on configuration
Everything needed to answer follow-up questions
Why This Matters: The LLM can answer detailed questions like "Who made the last commit?" or "What files changed in commit abc123?" because it has access to the full dataset, even if you only saw a summary.
Verbosity Levels: Control the amount of detail returned:
Minimal: Core data only (success status, primary identifiers)
Standard: Balanced output with essential context (recommended)
Full: Complete data including all metadata and statistics
For Developers: When creating custom tools, always include complete data in your responseFormatter. Balance human-readable summaries with comprehensive structured information. See AGENTS.md for response formatter best practices and the MCP specification for technical details.
🧑💻 Agent Development Guide
For strict rules when using this server with an AI agent, refer to the AGENTS.md file in this repository. Key principles include:
Logic Throws, Handlers Catch: Never use
try/catchin your toollogic. Throw anMcpErrorinstead.Pass the Context: Always pass the
RequestContextobject through your call stack for logging and tracing.Use the Barrel Exports: Register new tools and resources only in the
index.tsbarrel files within their respectivedefinitionsdirectories.Declarative Tool Pattern: Each tool is defined in a single
*.tool.tsfile with schema, logic, and response formatting.
🔒 Security Features
Path Sanitization: All file paths are validated and sanitized to prevent directory traversal attacks.
Base Directory Restriction: Optional
GIT_BASE_DIRconfiguration to restrict all git operations to a specific directory tree, providing security sandboxing for multi-tenant or shared hosting environments.Command Injection Prevention: Git commands are executed with carefully validated arguments via Bun.spawn.
Destructive Operation Protection: Dangerous operations require explicit confirmation flags.
Authentication Support: Built-in JWT and OAuth support for secure deployments.
Rate Limiting: Optional rate limiting via the DI-managed
RateLimiterservice.Audit Logging: All Git operations are logged with full context for security auditing.
🧪 Testing
This server uses Vitest for testing.
Run all tests:
npm testRun tests with coverage:
npm run test:coverageRun tests in watch mode:
npm test -- --watch
🗺️ Roadmap
Planned Git Provider Integrations
The server uses a provider-based architecture to support multiple git implementation backends:
✅ CLI Provider (Current): Full-featured git operations via native git CLI
Complete coverage of all 27 git tools
Executes git commands using Bun.spawn for optimal performance
Streaming I/O handling for large outputs (10MB buffer limit)
Configurable timeouts (60s default) and automatic process cleanup
Requires local git installation
Best for local development and server deployments
🚧 Isomorphic Git Provider (Planned): Pure JavaScript git implementation
Edge deployment compatibility (Cloudflare Workers, Vercel Edge, Deno Deploy)
No system dependencies required
Enables true serverless git operations
Core operations: clone, status, add, commit, push, pull, branch, checkout
Implementation: isomorphic-git
💡 GitHub API Provider (Maybe): Cloud-native git operations via GitHub REST/GraphQL APIs
No local repository required
Direct integration with GitHub-hosted repositories
Ideal for GitHub-centric workflows
The provider system allows seamless switching between implementations based on deployment environment and requirements. See AGENTS.md for architectural details.
🤝 Contributing
Issues and pull requests are welcome! If you plan to contribute, please run the local checks and tests before submitting your PR.
Development Workflow
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Make your changes following the existing patterns
Run
npm run devcheckto ensure code qualityRun
npm testto verify all tests passCommit your changes with conventional commits
Push to your fork and open a Pull Request
📜 License
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.