使用说明
Git工作流自动化MCP服务器
一个模型上下文协议(MCP)服务器,提供自动化的Git工作流工具,用于提交、创建拉取请求以及与适当的GitHub身份验证处理合并。
特性
- 自动化Git操作:在一个命令中提交、推送、创建PR和合并
- GitHub身份验证处理:自动清除有问题的环境令牌
- 模拟运行支持:执行操作前进行测试
- 常规承诺:支持正确的提交消息格式
- 分行管理:自动创建和切换分支
- 错误处理:全面的错误报告和回滚功能
可用工具
1. git_commit_and_push
提交分阶段更改并推送到远程存储库。
参数:
files(数组,可选):要提交的文件路径(所有更改为空)commitMessage(字符串,必填):提交消息(使用常规格式)branch(字符串,可选):要创建/切换到的分支名称workingDir(字符串,可选):工作目录路径dryRun(boolean,可选):预览而不执行
例子:
use_mcp_tool("git-workflow", "git_commit_and_push", {
"files": ["src/app.ts", "README.md"],
"commitMessage": "feat: add new authentication system",
"branch": "feature/auth-system",
"dryRun": true
})
2. create_pull_request
创建具有适当身份验证处理的GitHub pull请求。
参数:
title(string,必填):拉取请求标题body(string,必填):拉取请求描述baseBranch(字符串,可选):基本分支(默认:“main”)headBranch(字符串,可选):头部分支(默认为当前)workingDir(字符串,可选):工作目录路径dryRun(boolean,可选):预览而不执行
例子:
use_mcp_tool("git-workflow", "create_pull_request", {
"title": "Feature: User Authentication System",
"body": "Implements comprehensive user authentication with JWT tokens and OAuth2 support",
"baseBranch": "main",
"headBranch": "feature/auth-system"
})
3. merge_pull_request
合并GitHub拉取请求。
参数:
prNumber(string,必填):拉取请求号mergeMethod(字符串,可选):“合并”、“挤压”或“重基”(默认值:“合并“)deleteBranch(布尔值,可选):合并后删除分支(默认值:true)workingDir(字符串,可选):工作目录路径dryRun(boolean,可选):预览而不执行
例子:
use_mcp_tool("git-workflow", "merge_pull_request", {
"prNumber": "42",
"mergeMethod": "squash",
"deleteBranch": true
})
4. complete_git_workflow
执行完整的Git工作流:提交、推送、创建PR,以及可选的合并。
参数:
files(数组,可选):要提交的文件commitMessage(字符串,必填):提交消息(常规格式)prTitle(string,必填):拉取请求标题prBody(string,必填):拉取请求描述branch(字符串,可选):功能分支名称baseBranch(字符串,可选):基本分支(默认:“main”)autoMerge(布尔值,可选):自动合并PR(默认值:false)workingDir(字符串,可选):工作目录路径dryRun(boolean,可选):预览而不执行
例子:
use_mcp_tool("git-workflow", "complete_git_workflow", {
"files": ["src/**/*.ts", "docs/**/*.md"],
"commitMessage": "feat(auth): implement OAuth2 authentication",
"prTitle": "Feature: OAuth2 Authentication System",
"prBody": "Adds comprehensive OAuth2 authentication with Google and GitHub providers",
"branch": "feature/oauth2-auth",
"autoMerge": false,
"dryRun": true
})
安装
快速设置
-
克隆存储库
git clone https://github.com/Arcia125/git-workflow-mcp-server.git cd git-workflow-mcp-server -
再进行
npm install -
构建服务器
npm run build -
添加到MCP配置
将服务器添加到MCP客户端设置文件中:
{ "mcpServers": { "git-workflow": { "command": "node", "args": ["/path/to/git-workflow-mcp-server/build/index.js"], "disabled": false, "alwaysAllow": [], "disabledTools": [] } } }
替代方案:NPM全球安装(即将推出)
未来的版本将支持全局npm安装:
npm install -g git-workflow-mcp-server
配置路径
常见MCP设置位置:
- Roo代码:
%APPDATA%/Code - Insiders/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json - 克劳德桌面:
%APPDATA%/Claude/claude_desktop_config.json - 其他MCP客户端:检查客户的文档以了解设置位置
验证安装
用干运行测试安装:
use_mcp_tool("git-workflow", "git_commit_and_push", {
"files": ["README.md"],
"commitMessage": "test: verify MCP server installation",
"dryRun": true
})
先决条件
- 已安装Node.js
- Git配置了远程存储库
- GitHub命令行界面(
gh)已安装并验证 - 正确的GitHub存储库权限
认证
服务器通过以下方式自动处理GitHub身份验证问题:
- 清除有问题的环境令牌(
GITHUB_TOKEN,GH_TOKEN) - 使用PowerShell命令进行可靠的令牌管理
- 依赖GitHub CLI密钥环身份验证
- 为身份验证失败提供详细的错误消息
最佳实践
1.始终先进行试运行
// Test the operation first
use_mcp_tool("git-workflow", "complete_git_workflow", {
"commitMessage": "feat: add new feature",
"prTitle": "New Feature",
"prBody": "Description",
"dryRun": true
})
// Then execute after confirmation
use_mcp_tool("git-workflow", "complete_git_workflow", {
"commitMessage": "feat: add new feature",
"prTitle": "New Feature",
"prBody": "Description",
"dryRun": false
})
2.使用常规承诺
// Good commit messages:
"feat(auth): add OAuth2 integration"
"fix(ui): resolve button alignment issue"
"docs(api): update endpoint documentation"
"refactor(utils): simplify date formatting"
3.有意义的公关标题和描述
{
"prTitle": "Feature: OAuth2 Authentication System",
"prBody": "## Changes\n- Implements OAuth2 with Google/GitHub\n- Adds JWT token management\n- Updates user authentication flow\n\n## Testing\n- All auth tests pass\n- Manual testing completed"
}
错误处理
服务器提供全面的错误处理:
- Git存储库错误:验证存储库状态
- 身份验证失败:处理GitHub CLI身份验证问题
- 网络问题:提供清晰的错误消息
- 分支冲突:管理分支创建/切换
- 合并冲突:报告清楚地合并了问题
依赖项
@modelcontextprotocol/sdk:MCP服务器框架simple-git:Git操作axios:HTTP请求(如果需要)zod:架构验证
发展
要修改服务器,请执行以下操作:
- 编辑
src/index.ts - 跑
npm run build - 重新启动MCP客户端
支持
对于问题或疑问:
- 检查GitHub CLI身份验证:
gh auth status - 验证存储库权限
- 查看错误消息以获取具体指导
- 首先以干运行模式进行测试
版本
版本0.1.0-具有核心Git工作流自动化功能的初始版本。
