UNPKG

n8n-mcp

Version:

Integration between n8n workflow automation and Model Context Protocol (MCP)

196 lines 8.15 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const database_adapter_js_1 = require("../database/database-adapter.js"); const node_repository_js_1 = require("../database/node-repository.js"); const workflow_validator_js_1 = require("../services/workflow-validator.js"); const workflow_diff_engine_js_1 = require("../services/workflow-diff-engine.js"); const path_1 = require("path"); async function main() { console.log('🔍 Testing Node-Level Properties Configuration\n'); const dbPath = (0, path_1.join)(process.cwd(), 'nodes.db'); const dbAdapter = await (0, database_adapter_js_1.createDatabaseAdapter)(dbPath); const nodeRepository = new node_repository_js_1.NodeRepository(dbAdapter); const EnhancedConfigValidator = (await Promise.resolve().then(() => __importStar(require('../services/enhanced-config-validator.js')))).EnhancedConfigValidator; const validator = new workflow_validator_js_1.WorkflowValidator(nodeRepository, EnhancedConfigValidator); const diffEngine = new workflow_diff_engine_js_1.WorkflowDiffEngine(); console.log('1️⃣ Complete Node Configuration Example:'); const completeNode = { id: 'node_1', name: 'Database Query', type: 'n8n-nodes-base.postgres', typeVersion: 2.6, position: [450, 300], parameters: { operation: 'executeQuery', query: 'SELECT * FROM users WHERE active = true' }, credentials: { postgres: { id: 'cred_123', name: 'Production Database' } }, disabled: false, notes: 'This node queries active users from the production database', notesInFlow: true, executeOnce: true, onError: 'continueErrorOutput', retryOnFail: true, maxTries: 3, waitBetweenTries: 2000, alwaysOutputData: true }; console.log(JSON.stringify(completeNode, null, 2)); console.log('\n✅ All properties are at the correct level!\n'); console.log('2️⃣ Complete Workflow Example:'); const workflow = { name: 'Production Data Processing', nodes: [ { id: 'trigger_1', name: 'Every Hour', type: 'n8n-nodes-base.scheduleTrigger', typeVersion: 1.2, position: [250, 300], parameters: { rule: { interval: [{ field: 'hours', hoursInterval: 1 }] } }, notes: 'Runs every hour to check for new data', notesInFlow: true }, completeNode, { id: 'error_handler', name: 'Error Notification', type: 'n8n-nodes-base.slack', typeVersion: 2.3, position: [650, 450], parameters: { resource: 'message', operation: 'post', channel: '#alerts', text: 'Database query failed!' }, credentials: { slackApi: { id: 'cred_456', name: 'Alert Slack' } }, executeOnce: true, onError: 'continueRegularOutput' } ], connections: { 'Every Hour': { main: [[{ node: 'Database Query', type: 'main', index: 0 }]] }, 'Database Query': { main: [[{ node: 'Process Data', type: 'main', index: 0 }]], error: [[{ node: 'Error Notification', type: 'main', index: 0 }]] } } }; console.log('\n3️⃣ Validating Workflow:'); const result = await validator.validateWorkflow(workflow, { profile: 'strict' }); console.log(`Valid: ${result.valid}`); console.log(`Errors: ${result.errors.length}`); console.log(`Warnings: ${result.warnings.length}`); if (result.errors.length > 0) { console.log('\nErrors:'); result.errors.forEach((err) => console.log(`- ${err.message}`)); } console.log('\n4️⃣ Updating Node-Level Properties with Diff Engine:'); const operations = [ { type: 'updateNode', nodeName: 'Database Query', changes: { 'parameters.query': 'SELECT * FROM users WHERE active = true AND created_at > NOW() - INTERVAL \'7 days\'', 'onError': 'stopWorkflow', 'executeOnce': false, 'notes': 'Updated to only query users from last 7 days', 'maxTries': 5, 'disabled': false } } ]; console.log('Operations:'); console.log(JSON.stringify(operations, null, 2)); console.log('\n5️⃣ ❌ COMMON MISTAKES TO AVOID:'); const wrongNode = { id: 'wrong_1', name: 'Wrong Configuration', type: 'n8n-nodes-base.httpRequest', typeVersion: 4.2, position: [250, 300], parameters: { method: 'POST', url: 'https://api.example.com', onError: 'continueErrorOutput', retryOnFail: true, executeOnce: true, notes: 'This is wrong!', credentials: { httpAuth: { id: '123' } } } }; console.log('❌ Wrong (properties inside parameters):'); console.log(JSON.stringify(wrongNode.parameters, null, 2)); const wrongWorkflow = { name: 'Wrong Example', nodes: [wrongNode], connections: {} }; const wrongResult = await validator.validateWorkflow(wrongWorkflow); console.log('\nValidation of wrong configuration:'); wrongResult.errors.forEach((err) => console.log(`❌ ERROR: ${err.message}`)); console.log('\n✅ Summary of Node-Level Properties:'); console.log('- credentials: Link to credential sets'); console.log('- disabled: Disable node execution'); console.log('- notes: Internal documentation'); console.log('- notesInFlow: Show notes on canvas'); console.log('- executeOnce: Execute only once per run'); console.log('- onError: Error handling strategy'); console.log('- retryOnFail: Enable automatic retries'); console.log('- maxTries: Number of retry attempts'); console.log('- waitBetweenTries: Delay between retries'); console.log('- alwaysOutputData: Output data on error'); console.log('- continueOnFail: (deprecated - use onError)'); console.log('\n🎯 Remember: All these properties go at the NODE level, not inside parameters!'); } main().catch(console.error); //# sourceMappingURL=test-node-level-properties.js.map