Kiro 配置 Git MCP Server 通用教程
Kiro 配置 Git MCP Server 通用教程一、什么是 Git MCP ServerGit MCP Server 是基于 Model Context Protocol 的 Git 操作服务配置后 Kiro 可以在对话中直接执行 Git 操作查日志、看提交详情、对比分支差异等无需手动在终端执行命令再复制结果。二、提供的工具清单工具功能关键参数git_status查看工作区和暂存区状态repo_pathgit_log查看提交历史repo_path, max_countgit_show查看某次提交的详细内容repo_path, revisiongit_diff对比两个引用之间的差异repo_path, targetgit_diff_unstaged查看未暂存的修改repo_pathgit_diff_staged查看已暂存的修改repo_pathgit_add暂存文件repo_path, files[]git_commit创建提交repo_path, messagegit_create_branch创建分支repo_path, branch_name, base_branch?git_checkout切换分支repo_path, branch_namegit_reset取消暂存repo_pathgit_branch列出分支repo_path, branch_type注博客https://blog.csdn.net/badao_liumang_qizhi三、安装步骤步骤 1安装 mcp-server-gituv 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.exemacOS/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重连 MCPCtrlShiftP→ 搜索MCP→ 选择重新连接 MCP 服务器。在 Kiro 功能面板的 MCP Server 视图中确认git状态为已连接。四、配置字段说明字段说明示例值commandmcp-server-git 可执行文件的完整路径C:\\Users\\admin\\.local\\bin\\mcp-server-git.exeargs启动参数--repository指定仓库路径[--repository, D:\\Projects\\my-app]env环境变量git server 通常不需要额外环境变量{}disabled是否禁用falseautoApprove免确认自动执行的工具名列表[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 PowerShellTest-PathC:\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问题 4pywin32 权限拒绝Windows原因安装依赖时临时目录权限不足。解决以管理员身份打开终端再执行安装命令。问题 5没有 git_blame 工具说明mcp-server-gitPython 版目前不提供blame工具。如需追溯行级历史可以使用git_log配合文件路径查看文件级提交历史在终端中执行git blame -L start,end file或git log -L start,end:file或安装 Node.js 版的cyanheads/git-mcp-server提供 blame 功能八、安全建议只读工具可以 autoApprovegit_status、git_log、git_show、git_diff是安全的只读操作可以加入 autoApprove 列表写操作保持确认git_add、git_commit、git_checkout、git_reset会修改仓库状态建议保留手动确认不支持 push该 MCP Server 不暴露git push避免误推送到远程单仓库绑定一个 server 实例只服务一个仓库多仓库需配置多个 serverautoApprove 推荐配置只读操作免确认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. CtrlShiftP → MCP → 重新连接 6. MCP Server 视图确认 git 状态为已连接 7. 在对话中直接用自然语言请求 git 操作