🚀 Claude代码 + n8n + MCP集成项目
本项目将 n8n工作流自动化 与 Claude代码 以及 模型上下文协议(MCP)服务器 进行全面集成,可用于智能项目管理、自动内存转储以及由人工智能驱动的开发工作流。
✨ 主要特性
- 🔄 n8n工作流自动化:可视化工作流构建器,可实现复杂的自动化操作。
- 🤖 Claude代码集成:由人工智能驱动的编码助手,支持MCP。
- 💾 持久内存系统:保存项目状态和知识。
- 📄 自动转储:每日摘要和关机备份。
- 🎯 目标目录管理:在多个目录中有序生成代码。
- 🛠️ 开发工具:用于自动化、监控和维护的脚本。
- 🔧 兼容Windows:针对MINGW64/Git Bash环境进行了优化。
📦 安装指南
前提条件
- Node.js 18.0.0或更高版本
- npm 8.0.0或更高版本
- Git
- Claude专业版/团队版订阅(用于Claude代码)
- Windows:建议使用Git Bash或WSL2
1. 安装依赖
git clone <your-repo-url>
cd my-project-n8n
npm install
./automation/windows-fix.sh
./setup-targets.sh
2. 配置环境
cp .env.example .env
nano .env
3. 启动服务
npm run start &
claude auth
claude --dangerously-skip-permissions
claude
4. 验证设置
npm run check:dumps
claude "/mcp"
claude "Create a simple README.md in the target directory"
💻 使用示例
基础用法
项目管理
claude "Add todo: Implement user authentication, high priority, due tomorrow"
claude "Update project status to development with 75% progress"
claude "Record decision: Use PostgreSQL for database with rationale: better performance for complex queries"
claude "Get project overview with details"
claude "What are my next recommended actions?"
claude "Show me all high priority pending tasks"
代码生成
claude "Create a React UserProfile component with TypeScript in the frontend directory"
claude "Generate a responsive dashboard layout in the frontend/src/pages directory"
claude "Create Express API routes for user CRUD operations in the backend directory"
claude "Generate Mongoose models for User and Product in the backend/models directory"
claude "Create a complete authentication system with React frontend, Express backend, and shared TypeScript types"
n8n工作流集成
claude "Show me available n8n nodes for HTTP requests"
claude "Create a workflow that triggers when a GitHub issue is created and sends a Slack notification"
claude "List all n8n workflows and their status"
claude "Export the user-registration workflow to the workflows directory"
内存管理
claude "Create memory dump with type full"
claude "Create daily summary with metrics and tomorrow's plan"
claude "Search memory for 'authentication' across all types"
claude "What decisions have we made about the database?"
claude "Show me recent learnings from the past week"
高级用法
项目日常开发
npm run check:dumps
claude "Get project overview and next actions"
claude "Add todo: Implement password reset feature"
claude "Create React component for password reset form"
claude "Update project status with today's progress"
npm run dump:daily
功能开发
claude "Add upcoming feature: Real-time notifications with medium priority"
claude "Break down the implementation steps for real-time notifications"
claude "Create WebSocket server in backend for real-time features"
claude "Generate React hooks for WebSocket connection in frontend"
claude "Complete task with notes: Real-time notifications implemented successfully"
claude "Record learning: WebSocket implementation requires careful connection management"
团队协作
claude "Create API documentation for the authentication endpoints"
claude "Generate team update report for the past sprint"
claude "Record decision: Use Redis for session storage with rationale and alternatives"
claude "Export project report for stakeholder meeting"
📚 详细文档
API文档
配置文件
.env:环境变量和设置。
.mcp.json:MCP服务器配置。
package.json:依赖项和脚本。
- 项目内存:存储在
project-memory.json 中。
生成的文件
- 内存转储:
memory-dumps/ 目录下的Markdown文件。
- 备份:
backups/ 目录下的压缩JSON文件。
- 日志:
logs/ 目录下的操作日志。
- 工作流:
workflows/ 目录下的n8n导出文件。
🔧 技术细节
环境变量(.env)
PROJECT_NAME=My Awesome Project
PROJECT_VERSION=1.0.0
N8N_HOST=http://localhost:5678
N8N_API_KEY=your_api_key_here
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=your_secure_password
TARGET_PROJECT_DIR=/c/Workspace/MyProject
FRONTEND_DIR=/c/Workspace/MyProject/frontend
BACKEND_DIR=/c/Workspace/MyProject/backend
SHARED_DIR=/c/Workspace/MyProject/shared
MEMORY_FILE=./project-memory.json
DUMP_DIR=./memory-dumps
BACKUP_DIR=./backups
AUTO_DUMP=true
CRON_ENABLED=true
DAILY_DUMP_TIME=18:00
BACKUP_INTERVAL=4h
CLEANUP_DAYS=30
LOG_LEVEL=info
LOG_FILE=./logs/project.log
MCP服务器(.mcp.json)
{
"mcpServers": {
"memory-dump": {
"command": "node",
"args": ["./mcp-servers/memory-dump-server.js"],
"env": {
"MEMORY_FILE": "./project-memory.json",
"DUMP_DIR": "./memory-dumps",
"AUTO_DUMP": "true"
}
},
"filesystem-target": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "${TARGET_PROJECT_DIR}"],
"env": {}
},
"filesystem-current": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./"],
"env": {}
}
}
}
MCP服务器功能
内存转储服务器
- 项目状态管理:跟踪阶段、进度和里程碑。
- 待办事项管理:添加、更新和完成具有优先级的任务。
- 知识库:记录决策、学习和洞察。
- 自动转储系统:在事件发生时自动保存内存。
- 搜索和分析:在项目历史记录中查找信息。
文件系统服务器
- 多目录访问:针对不同的项目区域。
- 有序代码生成:前端、后端和共享代码。
- 文件操作:读取、写入、搜索和管理文件。
- 项目结构:维护有序的目录层次结构。
自动化功能
每日自动化
- 下午6:00:生成每日摘要。
- 晚上11:30:完整内存转储和备份。
- 每4小时:增量备份(工作日)。
- 每周:全面的项目报告。
事件触发的转储
- 任务完成:任务标记为完成时自动转储。
- 里程碑达成:为里程碑进行全面转储。
- 关机检测:系统关机时进行紧急转储。
- 错误恢复:发生严重错误时创建备份。
清理和维护
- 日志轮转:自动管理日志文件。
- 备份清理:删除30天以上的备份。
- 内存优化:压缩旧的转储和备份。
- 健康监控:检查系统状态并发出警报。
📜 可用脚本
npm run start
npm run start:docker
npm run stop:docker
npm run claude
npm run test:mcp
npm run dump:manual
npm run dump:daily
npm run dump:shutdown
npm run check:dumps
npm run setup:cron
npm run change-target
npm run test:targets
npm run logs:n8n
npm run logs:project
🚨 故障排除
常见问题
MCP服务器无法连接
claude "/mcp"
cd /path/to/project
claude
n8n无法访问
curl http://localhost:5678/rest/health
npm run start
文件权限问题
chmod +x automation/*.sh
chmod +x mcp-servers/*.js
chmod 755 memory-dumps backups logs
Windows路径问题
./automation/windows-fix.sh
调试信息
./automation/check-dumps.sh
tail -f logs/project.log
tail -f logs/dump.log
node mcp-servers/memory-dump-server.js
curl http://localhost:5678/rest/health
🤝 贡献指南
添加新的MCP服务器
- 在
mcp-servers/ 目录中创建服务器。
- 将配置添加到
.mcp.json 中。
- 更新文档。
- 使用Claude代码进行测试。
扩展自动化功能
- 在
automation/ 目录中添加脚本。
- 更新
package.json 脚本。
- 在README中记录使用方法。
- 在目标平台上进行测试。
改进内存系统
- 扩展内存转储服务器的功能。
- 添加新的工具函数。
- 更新自动转储触发器。
- 增强搜索和分析功能。
📄 许可证
本项目采用MIT许可证 - 有关详细信息,请参阅 LICENSE 文件。
🆘 支持
获取帮助
- 查看文档:查看本README和内联注释。
- 运行诊断:使用
npm run check:dumps 和调试脚本。
- 查看日志:查看
logs/ 目录中的日志。
- 社区资源:
报告问题
报告问题时,请提供以下信息:
- 系统信息(操作系统、Node.js版本)
- 错误消息和日志
- 重现步骤
- 配置文件(不包含敏感数据)
功能请求
改进建议:
- 新的MCP服务器功能
- 额外的自动化功能
- 更好的Windows兼容性
- 增强的文档
🎉 致谢
- Anthropic 提供了Claude代码和MCP协议。
- n8n 提供了出色的工作流自动化平台。
- 社区贡献者 开发了MCP服务器和工具。
- 开源库 使这个集成成为可能。
编码愉快!🚀
使用n8n、Claude代码和MCP精心打造 ❤️