cyanheads/git-mcp-server

Repository files navigation

TypeScriptModel Context ProtocolVersionLicenseStatusGitHub

Empower your AI agents with comprehensive, secure, and programmatic control over Git repositories!

An MCP (Model Context Protocol) server providing a robust, LLM-friendly interface to the standard git command-line tool. Enables LLMs and AI agents to perform a wide range of Git operations like clone, commit, push, pull, branch, diff, log, status, and more via the MCP standard.

Built on the cyanheads/mcp-ts-template, this server follows a modular architecture with robust error handling, logging, and security features.

This server equips your AI with a comprehensive suite of tools to interact with Git repositories:

Tool CategoryDescriptionKey Features -
Repository & StagingManage repository state, from initialization to staging changes.- git_init: Initialize a new repository.
- git_clone: Clone remote repositories.
- git_add: Stage changes for commit.
- git_status: Check the status of the working directory.
- git_clean: Remove untracked files (requires force flag). -
Committing & HistoryCreate commits, inspect history, and view changes over time.- git_commit: Create new commits with conventional messages.
- git_log: View commit history with filtering options.
- git_diff: Show changes between commits, branches, or the working tree.
- git_show: Inspect Git objects like commits and tags. -
Branching & MergingManage branches, merge changes, and rebase commits.- git_branch: List, create, delete, and rename branches.
- git_checkout: Switch between branches or commits.
- git_merge: Merge branches together.
- git_rebase: Re-apply commits on top of another base.
- git_cherry_pick: Apply specific commits from other branches. -
Remote OperationsInteract with remote repositories.- git_remote: Manage remote repository connections.
- git_fetch: Download objects and refs from a remote.
- git_pull: Fetch and integrate with another repository.
- git_push: Update remote refs with local changes. -
Advanced WorkflowsSupport for more complex Git workflows and repository management.- git_tag: Create, list, or delete tags.
- git_stash: Temporarily store modified files.
- git_worktree: Manage multiple working trees attached to a single repository.
- git_set_working_dir: Set a persistent working directory for a session.
- git_wrapup_instructions: Get a standard workflow for finalizing changes. -

| Overview | Features | Installation | | Configuration | Project Structure | | Tools | Resources | Development | License |

The Git MCP Server acts as a bridge, allowing applications (MCP Clients) that understand the Model Context Protocol (MCP) – like advanced AI coding assistants (LLMs), IDE extensions, or custom research tools – to interact directly and safely with local Git repositories.

Instead of complex scripting or manual command-line interaction, your tools can leverage this server to:

  • Automate Git workflows: Clone repositories, create branches, stage changes, commit work, push updates, and manage tags programmatically.
  • Gain repository insights: Check status, view logs, diff changes, and inspect Git objects without leaving the host application.
  • Integrate Git into AI-driven development: Enable LLMs to manage version control as part of their coding or refactoring tasks, ensuring code integrity and history.
  • Support CI/CD and DevOps automation: Build custom scripts and tools that orchestrate complex Git operations for automated builds, testing, and deployments.

Built on the robust mcp-ts-template, this server provides a standardized, secure, and efficient way to expose Git functionality via the MCP standard. It achieves this by securely executing the standard git command-line tool installed on the system using Node.js's child_process module, ensuring compatibility and leveraging the full power of Git.

Developer Note: This repository includes a .clinerules file that serves as a developer cheat sheet for your LLM coding agent with quick reference for the codebase patterns, file locations, and code snippets.

