用于 Git 操作的模型上下文协议 (MCP) 服务器,为像 Claude Desktop 这样的 MCP 客户端提供全面的 Git 功能。
npm install -g git-mcp-server
克隆并安装:
git clone https://github.com/yourusername/git-mcp-server.git
cd git-mcp-server
npm install
构建项目:
npm run build
将此服务器添加到您的 Claude Desktop 配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"git": {
"command": "git-mcp-server",
"args": []
}
}
}
对于其他 MCP 客户端,直接使用服务器二进制文件:
git-mcp-server
服务器将自动使用当前工作目录作为 Git 仓库上下文。
配置完成后,您可以通过您的 MCP 客户端使用 Git 操作。服务器会自动检测当前工作目录中的 Git 仓库。
让您的 MCP 客户端(如 Claude)执行 Git 操作:
您可以手动从任何 Git 仓库测试服务器:
cd /path/to/your/git/repo
git-mcp-server
git_status - 获取当前 git 状态git_current_branch - 获取当前分支名称git_staged_changes - 获取暂存更改git_working_directory - 获取当前工作目录信息git_diff - 显示分支/提交之间的差异git_log- 获取提交历史git_show_file - 显示特定提交处的文件内容git_branches - 列出所有分支git_checkout - 切换到不同分支或创建新分支git_add - 将文件添加到暂存区git_commit - 创建带有消息和文件的提交git_pull - 从远程仓库拉取更改git_fetch - 从远程仓库获取更改而不合并git_init - 初始化一个新的 git 仓库MIT 许可证 - 详情见 LICENSE 文件。
git-mcp-server/
├── package.json # 项目依赖和脚本
├── tsconfig.json # TypeScript 配置
├── src/
│ └── index.ts # 主服务器实现
├── build/
│ └── index.js # 编译的 JavaScript(生成)
└── README.md # 此文件
npm run build - 构建 TypeScript 代码npm run dev - 开发监视模式npm start - 运行构建的服务器
</中文翻译>