Skip to main content
Glama
MCP Server Git

MCP Server Git

by liliangshan

MCP Server Git

A Model Context Protocol (MCP) server for executing git push operations with flexible branch mapping.

Features

  • Execute git push commands with flexible branch mapping and auto add/commit

  • Comprehensive Git operations: status, diff, add, log, push

  • Push history tracking and duplicate prevention

  • Pending changes review system with forced validation

  • Operation logging for debugging and monitoring

  • Support for multiple languages (English, Chinese, Traditional Chinese)

  • Environment variable configuration for flexibility

  • Proxy support (HTTP, HTTPS, SOCKS5) for corporate networks

Related MCP server: Git MCP

Installation

npm install -g @liangshanli/mcp-server-git

Environment Variables

The server requires the following environment variables:

Required

  • PROJECT_PATH: Absolute path to the git repository

  • LOCAL_BRANCH: Local branch name to push from

  • REMOTE_BRANCH: Remote branch name to push to

Optional

  • REMOTE_NAME: Remote name (default: "origin")

  • PULL_SOURCE_BRANCH: Source branch for git_pull (default: same as REMOTE_BRANCH)

  • GIT_PUSH_FLAGS: Additional git push flags (default: "--progress")

  • TOOL_PREFIX: Prefix for MCP tool names (default: "")

  • REPO_NAME: Repository identifier for logging and identification

  • LANGUAGE: Language for messages ("en", "zh", "zh-CN", "zh-TW") (default: "en")

  • MCP_LOG_DIR: Directory for log files (default: "./.setting" or "./.setting.{REPO_NAME}")

  • MCP_LOG_FILE: Log filename (default: "mcp-git.log")

  • MCP_PUSH_HISTORY_FILE: Push history filename (default: "push-history.json")

  • MCP_CHANGES_FILE: Pending changes filename (default: "pending-changes.json")

  • HTTP_PROXY: HTTP proxy URL (e.g., "http://proxy.company.com:8080")

  • HTTPS_PROXY: HTTPS proxy URL (e.g., "http://proxy.company.com:8080")

  • SOCKS_PROXY: SOCKS5 proxy URL (e.g., "socks5://proxy.company.com:1080"). Note: Git may require additional configuration for SOCKS5 proxy support.

  • NO_PROXY: Comma-separated list of hosts that should not use proxy

  • ALL_PROXY: Universal proxy URL for all protocols

Usage

1. Set Environment Variables

export PROJECT_PATH="/path/to/your/git/repository"
export LOCAL_BRANCH="main"
export REMOTE_BRANCH="main"
export REMOTE_NAME="origin"  # optional
export GIT_PUSH_FLAGS="--progress --verbose"  # optional
export TOOL_PREFIX="myproject"  # optional
export REPO_NAME="my-project"  # optional

# Proxy settings (optional)
export HTTP_PROXY="http://proxy.company.com:8080"
export HTTPS_PROXY="http://proxy.company.com:8080"
export SOCKS_PROXY="socks5://proxy.company.com:1080"
export NO_PROXY="localhost,127.0.0.1,.local"

2. Start the Server

Using npm script

npm start

Using the CLI

mcp-server-git

Using start-server.js (with validation)

npm run start-managed

Editor Integration

Multiple Project Instances Support

You can configure multiple instances of the Git MCP server in your editor to manage different repositories simultaneously. Use REPO_NAME and TOOL_PREFIX to isolate the tools and logs for each project.

Cursor Editor Configuration

Create or update .cursor/mcp.json in your project root:

{
  "mcpServers": {
    "git-web-app": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-git"],
      "env": {
        "PROJECT_PATH": "D:/projects/web-app",
        "LOCAL_BRANCH": "main",
        "REMOTE_BRANCH": "main",
        "REPO_NAME": "web-app",
        "TOOL_PREFIX": "web"
      }
    },
    "git-api-service": {
      "command": "npx",
      "args": ["@liangshanli/mcp-server-git"],
      "env": {
        "PROJECT_PATH": "D:/projects/api-service",
        "LOCAL_BRANCH": "develop",
        "REMOTE_BRANCH": "develop",
        "REPO_NAME": "api-service",
        "TOOL_PREFIX": "api"
      }
    }
  }
}

Benefits of Multiple Instances:

  • Tool Isolation: Each instance has its own prefixed tools (e.g., web_git_push, api_git_push).

  • Log Isolation: Logs are stored in separate directories (e.g., ./.setting.web-app/, ./.setting.api-service/).

  • Independent Config: Different branches and paths for each repository.

💡 Best Practices and Usage Suggestions