Leverages the robust utilities provided by the mcp-ts-template:

  • Logging: Structured, configurable logging (file rotation, stdout JSON, MCP notifications) with sensitive data redaction.
  • Error Handling: Centralized error processing, standardized error types (McpError), and automatic logging.
  • Configuration: Environment variable loading (dotenv) with comprehensive validation.
  • Input Validation/Sanitization: Uses zod for schema validation and custom sanitization logic (crucial for paths).
  • Request Context: Tracking and correlation of operations via unique request IDs using AsyncLocalStorage.
  • Type Safety: Strong typing enforced by TypeScript and Zod schemas.
  • HTTP Transport: High-performance HTTP server using Hono, featuring session management, CORS, and authentication support.
  • Deployment: Multi-stage Dockerfile for creating small, secure production images with native dependency support.
  • Direct Git CLI Execution: Interacts with Git by securely executing the standard git command-line tool via Node.js child_process, ensuring full compatibility and access to Git's features.
  • Comprehensive Command Coverage: Exposes a wide range of Git commands as MCP tools (see Tools section).
  • Repository Interaction: Supports status checking, branching, staging, committing, fetching, pulling, pushing, diffing, logging, resetting, tagging, and more.
  • Working Directory Management: Allows setting and clearing a session-specific working directory for context persistence across multiple Git operations.
  • Safety Features: Includes checks and requires explicit confirmation for potentially destructive operations like git clean and git reset --hard.
  • Commit Signing: Supports GPG or SSH signing for verified commits, controlled via the GIT_SIGN_COMMITS environment variable and server-side Git configuration. Includes an optional tool parameter to fall back to unsigned commits on signing failure.

Add the following to your MCP client's configuration file (e.g., cline_mcp_settings.json). This configuration uses npx to run the server, which will automatically install the package if not already present:

{
  "mcpServers": {
    "git-mcp-server": {
      "command": "npx",
      "args": ["@cyanheads/git-mcp-server"],
      "env": {
        "MCP_LOG_LEVEL": "info",
        "GIT_SIGN_COMMITS": "false"
      }
    }
  }
}
npm install @cyanheads/git-mcp-server
  1. Clone the repository:

    git clone https://.com/cyanheads/git-mcp-server.git
    cd git-mcp-server
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build
    # or npm run rebuild

Configure the server using environment variables. These environmental variables are set within your MCP client config/settings (e.g. claude_desktop_config.json for Claude Desktop)

VariableDescriptionDefault
MCP_TRANSPORT_TYPETransport mechanism: stdio or http.stdio
MCP_HTTP_PORTPort for the HTTP server (if MCP_TRANSPORT_TYPE=http). Retries next ports if busy.3010
MCP_HTTP_HOSTHost address for the HTTP server (if MCP_TRANSPORT_TYPE=http).127.0.0.1
MCP_ALLOWED_ORIGINSComma-separated list of allowed origins for CORS (if MCP_TRANSPORT_TYPE=http).(none)
MCP_LOG_LEVELLogging level (debug, info, notice, warning, error, crit, alert, emerg). Inherited from template.info
GIT_SIGN_COMMITSSet to "true" to enable signing attempts for commits made by the git_commit tool. Requires server-side Git/key setup (see below).false
MCP_AUTH_MODEAuthentication mode: jwt, oauth, or none.none
MCP_AUTH_SECRET_KEYSecret key for JWT validation (if MCP_AUTH_MODE=jwt).''
OAUTH_ISSUER_URLOIDC issuer URL for OAuth validation (if MCP_AUTH_MODE=oauth).''
OAUTH_AUDIENCEAudience claim for OAuth validation (if MCP_AUTH_MODE=oauth).''

The codebase follows a modular structure within the src/ directory:

src/
β”œβ”€β”€ index.ts           # Entry point: Initializes and starts the server
β”œβ”€β”€ config/            # Configuration loading (env vars, package info)
β”‚   └── index.ts
β”œβ”€β”€ mcp-server/        # Core MCP server logic and capability registration
β”‚   β”œβ”€β”€ server.ts      # Server setup, capability registration
β”‚   β”œβ”€β”€ transports/    # Transport handling (stdio, http)
β”‚   β”œβ”€β”€ resources/     # MCP Resource implementations (currently none)
β”‚   └── tools/         # MCP Tool implementations (subdirs per tool)
β”œβ”€β”€ types-global/      # Shared TypeScript type definitions
└── utils/             # Common utility functions (logger, error handler, etc.)

For a detailed file tree, run npm run tree or see docs/tree.md.

The Git MCP Server provides a suite of tools for interacting with Git repositories, callable via the Model Context Protocol.

