Git MCP 參考伺服器可讓用戶端讀取與操作 Git。本例只測讀取:在拋棄式儲存庫建立一個提交,改動出貨時間,再檢查 status、log 與未暫存 diff。
這次隔離測試驗證什麼
status 應指出 note.txt 有變動;log 應找到合成提交;diff 應同時保留舊時間 08:30 與新時間 16:45。若只看變更後全文,會失去改動前後的差異線索。
以下是實際保存的合成資料輸出,不是模型效能評比。
{
"status": "On branch master\nChanges not staged for commit:\n (use \"git add <file>...\" to update what will be committed)\n (use \"git restore <file>...\" to discard changes in working directory)\n\tmodified: note.txt\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")",
"log": [
"Commit: 8e8ea445f7b1ff941d59e3830cae203ba060cd58\nAuthor: Fixture\nDate: 2026-11-15 23:19:13+00:00\nMessage: synthetic fixture\n"
],
"diff": "diff --git a/note.txt b/note.txt\nindex 4ed69a1..120f624 100644\n--- a/note.txt\n+++ b/note.txt\n@@ -1 +1 @@\n-NOTE-31 08:30\n+NOTE-31 16:45"
}
重現這個小任務
紀錄使用 Linux 與 Python 3.12。安裝需要下載公開套件,核心執行階段無外網;未測試 Windows shell。請在可拋棄的環境執行範例。
python -m pip install mcp-server-git==2026.11.11
除了 Python 套件還需要 Git 執行檔;實測映像已安裝 Git。範例只在 /tmp 建立可拋棄的儲存庫。
import sys,json,traceback,importlib.metadata as meta,pathlib,asyncio,subprocess,os
SLUG='mcp-git'
def emit(package,checks,observations,**kw):
print(json.dumps({'checks':checks,'observations':observations},ensure_ascii=False,default=str,indent=2))
def mcp_git():
from git import Repo
from mcp_server_git.server import git_status,git_log,git_diff_unstaged
p=pathlib.Path('/tmp/repo');p.mkdir();r=Repo.init(p);r.config_writer().set_value('user','name','Fixture').set_value('user','email','fixture@example.test').release();f=p/'note.txt';f.write_text('NOTE-31 08:30\n');r.index.add(['note.txt']);r.index.commit('synthetic fixture');f.write_text('NOTE-31 16:45\n');a=git_status(r);b=git_log(r,max_count=1);d=git_diff_unstaged(r)
emit('mcp-server-git',dict(modified='note.txt' in str(a),history='synthetic fixture' in str(b),diff='16:45' in str(d) and '08:30' in str(d)),dict(status=a,log=b,diff=d),scope='Reference server read-only Git functions on disposable local repository. No remote push, credentials or AI host.')
mcp_git()
限制與未測部分
未測試遠端存取、push、分支變更、Host 權限或 MCP stdio。測試使用合成 Git 身分,沒有帳戶登入或私有儲存庫。
其他功能依下列固定版本官方文件整理,未本地實測。開源套件不代表代管執行或模型呼叫免費。
來源與測試紀錄
本次由 Codex 在非 root、封鎖外網、無發布憑證的容器執行合成資料測試,不代表站長親測。
實測套件:2026.11.11;文件 commit:e1dc4b18dbb9。套件與 README 分別固定,不假定是同一版。測試日期:2026-11-15。