To fully leverage the power of MCP Git Server, it is recommended to follow these "strong constraint" instructions when collaborating with AI:

  1. Atomic Recording (save_changes):

    • Instruction Suggestion: "Please call the save_changes tool immediately after completing each independent small feature or bug fix. You need to clearly list the modified files and briefly describe your modification logic in one or two sentences. Strictly forbid accumulating a large number of changes without recording them."

    • Value: This ensures that AI's memory fragments are solidified in real-time, preventing the loss of initial intent in subsequent complex refactors.

  2. Modular Pushing (git_push):

    • Instruction Suggestion: "When we have completed all development and self-testing for the current feature module, please push by calling git_push. Before pushing, you must first fully read and summarize all our saved records from this session via get_pending_changes, generating a clear, structured Commit Message that covers all changes."

    • Value: Making "summarizing historical records" a statutory pre-step for pushing, completely eliminating "goldfish memory" commits.

  3. Periodic Review:

    • If the session is extremely long (e.g., lasting several hours), you can occasionally ask the AI to call get_pending_changes for a mid-term summary to ensure the stored records perfectly match the current actual code state.

3. MCP Tools

The server provides the following MCP tools:

git_push (or <TOOL_PREFIX>_git_push)

Execute git push command with a commit message. Automatically adds and commits changes before pushing. Requires reviewing pending changes first.

Important: You MUST call get_pending_changes to review changes before using this tool. The push will be blocked if changes haven't been reviewed.

What it does:

  1. Automatically runs git add . to stage all changes

  2. Automatically runs git commit -m "message" to commit changes

  3. Executes git push to push to remote repository

  4. Clears all pending changes and resets review status

Parameters:

  • message (string, required): Commit message

Example:

{
  "name": "git_push",
  "arguments": {
    "message": "Update project files"
  }
}

If TOOL_PREFIX is set (e.g., "myproject"), the tool name becomes myproject_git_push.

Required Workflow:

  1. Make code changes

  2. Call save_changes to record your modifications

  3. Call get_pending_changes to review and mark changes as reviewed

  4. Call git_push to automatically add, commit, and push changes

  5. For subsequent pushes, repeat steps 3-4 (review status is reset after each push attempt)

This executes: git push <REMOTE_NAME> <LOCAL_BRANCH>:<REMOTE_BRANCH> --progress

get_push_history (or <TOOL_PREFIX>_get_push_history)

Get the last 5 push history records to check for duplicates.

Parameters: None

get_operation_logs (or <TOOL_PREFIX>_get_operation_logs)

Get operation logs for debugging.

Parameters:

  • limit (number, optional): Number of logs to return (default: 50)

  • offset (number, optional): Offset for pagination (default: 0)

git_status (or <TOOL_PREFIX>_git_status)

Show the working directory and staging area status.

Parameters: None

Example:

{
  "name": "git_status"
}

git_diff (or <TOOL_PREFIX>_git_diff)

Show changes between working directory and HEAD or staging area.

Parameters:

  • staged (boolean, optional): Show staged changes instead of unstaged (default: false)

  • files (array, optional): Specific files to show diff for

Examples:

{
  "name": "git_diff"
}
{
  "name": "git_diff",
  "arguments": {
    "staged": true
  }
}

git_add (or <TOOL_PREFIX>_git_add)

Add file contents to the staging area.

Parameters:

  • files (array, optional): Files to add (default: ["."] for all files)

Examples:

{
  "name": "git_add"
}
{
  "name": "git_add",
  "arguments": {
    "files": ["src/main.js", "src/utils.js"]
  }
}

git_log (or <TOOL_PREFIX>_git_log)

Show commit history.

Parameters:

  • limit (number, optional): Number of commits to show (1-100, default: 10)

  • oneline (boolean, optional): Show commits in oneline format (default: false)

Examples:

{
  "name": "git_log"
}
{
  "name": "git_log",
  "arguments": {
    "limit": 5,
    "oneline": true
  }
}

git_pull (or <TOOL_PREFIX>_git_pull)

Execute git pull command from the configured remote and source branch.

Parameters: None

Example:

{
  "name": "git_pull"
}

This executes: git pull <REMOTE_NAME> <PULL_SOURCE_BRANCH>

save_changes (or <TOOL_PREFIX>_save_changes)

Save pending changes before pushing. Records modified files and change content for review.

Parameters:

  • files (array, required): Array of modified file paths

  • content (string, required): Description of the changes made

Example:

{
  "name": "save_changes",
  "arguments": {
    "files": ["src/main.js", "src/utils.js"],
    "content": "Fixed bug in user authentication"
  }
}

get_pending_changes (or <TOOL_PREFIX>_get_pending_changes)

Get and review pending changes before pushing. This tool MUST be called before git_push to enable pushing.

Important: Calling this tool marks changes as reviewed, allowing git_push to proceed. The review status is reset after each push attempt.

Parameters:

  • limit (number, optional): Number of changes to return (1-1000, default: 1000 - shows all changes)

  • offset (number, optional): Offset for pagination (default: 0)

Command Mapping

The server executes the following git command:

cd <PROJECT_PATH>
git push <REMOTE_NAME> <LOCAL_BRANCH>:<REMOTE_BRANCH> --progress

For example, with the default settings:

cd /path/to/project
git push origin main:main --progress

Validation

The server performs the following validations on startup:

  1. Checks for required environment variables

  2. Verifies that PROJECT_PATH exists

  3. Ensures PROJECT_PATH is a valid git repository (contains .git directory)

