Kiro 配置 Git MCP Server 通用教程
一、什么是 Git MCP Server
Git MCP Server 是基于 Model Context Protocol 的 Git 操作服务,配置后 Kiro 可以在对话中直接执行 Git 操作(查日志、看提交详情、对比分支差异等),无需手动在终端执行命令再复制结果。
二、提供的工具清单
| 工具 | 功能 | 关键参数 |
|---|---|---|
git_status | 查看工作区和暂存区状态 | repo_path |
git_log | 查看提交历史 | repo_path, max_count |
git_show | 查看某次提交的详细内容 | repo_path, revision |
git_diff | 对比两个引用之间的差异 | repo_path, target |
git_diff_unstaged | 查看未暂存的修改 | repo_path |
git_diff_staged | 查看已暂存的修改 | repo_path |
git_add | 暂存文件 | repo_path, files[] |
git_commit | 创建提交 | repo_path, message |
git_create_branch | 创建分支 | repo_path, branch_name, base_branch? |
git_checkout | 切换分支 | repo_path, branch_name |
git_reset | 取消暂存 | repo_path |
git_branch | 列出分支 | repo_path, branch_type |
注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
三、安装步骤
步骤 1:安装 mcp-server-git
uv toolinstallmcp-server-git --index-url https://pypi.tuna.tsinghua.edu.cn/simple安装成功后输出示例:
Installed 1 executable: mcp-server-git warning: `C:\Users\<用户名>\.local\bin` is not on your PATH.记住可执行文件路径:
- Windows:
C:\Users\<用户名>\.local\bin\mcp-server-git.exe - macOS/Linux:
~/.local/bin/mcp-server-git
步骤 2:配置 MCP
编辑.kiro/settings/mcp.json,添加 git server 配置:
{"mcpServers":{"git":{"command":"C:\\Users\\<用户名>\\.local\\bin\\mcp-server-git.exe","args":["--repository","D:\\your\\project\\path"],"env":{},"disabled":false,"autoApprove":[]}}}步骤 3:重连 MCP
Ctrl+Shift+P→ 搜索MCP→ 选择重新连接 MCP 服务器。
在 Kiro 功能面板的 MCP Server 视图中确认git状态为已连接。
四、配置字段说明
| 字段 | 说明 | 示例值 |
|---|---|---|
command | mcp-server-git 可执行文件的完整路径 | C:\\Users\\admin\\.local\\bin\\mcp-server-git.exe |
args | 启动参数,--repository指定仓库路径 | ["--repository", "D:\\Projects\\my-app"] |
env | 环境变量,git server 通常不需要额外环境变量 | {} |
disabled | 是否禁用 | false |
autoApprove | 免确认自动执行的工具名列表 | ["git_status", "git_log", "git_show"] |
关于--repository参数
- 必须是绝对路径
- 所有 git 操作都限定在此仓库内(安全隔离)
- 如果省略,server 会使用启动时的工作目录(不推荐,可能导致路径不一致)
五、完整配置示例(MySQL + Git 多 Server)
{"mcpServers":{"mysql":{"command":"C:\\Users\\admin\\.local\\bin\\mcp-server-mysql.exe","args":[],"env":{"MYSQL_HOST":"localhost","MYSQL_PORT":"3306","MYSQL_USER":"root","MYSQL_PASSWORD":"your_password","MYSQL_DATABASE":"your_database","UV_INDEX_URL":"https://pypi.tuna.tsinghua.edu.cn/simple"},"disabled":false,"autoApprove":[]},"git":{"command":"C:\\Users\\admin\\.local\\bin\\mcp-server-git.exe","args":["--repository","D:\\Projects\\my-app"],"env":{},"disabled":false,"autoApprove":[]}}}六、使用示例
配置成功后,直接在对话中用自然语言请求:
查看最近提交
“看下最近 10 条提交记录”
查看某次提交详情
“show 一下 commit abc1234 做了什么改动”
对比分支差异
“对比 feature/xxx 和 main 分支的差异”
查看某文件的修改历史
“看下 src/UserService.java 相关的最近 5 次提交”
查看工作区状态
“当前有哪些文件被修改了”
七、常见问题
问题 1:提示 mcp-server-git.exe 不存在
原因:未安装或路径不对。
解决:
# 确认安装uv toolinstallmcp-server-git --index-url https://pypi.tuna.tsinghua.edu.cn/simple# 确认路径(Windows PowerShell)Test-Path"C:\Users\<用户名>\.local\bin\mcp-server-git.exe"问题 2:连接后 MCP Logs 报 “repository not found”
原因:--repository指定的路径不是一个有效的 git 仓库(没有.git目录)。
解决:确认路径正确且该目录已git init或git clone。
问题 3:下载包超时
原因:国内访问 PyPI 超时。
解决:安装时指定镜像源:
uv toolinstallmcp-server-git --index-url https://pypi.tuna.tsinghua.edu.cn/simple问题 4:pywin32 权限拒绝(Windows)
原因:安装依赖时临时目录权限不足。
解决:以管理员身份打开终端再执行安装命令。
问题 5:没有 git_blame 工具
说明:mcp-server-git(Python 版)目前不提供blame工具。如需追溯行级历史,可以:
- 使用
git_log配合文件路径查看文件级提交历史 - 在终端中执行
git blame -L <start>,<end> <file>或git log -L <start>,<end>:<file> - 或安装 Node.js 版的
@cyanheads/git-mcp-server(提供 blame 功能)
八、安全建议
- 只读工具可以 autoApprove:
git_status、git_log、git_show、git_diff是安全的只读操作,可以加入 autoApprove 列表 - 写操作保持确认:
git_add、git_commit、git_checkout、git_reset会修改仓库状态,建议保留手动确认 - 不支持 push:该 MCP Server 不暴露
git push,避免误推送到远程 - 单仓库绑定:一个 server 实例只服务一个仓库,多仓库需配置多个 server
autoApprove 推荐配置(只读操作免确认):
"autoApprove":["git_status","git_log","git_show","git_diff","git_diff_unstaged","git_diff_staged","git_branch"]九、配置流程速查
1. uv tool install mcp-server-git --index-url https://pypi.tuna.tsinghua.edu.cn/simple 2. 确认可执行文件路径:C:\Users\<用户名>\.local\bin\mcp-server-git.exe 3. 编辑 .kiro/settings/mcp.json,添加 git server 配置 4. args 中用 --repository 指定仓库绝对路径 5. Ctrl+Shift+P → MCP → 重新连接 6. MCP Server 视图确认 git 状态为已连接 7. 在对话中直接用自然语言请求 git 操作