Git文档MCP服务器
自动执行Git文档任务的模型上下文协议(MCP)服务器。此服务器提供智能工具,用于添加带有分支代码的代码注释、生成结构化提交消息和创建每日工作日志。
特性
1.🔖 添加代码注释
使用分支代码前缀自动向代码更改添加内联注释。
格式: // :
例子:
// FLYF-228: Added validation for user input
function validateUser(user) {
// ... code
}特征:
- 从git diff、阶段性更改或特定文件读取
- 从分支名称中提取分支代码(格式:
FLY[A-Z]-[0-9]{3}) - 防止重复评论
- 验证评论位置和格式
2.📝 生成提交消息
根据阶段性更改创建结构化提交消息。
格式:
:
Issues Addressed:
-
-
Limitations:
-
Comments:
- 例子:
FLYF-228: added validation check
Issues Addressed:
- Fixed missing null check
- Added input sanitization
Limitations:
- Works only for user role admin
Comments:
- Further refactoring needed3.📊 日常工作日志
从提交历史生成全面的每日工作日志。
输出示例:
Date: 2025-11-23
Branch: FLYF-228
Commits: 5
Work Log:
Features:
- Implemented validation rules
- Added MCP auto-commenting logic
Bug Fixes:
- Fixed null pointer exception
Refactoring:
- Refactored helper functions
Pending:
- 3 file(s) staged but not committed
- Review and commit staged changes
Summary:
- Total commits: 5
- Branch: feature/FLYF-228-test-branch安装
先决条件
- Node.js 18.0.0或更高版本
- 具有正确分支命名的Git存储库
设置
- 克隆或下载此存储库:
git clone https://github.com/Supreeth741/mcp-git-tools.git
cd mcp-git-tools- 安装依赖项:
npm install- 构建项目:
npm run build用法
作为MCP服务器
配置您的MCP客户端(例如Claude Desktop)以使用此服务器:
Claude桌面配置(claude_desktop_config.json):
在Windows上:
{
"mcpServers": {
"git-doc": {
"command": "node",
"args": ["d:\\flyzo\\mcp-git-tools\\dist\\index.js"],
"cwd": "d:\\flyzo\\your-git-project"
}
}
}在macOS/Linux上:
{
"mcpServers": {
"git-doc": {
"command": "node",
"args": ["/path/to/mcp-git-tools/dist/index.js"],
"cwd": "/path/to/your-git-project"
}
}
}注: 这 cwd 应该指向您要使用这些工具的实际Git项目目录。
可用工具
1. add_code_comments
为带有分支代码前缀的代码更改添加内联注释。
参数:
comment(必填):要添加的评论文本source(可选):更改来源-"staged","unstaged",或"file"(默认值:"staged")filePath(可选):文件路径(当源为"file")lineNumber(可选):行号(当源为"file")
MCP客户端中的示例用法:
Add comment "fixed validation bug" to staged changesAdd comment "TODO: optimize this loop" to file src/utils/helper.ts at line 422. generate_commit_message
根据阶段性更改生成结构化提交消息。
参数:
includeIssues(可选):包括“已解决的问题”部分(默认值:true)includeLimitations(可选):包括“限制”部分(默认值:true)includeComments(可选):包括“注释”部分(默认值:true)
MCP客户端中的示例用法:
Generate a commit message for my staged changesGenerate commit message without limitations section3. generate_daily_worklog
从提交历史生成每日工作日志。
参数:
date(可选):YYYY-MM-DD格式的日期(默认为今天)
MCP客户端中的示例用法:
Generate my work log for todayShow me the work log for 2025-11-20分行代码格式
服务器使用以下模式从git分支名称中提取分支代码:
图案: FLY[A-Z]-[0-9]{3}
有效示例:
FLYF-228从feature/FLYF-228-user-validationFLYZ-101从bugfix/FLYZ-101-fix-loginFLYA-999从FLYA-999-refactor-api
无效示例:
FLY-123(FLY后缺少字母)FLYF-12(只有2位数字,而不是3位)FLYF-1234(4位数字代替3位)
发展
脚本
# Build the project
npm run build
# Watch mode for development
npm run watch
# Run the server
npm start
# Build and run
npm run dev项目结构
mcp-git-tools/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── utils/
│ │ ├── branchParser.ts # Branch code extraction
│ │ └── gitOps.ts # Git operations
│ └── tools/
│ ├── addComments.ts # Add comments tool
│ ├── generateCommit.ts # Generate commit message tool
│ └── workLog.ts # Work log tool
├── dist/ # Compiled JavaScript (generated)
├── package.json
├── tsconfig.json
└── README.md运作原理
- 分支检测: 服务器读取您当前的git分支名称,并使用正则表达式模式匹配提取分支代码。
- Git集成: 用途
simple-git库与git存储库交互-读取差异、阶段性更改和提交历史记录。
- MCP协议: 实现模型上下文协议,以公开三个可由MCP客户端(如Claude Desktop)调用的工具。
- 智能分析: 分析代码更改以生成有意义的注释、提交消息和工作日志。
故障排除
“未找到有效的分支代码”
- 确保您的分支机构名称遵循以下格式:
FLY[A-Z]-[0-9]{3} - 例子:
feature/FLYF-228-description
“未发现阶段性更改”
- 先进行更改:
git add - 然后使用生成提交消息工具
“找不到模块@modelcontextprotocol/sdk”
- 跑
npm install安装依赖项 - 跑
npm run build编译TypeScript
服务器未出现在MCP客户端中
- 检查MCP配置中的路径是否正确
- 确保
dist/index.js存在(运行npm run build) - 配置更改后重新启动MCP客户端
需求
- Node.js>=18.0.0
- Git仓库
- 后面的分支机构名称
FLY[A-Z]-[0-9]{3}模式
许可证
麻省理工学院
作者
大街741
贡献
欢迎投稿!请随时提交拉取请求。
更新日志
版本1.0.0
- 初始版本
- 添加带有分支代码前缀的代码注释
- 生成结构化提交消息
- 根据提交历史记录创建每日工作日志
