🚀 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精心打造 ❤️