使用说明
自定义MCP服务器
一个全面的模型上下文协议(MCP)服务器,用于简化开发工作流程和自动化常见任务。
什么是MCP?
模型上下文协议(MCP)是人工智能助手与外部数据源和工具安全连接的标准化方式。它能够:
- 安全集成:将人工智能模型与本地和远程资源连接起来
- 工具扩展:为AI助手添加自定义功能
- 工作流自动化:简化重复的开发任务
- 上下文增强:从各种数据源提供丰富的上下文
特性
此自定义MCP服务器提供以下工具:
🔧 开发自动化
- 代码生成:生成样板代码和模板
- 文件管理:自动创建、修改和组织文件
- Git工作流:简化分支机构管理、提交和PR创建
- 测试:自动生成和执行测试
🚀 CI/CD集成
- 分行管理:自动创建和切换开发分支
- 拉取请求自动化:使用适当的模板自动创建PR
- 代码审查:自动代码质量检查和建议
- 部署:简化了对各种环境的部署
📝 文档
- README生成:自动生成全面的文档
- 代码注释:智能注释生成,更好地理解代码
- API文档:来自代码注释的自动API文档
安装
先决条件
- Node.js 18+或Python 3.8+
- Git配置了正确的凭据
- 您首选的AI助手(Claude、GPT-4等)
设置
-
克隆存储库
git clone <your-repo-url> cd custom-mcp-server -
安装依赖项
# For Node.js npm install # For Python pip install -r requirements.txt -
配置MCP服务器
# Copy example config cp config.example.json config.json # Edit configuration nano config.json -
启动服务器
# Node.js npm start # Python python main.py
配置
创建一个 config.json 文件:
{
"server": {
"port": 3000,
"host": "localhost"
},
"git": {
"defaultBranch": "main",
"devBranch": "dev",
"remoteOrigin": "origin"
},
"automation": {
"autoCommit": true,
"autoPush": true,
"prTemplate": "templates/pr-template.md"
},
"tools": {
"codeGen": true,
"gitOps": true,
"documentation": true
}
}
用法
基本工作流自动化
-
创建新功能分支
Hey MCP, create a new feature branch called "feature/user-auth" -
生成代码结构
Generate a REST API structure for user authentication with: - Login endpoint - Registration endpoint - JWT middleware - User model -
自动化测试
Create unit tests for the authentication endpoints -
Git工作流自动化
Commit changes with message "Add user authentication system" and push to dev branch -
拉取请求创建
Create a PR from dev to main with title "Feature: User Authentication System"
高级自动化示例
完成功能开发
# Start with an idea
"Create a complete user management system with CRUD operations"
# MCP will:
# 1. Create feature branch
# 2. Generate models, controllers, routes
# 3. Create database migrations
# 4. Generate tests
# 5. Update documentation
# 6. Commit and push to dev
# 7. Create PR to main
Bug修复工作流程
# Report a bug
"Fix the login timeout issue in user authentication"
# MCP will:
# 1. Analyze existing code
# 2. Identify the problem
# 3. Generate fix
# 4. Update tests
# 5. Create hotfix branch
# 6. Commit and create PR
可用工具
Git操作
create_branch(name, base_branch)commit_changes(message, files)push_to_remote(branch)create_pull_request(title, description, base, head)
代码生成
generate_api_endpoint(path, method, description)create_model(name, fields)generate_tests(file_path)add_documentation(file_path)
文件操作
create_file(path, content)modify_file(path, changes)organize_files(directory)backup_files(pattern)
质量保证
run_tests()lint_code()security_scan()performance_check()
工作流示例
标准开发流程
graph TD
A[Idea/Task] --> B[Create Feature Branch]
B --> C[Generate Code Structure]
C --> D[Implement Logic]
D --> E[Generate Tests]
E --> F[Run Quality Checks]
F --> G[Commit & Push to Dev]
G --> H[Create PR to Main]
H --> I[Code Review]
I --> J[Merge to Main]
自动化部署管道
graph TD
A[PR Merged to Main] --> B[Trigger Deployment]
B --> C[Run Tests]
C --> D[Build Application]
D --> E[Deploy to Staging]
E --> F[Run E2E Tests]
F --> G[Deploy to Production]
G --> H[Monitor & Alert]
最佳实践
1.分行管理
- 始终处理特征分支
- 保持开发分支与主分支同步
- 使用描述性分支名称(feature/、bugfix/、hotfix/)
2.提交消息
- 使用常规提交格式
- 包括范围和描述
- 参考发行号(如适用)
3.拉取请求
- 使用PR模板
- 包括详尽的描述
- 添加审阅者和标签
- 链接到相关问题
4.代码质量
- 提交前运行测试
- 使用一致的格式
- 添加有意义的评论
- 遵循项目编码标准
与AI助手集成
克劳德集成
# Add to Claude's system prompt
"You have access to a custom MCP server that can automate development workflows. Use the available tools to streamline coding tasks, manage git operations, and maintain code quality."
VS代码集成
{
"mcp.servers": {
"custom-dev-server": {
"command": "node",
"args": ["path/to/custom-mcp-server/main.js"]
}
}
}
故障排除
常见问题
-
MCP服务器连接失败
# Check server status curl http://localhost:3000/health # Restart server npm restart -
Git身份验证问题
# Configure git credentials git config --global user.name "Your Name" git config --global user.email "your.email@example.com" # Setup SSH key for GitHub ssh-keygen -t rsa -b 4096 -C "your.email@example.com" -
权限错误
# Fix file permissions chmod +x scripts/*.sh # Update npm permissions npm config set prefix ~/.npm-global
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
路线图
- []添加对更多代码语言的支持
- []与更多CI/CD平台集成
- []高级代码分析和建议
- []团队协作功能
- []自定义webhook集成
- []Docker容器化
- []Kubernetes部署自动化
支持
- 📧 电子邮件:support@your-domain.com
- 💬 Discord:[您的Discord服务器]
- 📖 文档:[您的文档网站]
- 🐛 问题: GitHub问题
致谢
- Anthropic的MCP协议
- 开源社区
- 贡献者和测试者
制作❤️ 适用于热爱自动化的开发人员