Git MCP server

Integrates with Git repositories to enable version control operations and automation, supporting both shell-based commands and the go-git library for flexible implementation.
Back to servers
Setup instructions
Provider
/servers/geropl-git
Release date
Feb 28, 2025
Language
Go
Stats
20 stars

Git MCP Server is a powerful tool that provides an interface between Large Language Models and Git repositories through the Model Context Protocol (MCP). It allows AI assistants to interact with Git repositories, performing operations like viewing status, making commits, and managing branches.

Installation

Prerequisites

  • Go 1.18 or higher
  • Git installed on your system

Download Prebuilt Binaries

You can download prebuilt binaries for your platform from the GitHub Releases page.

Building from Source

# Clone the repository
git clone https://github.com/geropl/git-mcp-go.git
cd git-mcp-go

# Build the server
go build -o git-mcp-go .

Install with go install

go install github.com/geropl/git-mcp-go@latest

Usage

Command Line Structure

The Git MCP Server uses a command-line structure with subcommands:

git-mcp-go
├── serve [flags] [repository-paths...]
│   ├── --repository, -r <paths>                  # Repository paths (multiple ways to specify)
│   ├── --mode <shell|go-git>
│   ├── --write-access
│   └── --verbose, -v
└── setup [flags] [repository-paths...]
    ├── --repository, -r <paths>                  # Repository paths (multiple ways to specify)
    ├── --mode <shell|go-git>
    ├── --write-access
    ├── --auto-approve <tool-list|allow-read-only|allow-local-only>
    └── --tool <cline,roo-code>

Multi-Repository Support

The Git MCP Server can monitor and operate on multiple repositories simultaneously. You can specify repositories in several ways:

  1. Using the -r/--repository flag:
    • With comma-separated paths: -r=/path/to/repo1,/path/to/repo2
    • With multiple flag instances: -r=/path/to/repo1 -r=/path/to/repo2
  2. As positional arguments: serve /path/to/repo1 /path/to/repo2
  3. A combination of both approaches

When using multiple repositories, the server will default to the first repository for operations where a specific repository is not specified.

Starting the Server

The serve command starts the Git MCP server:

# Run with verbose logging
./git-mcp-go serve -v /path/to/repo1 /path/to/repo2 /path/to/repo3

# Run with go-git implementation
./git-mcp-go serve --mode go-git -r=/path/to/repo1,/path/to/repo2

# Enable write access for remote operations
./git-mcp-go serve -r=/path/to/repo1,/path/to/repo2 --write-access

The --mode flag allows you to choose between two different implementations:

  • shell: Uses the Git CLI commands via shell execution (default)
  • go-git: Uses the go-git library for Git operations where possible

The --write-access flag enables operations that modify remote state (currently only the push operation).

Setting Up with AI Assistants

The setup command configures the Git MCP server for use with an AI assistant:

# Set up for Cline with a single repository
./git-mcp-go setup -r /path/to/git/repository

# Set up with multiple repositories
./git-mcp-go setup /path/to/repo1 /path/to/repo2 /path/to/repo3

# Set up with write access enabled
./git-mcp-go setup -r=/path/to/repo1,/path/to/repo2 --write-access

# Set up with auto-approval for read-only tools
./git-mcp-go setup -r=/path/to/repo1,/path/to/repo2 --auto-approve=allow-read-only

The --auto-approve flag specifies which tools should be auto-approved:

  • allow-read-only: Auto-approve all read-only tools (git_status, git_diff_unstaged, etc.)
  • allow-local-only: Auto-approve all local-only tools (including git_commit, git_add, git_reset)
  • comma-separated list: Auto-approve specific tools (e.g., git_status,git_log)

Available Git Operations

The server provides the following Git operations as tools:

  • git_status: Shows the working tree status
  • git_diff_unstaged: Shows changes in the working directory that are not yet staged
  • git_diff_staged: Shows changes that are staged for commit
  • git_diff: Shows differences between branches or commits
  • git_commit: Records changes to the repository
  • git_add: Adds file contents to the staging area
  • git_reset: Unstages all staged changes
  • git_log: Shows the commit logs
  • git_create_branch: Creates a new branch from an optional base branch
  • git_checkout: Switches branches
  • git_show: Shows the contents of a commit
  • git_init: Initialize a new Git repository
  • git_push: Pushes local commits to a remote repository (requires --write-access flag)
  • git_list_repositories: Lists all available Git repositories

Repository Management

Listing Repositories

The git_list_repositories tool lists all available Git repositories that the server is monitoring, showing:

  • The total number of repositories
  • The path to each repository
  • The repository name (derived from the directory name)

Example output:

Available repositories (3):

1. repo1 (/path/to/repo1)
2. repo2 (/path/to/repo2)
3. another-project (/path/to/another-project)

Repository Selection

When running commands that require a repository path:

  1. If a specific repo_path is provided in the command, it will be used.
  2. If no repo_path is provided and multiple repositories are configured, the first repository will be used as the default.
  3. Each command output will indicate which repository was used for the operation.

Automatic Installation and Configuration

For a quick start, use this script to download and set up the Git MCP server:

# Download linux binary for the latest release
RELEASE="$(curl -s https://api.github.com/repos/geropl/git-mcp-go/releases/latest)"
DOWNLOAD_URL="$(echo $RELEASE | jq -r '.assets[] | select(.name | contains("linux-amd64")) | .browser_download_url')"
curl -L -o ./git-mcp-go $DOWNLOAD_URL
chmod +x ./git-mcp-go

# Setup the mcp server with a single repository
./git-mcp-go setup -r /path/to/git/repository --tool=cline --auto-approve=allow-local-only

rm -f ./git-mcp-go

Manual Configuration

You can manually add this to your claude_desktop_config.json:

"mcpServers": {
  "git": {
    "command": "/path/to/git-mcp-go",
    "args": ["serve", "-r=/path/to/repo1,/path/to/repo2", "--mode", "shell"]
  }
}

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "git" '{"command":"/path/to/git-mcp-go","args":["serve","-r","/path/to/git/repository"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "git": {
            "command": "/path/to/git-mcp-go",
            "args": [
                "serve",
                "-r",
                "/path/to/git/repository"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "git": {
            "command": "/path/to/git-mcp-go",
            "args": [
                "serve",
                "-r",
                "/path/to/git/repository"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later