Say Goodbye to AI's "Goldfish Memory"! MCP Git Server Deep Integration Guide

Have you ever found yourself in such an awkward and frustrating situation? During a deep coding session, you and your AI assistant are working in perfect harmony. It gracefully refactors core modules, fixes deep-seated bugs, and even optimizes several edge components along the way. In the process, changes span 5, 6, or even more files, with complex logic involving more than three interconnected features. However, when the work is done and you eagerly instruct it to git push, reality hits you hard—the AI-generated commit message is so pale and weak, writing only “Update index.js” or merely describing the few lines of trivial code it changed in the last five minutes.

In that moment, the grand designs you discussed earlier and the critical edge cases it handled half an hour ago seem to have vanished from its “electronic brain.” This “goldfish-like short-term memory” not only makes your project’s Git history a mess but also leaves you with a deep sense of helplessness. You have to stop what you’re doing, crawl through file diffs, and manually piece together the commit message that should have been fully summarized by the AI. This “collaboration gap” caused by the AI’s loss of context is one of the most headache-inducing ailments of current Large Language Models when handling complex, long-term Git tasks. AI often focuses only on the present, ignoring the efforts it has put in throughout the long conversational chain.

MCP Git Server was born to end this terrible experience. It is more than just a simple Git command forwarder; it introduces an innovative “Change Evidence” and “Mandatory Review” workflow. Through physical-level persistent storage, it equips the AI with an “unforgettable” memory enhancement engine, thoroughly solving the pain points of context loss in AI collaboration, ensuring that every push carries the full weight of the collective wisdom.


:rocket: Core Technology: Persistent Change Context

Traditional Git MCP tools are often “change and forget.” Our server ensures every step of the AI’s thought process is recorded through a closed-loop mechanism:

1. Offline Change Recorder (save_changes)

Whenever the AI completes a stage of code modification, it must call save_changes to save the list of modified files and the intent of the change to the server’s persistent storage (.setting/pending-changes.json). These records will not be lost even if the session restarts.

2. Mandatory Review Filter (get_pending_changes)

This is the most critical step. Before executing the final push, the system checks the status. If the AI hasn’t called get_pending_changes to read and confirm the previous change records, the git_push will be forcibly intercepted.

Purpose: To force the AI to “read” all its previously saved records before committing, reawakening its memory.

3. Global Perspective Push (git_push)

Only after the AI has reviewed all pending changes can it generate a clear, structured commit message that covers all variations accurately.


:light_bulb: 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.

:hammer_and_wrench: MCP Tool List and Usage Guide

Below are the primary MCP tools provided by the server, which together build a complete “AI Memory Enhancement” workflow:

Memory Enhancement (Core)

  • save_changes:
    • Function: Called by AI after modifying code to save the modified file paths and change intent description.
    • Value: Persistent AI’s temporary memory, ensuring context is not lost in complex tasks.
  • get_pending_changes:
    • Function: Lists all saved but unpushed change records and activates push permission.
    • Value: Forces AI to “review” the entire change before pushing, generating more accurate commit messages.

Git Core Operations

  • git_push:
    • Function: Automatically executes add ., commit, and pushes to the specified remote branch.
    • Prerequisite: Must call get_pending_changes to review changes first.
  • git_status:
    • Function: Displays the status of the working directory and staging area.
    • Value: Allows AI to keep track of current code changes at any time.
  • git_diff:
    • Function: Shows detailed file differences (supports staged and unstaged).
    • Value: Assists AI in analyzing modification logic and self-checking code quality.
  • git_log:
    • Function: Views commit history, supporting limit and oneline modes.
  • git_add:
    • Function: Manually adds files to the staging area.

Assistance and Management

  • get_push_history:
    • Function: Gets the last 5 push records.
    • Value: Prevents AI from duplicate commits or pushing already existing logic.
  • get_operation_logs:
    • Function: Gets server operation logs.
    • Value: A “black box” for developers to troubleshoot abnormal AI behavior.

:gear: Environment Variable Configuration Guide

To perfectly adapt MCP Git Server to your development environment, we offer a rich set of environment variable configuration options:

1. Core Required Items

Variable Description Example
PROJECT_PATH Absolute path to the Git repository D:/projects/my-repo
LOCAL_BRANCH Local branch name to push from main
REMOTE_BRANCH Corresponding remote branch name main

2. Identification and Isolation (Required for Multi-project)

Variable Description Default
REPO_NAME Unique repository identifier, used to distinguish log directories (None)
TOOL_PREFIX Prefix for MCP tool names (e.g., my_git_push) (None)
LANGUAGE AI interaction and message language (en/zh/zh-CN/zh-TW) en

3. Network and Proxy (Required for Corporate Environments)

Supports standard proxy protocols, allowing AI to push smoothly even within internal networks:

  • HTTP_PROXY / HTTPS_PROXY: HTTP/HTTPS proxies
  • SOCKS_PROXY: SOCKS5 proxy
  • ALL_PROXY: Global proxy
  • NO_PROXY: List of domains to bypass proxy (comma-separated)

4. Logs and Storage Paths (Advanced Customization)

Variable Description Default
MCP_LOG_DIR Directory for log storage ./.setting
MCP_LOG_FILE Filename for run logs mcp-git.log
MCP_CHANGES_FILE Critical: Pending changes record file pending-changes.json
MCP_PUSH_HISTORY_FILE Push history record file push-history.json

:toolbox: Git Core Capabilities Bundle

Beyond the unique change tracking mechanism, it is a complete set of Git enhancement tools that allow AI to deeply involve itself in your development workflow:

  • git_status: Real-time view of workspace status, never missing an unstaged change.
  • git_diff: Line-by-line comparison of changes. AI can use it to analyze logic changes and ensure commit quality.
  • git_add: Flexible staging control. Supports adding by file or in bulk.
  • git_log: Trace project history. AI can read previous commit records to learn your code commit standards.
  • get_push_history: Smart duplicate check. Check for similar commits before pushing to avoid redundant operations.

:hammer_and_wrench: Multi-project Integration Example (Cursor/VS Code)

Through TOOL_PREFIX and REPO_NAME, you can seamlessly switch and manage multiple projects within the same editor interface:

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

After configuration, your AI will have two independent sets of skill groups:

  • web_git_push / web_save_changes … (for the frontend project)
  • api_git_push / api_save_changes … (for the backend project)
  • They have their own independent log spaces (./.setting.frontend/ and ./.setting.backend/), and memories do not interfere with each other!

:chart_increasing: Why Do You Need It?

  • Prevent Missing Commit Descriptions: No more meaningless “Update code” commits.
  • Long Session Protection: During complex refactoring, AI can maintain logical consistency from the first line of code to the last by reading records.
  • Audit Transparency: All operations and change intentions are recorded in mcp-git.log, making it easy to review the AI’s behavior.

Install Now:
npm install -g @liangshanli/mcp-server-git

GitHub Repository:
https://github.com/liliangshan/mcp-server-git

Empower your AI assistant with “unforgettable” Git commit capabilities!