Tool NameDescriptionKey Arguments
git_addStages specified files or patterns.path?, files?
git_branchManages branches (list, create, delete, rename, show current).path?, mode, branchName?, newBranchName?, startPoint?, force?, all?, remote?
git_checkoutSwitches branches or restores working tree files.path?, branchOrPath, newBranch?, force?
git_cherry_pickApplies changes introduced by existing commits.path?, commitRef, mainline?, strategy?, noCommit?, signoff?
git_cleanRemoves untracked files. Requires force: true.path?, force, dryRun?, directories?, ignored?
git_clear_working_dirClears the session-specific working directory.(none)
git_cloneClones a repository into a specified absolute path.repositoryUrl, targetPath, branch?, depth?, quiet?
git_commitCommits staged changes. Supports author override, signing control.path?, message, author?, allowEmpty?, amend?, forceUnsignedOnFailure?
git_diffShows changes between commits, working tree, etc.path?, commit1?, commit2?, staged?, file?, includeUntracked?
git_fetchDownloads objects and refs from other repositories.path?, remote?, prune?, tags?, all?
git_initInitializes a new Git repository at the specified absolute path. Defaults to 'main' for initial branch.path, initialBranch?, bare?, quiet?
git_logShows commit logs.path?, maxCount?, author?, since?, until?, branchOrFile?
git_mergeMerges the specified branch into the current branch.path?, branch, commitMessage?, noFf?, squash?, abort?
git_pullFetches from and integrates with another repository or local branch.path?, remote?, branch?, rebase?, ffOnly?
git_pushUpdates remote refs using local refs.path?, remote?, branch?, remoteBranch?, force?, forceWithLease?, setUpstream?, tags?, delete?
git_rebaseReapplies commits on top of another base tip.path?, mode?, upstream?, branch?, interactive?, strategy?, strategyOption?, onto?
git_remoteManages remote repositories (list, add, remove, show).path?, mode, name?, url?
git_resetResets current HEAD to a specified state. Supports soft, mixed, hard modes. USE 'hard' WITH CAUTION.path?, mode?, commit?
git_set_working_dirSets the default working directory. Can optionally initialize repo if not present. Requires absolute path.path, validateGitRepo?, initializeIfNotPresent?
git_showShows information about Git objects (commits, tags, etc.).path?, ref, filePath?
git_stashManages stashed changes (list, apply, pop, drop, save).path?, mode, stashRef?, message?
git_statusGets repository status (branch, staged, modified, untracked files).path?
git_tagManages tags (list, create annotated/lightweight, delete).path?, mode, tagName?, message?, commitRef?, annotate?
git_worktreeManages Git worktrees (list, add, remove, move, prune).path?, mode, worktreePath?, commitish?, newBranch?, force?, detach?, newPath?, verbose?, dryRun?, expire?
git_wrapup_instructionsProvides a standard Git wrap-up workflow.acknowledgement, updateAgentMetaFiles?

Note: The path parameter for most tools defaults to the session's working directory if set via git_set_working_dir.

MCP Resources are not implemented in this version (v2.1.4).

This version focuses on the refactored Git tools implementation based on the latest mcp-ts-template and MCP SDK v1.13.0. Resource capabilities, previously available, have been temporarily removed during this major update.

If you require MCP Resource access (e.g., for reading file content directly via the server), please use the stable v1.2.4 release.

Future development may reintroduce resource capabilities in a subsequent release.

# Build the project (compile TS to JS in dist/ and make executable)
npm run build

# Test the server locally using the MCP inspector tool (stdio transport)
npm run inspector

# Test the server locally using the MCP inspector tool (http transport)
npm run inspector:http

# Clean build artifacts
npm run clean

# Generate a file tree representation for documentation
npm run tree

# Clean build artifacts and then rebuild the project
npm run rebuild

# Format code with Prettier
npm run format

# Start the server using stdio (default)
npm start
# Or explicitly:
npm run start:stdio

# Start the server using HTTP transport
npm run start:http

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


Built with the Model Context Protocol

About

An MCP (Model Context Protocol) server enabling LLMs and AI agents to interact with Git repositories. Provides tools for comprehensive Git operations including clone, commit, branch, diff, log, status, push, pull, merge, rebase, worktree, tag management, and more, via the MCP standard. STDIO & HTTP.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published