Logging

  • All operations are logged to files in the configured log directory

  • Push history is maintained to prevent duplicate operations

  • Operation logs include request/response details for debugging

Error Handling

  • Environment variable validation on startup

  • Git command error handling with detailed error messages

  • Automatic logging of all operations and errors

License

MIT

Available Tools

10 tools
get_operation_logsB

Get operation logs for debugging and monitoring purposes.

Inputs: limit, offset.

get_pending_changesA

Get pending changes that need to be reviewed before pushing. This tool MUST be called before git_push to enable pushing.

USAGE: Call this tool to view and review all pending changes. This will mark changes as reviewed, allowing git_push to proceed. The review status is reset after each push attempt.

By default, this tool returns ALL pending changes (limit=1000). Use smaller limit values for pagination if needed.

Examples: {} - View and review ALL changes (default) {"limit": 10, "offset": 0} - View and review first 10 changes {"limit": 50} - View and review first 50 changes

NOTE: Review status is valid only for the next push attempt. You may need to review again for subsequent pushes.

Inputs: limit, offset.

get_push_historyA

Get the last 5 push history records for the git repository. This tool should be called before using git_push to ensure the current changes have not been pushed before.

Inputs: no named parameters.

git_addA

Add file contents to the staging area.

USAGE: Call this tool to stage files for commit. Use "." to add all changes, or specify specific files.

Examples: {} - Add all changes (equivalent to "git add .") {"files": ["src/main.js", "src/utils.js"]} - Add specific files {"files": ["*.js"]} - Add files matching pattern (use shell expansion)

Inputs: files.

git_diffB

Show changes between working directory and HEAD or staging area.

USAGE: Call this tool to see the differences between your working directory and the last commit, or between staging area and HEAD.

Examples: {} - Show all unstaged changes {"staged": true} - Show staged changes {"files": ["src/main.js"]} - Show changes for specific file(s)

Inputs: staged, files.

git_logB

Show commit history.

USAGE: Call this tool to view the commit history of the repository.

Examples: {} - Show last 10 commits with full details {"limit": 5} - Show last 5 commits {"limit": 20, "oneline": true} - Show last 20 commits in oneline format

Inputs: limit, oneline.

git_pullA

Execute git pull command from "origin/main" to the current branch.

Pull command: git pull origin main

Inputs: no named parameters.

git_pushA

Execute git push command from "main" to "origin/main" in project path "/app/repo".

Push command: git push origin main:main --progress

⚠️ REQUIREMENT: You MUST call get_pending_changes to review changes before using this tool.

USAGE:

  1. First call get_pending_changes to review pending changes

  2. Then call this tool with the commit message parameter. Example: {message: "Update project files"}

Please provide the commit message in English language.

NOTE: If the push result contains a branch merge URL (such as a pull request URL), please output it to the user. If you can open a browser, you may also automatically open the URL.

The review status is reset after each push attempt (success or failure).

Inputs: message (required).

git_statusB

Show the working directory and staging area status.

USAGE: Call this tool to see which files have been modified, added, or deleted in your working directory and staging area.

Example: {}

Inputs: no named parameters.

save_changesA

Save pending changes before pushing. This tool records modified files and change content for review before git push.

USAGE: Call this tool to save your changes before pushing. The saved changes must be reviewed using get_pending_changes before git_push can proceed.

Please provide the change description in English language.

Example: {"files": ["src/main.js", "src/utils.js"], "content": "Fixed bug in user authentication"}

Inputs: files (required), content (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 10 tools

    Disambiguation4/5

    Most tools have distinct purposes: logs, pending changes, push history, add, diff, log, pull, push, status, save changes. The only potential confusion is between save_changes and get_pending_changes, but their usage order is clearly specified.

    Naming Consistency3/5

    Naming is mixed: tools use three patterns (get_*, git_*, and save_changes). Although each pattern is readable, the inconsistency across the set reduces predictability for an agent.

    Tool Count5/5

    10 tools is within the ideal range (3-15) for a focused Git server. Each tool serves a clear purpose without overloading the surface.

    Completeness2/5

    The server lacks a git commit tool, which is central to the git workflow. The custom save_changes/get_pending_changes workflow attempts to fill this but does not provide a true commit operation. Additionally, branch management tools are absent, limiting the server to a single-branch workflow.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      A Model Context Protocol server for Git repository interaction and automation. This server provides tools to read, search, and manipulate Git repositories via Large Language Models.
      14
      90,074 PyPI
      91,897
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      MCP server for managing Git operations on local repositories, allowing users to list repositories, get and create tags, list commits, push tags, and refresh repositories through a standardized interface.
      6
      3
      -
    • A
      license
      C
      quality
      B
      maintenance
      A Model Context Protocol server that enables LLMs to interact with Git repositories, providing tools to read, search, and manipulate Git repositories through commands like status, diff, commit, and branch operations.
      22
      4
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that enables AI assistants to perform standard Git operations like staging, committing, and pushing changes. It facilitates a high-quality, standardized workflow for managing code repositories through natural language commands.
      145 npm
      ISC