Skip to main content
Glama

n8n-MCP

by 88-888
test-expression-format-validation.jsβ€’7.75 kB
#!/usr/bin/env node /** * Test script for expression format validation * Tests the validation of expression prefixes and resource locator formats */ const { WorkflowValidator } = require('../dist/services/workflow-validator.js'); const { NodeRepository } = require('../dist/database/node-repository.js'); const { EnhancedConfigValidator } = require('../dist/services/enhanced-config-validator.js'); const { createDatabaseAdapter } = require('../dist/database/database-adapter.js'); const path = require('path'); async function runTests() { // Initialize database const dbPath = path.join(__dirname, '..', 'data', 'nodes.db'); const adapter = await createDatabaseAdapter(dbPath); const db = adapter; const nodeRepository = new NodeRepository(db); const validator = new WorkflowValidator(nodeRepository, EnhancedConfigValidator); console.log('\nπŸ§ͺ Testing Expression Format Validation\n'); console.log('=' .repeat(60)); // Test 1: Email node with missing = prefix console.log('\nπŸ“ Test 1: Email Send node - Missing = prefix'); console.log('-'.repeat(40)); const emailWorkflowIncorrect = { nodes: [ { id: 'b9dd1cfd-ee66-4049-97e7-1af6d976a4e0', name: 'Error Handler', type: 'n8n-nodes-base.emailSend', typeVersion: 2.1, position: [-128, 400], parameters: { fromEmail: '{{ $env.ADMIN_EMAIL }}', // INCORRECT - missing = toEmail: 'admin@company.com', subject: 'GitHub Issue Workflow Error - HIGH PRIORITY', options: {} }, credentials: { smtp: { id: '7AQ08VMFHubmfvzR', name: 'romuald@aiadvisors.pl' } } } ], connections: {} }; const result1 = await validator.validateWorkflow(emailWorkflowIncorrect); if (result1.errors.some(e => e.message.includes('Expression format'))) { console.log('βœ… ERROR DETECTED (correct behavior):'); const formatError = result1.errors.find(e => e.message.includes('Expression format')); console.log('\n' + formatError.message); } else { console.log('❌ No expression format error detected (should have detected missing prefix)'); } // Test 2: Email node with correct = prefix console.log('\nπŸ“ Test 2: Email Send node - Correct = prefix'); console.log('-'.repeat(40)); const emailWorkflowCorrect = { nodes: [ { id: 'b9dd1cfd-ee66-4049-97e7-1af6d976a4e0', name: 'Error Handler', type: 'n8n-nodes-base.emailSend', typeVersion: 2.1, position: [-128, 400], parameters: { fromEmail: '={{ $env.ADMIN_EMAIL }}', // CORRECT - has = toEmail: 'admin@company.com', subject: 'GitHub Issue Workflow Error - HIGH PRIORITY', options: {} } } ], connections: {} }; const result2 = await validator.validateWorkflow(emailWorkflowCorrect); if (result2.errors.some(e => e.message.includes('Expression format'))) { console.log('❌ Unexpected expression format error (should accept = prefix)'); } else { console.log('βœ… No expression format errors (correct!)'); } // Test 3: GitHub node without resource locator format console.log('\nπŸ“ Test 3: GitHub node - Missing resource locator format'); console.log('-'.repeat(40)); const githubWorkflowIncorrect = { nodes: [ { id: '3c742ca1-af8f-4d80-a47e-e68fb1ced491', name: 'Send Welcome Comment', type: 'n8n-nodes-base.github', typeVersion: 1.1, position: [-240, 96], parameters: { operation: 'createComment', owner: '{{ $vars.GITHUB_OWNER }}', // INCORRECT - needs RL format repository: '{{ $vars.GITHUB_REPO }}', // INCORRECT - needs RL format issueNumber: null, body: 'πŸ‘‹ Hi @{{ $(\'Extract Issue Data\').first().json.author }}!' // INCORRECT - missing = }, credentials: { githubApi: { id: 'edgpwh6ldYN07MXx', name: 'GitHub account' } } } ], connections: {} }; const result3 = await validator.validateWorkflow(githubWorkflowIncorrect); const formatErrors = result3.errors.filter(e => e.message.includes('Expression format')); console.log(`\nFound ${formatErrors.length} expression format errors:`); if (formatErrors.length >= 3) { console.log('βœ… All format issues detected:'); formatErrors.forEach((error, index) => { const field = error.message.match(/Field '([^']+)'/)?.[1] || 'unknown'; console.log(` ${index + 1}. Field '${field}' - ${error.message.includes('resource locator') ? 'Needs RL format' : 'Missing = prefix'}`); }); } else { console.log('❌ Not all format issues detected'); } // Test 4: GitHub node with correct resource locator format console.log('\nπŸ“ Test 4: GitHub node - Correct resource locator format'); console.log('-'.repeat(40)); const githubWorkflowCorrect = { nodes: [ { id: '3c742ca1-af8f-4d80-a47e-e68fb1ced491', name: 'Send Welcome Comment', type: 'n8n-nodes-base.github', typeVersion: 1.1, position: [-240, 96], parameters: { operation: 'createComment', owner: { __rl: true, value: '={{ $vars.GITHUB_OWNER }}', // CORRECT - RL format with = mode: 'expression' }, repository: { __rl: true, value: '={{ $vars.GITHUB_REPO }}', // CORRECT - RL format with = mode: 'expression' }, issueNumber: 123, body: '=πŸ‘‹ Hi @{{ $(\'Extract Issue Data\').first().json.author }}!' // CORRECT - has = } } ], connections: {} }; const result4 = await validator.validateWorkflow(githubWorkflowCorrect); const formatErrors4 = result4.errors.filter(e => e.message.includes('Expression format')); if (formatErrors4.length === 0) { console.log('βœ… No expression format errors (correct!)'); } else { console.log(`❌ Unexpected expression format errors: ${formatErrors4.length}`); formatErrors4.forEach(e => console.log(' - ' + e.message.split('\n')[0])); } // Test 5: Mixed content expressions console.log('\nπŸ“ Test 5: Mixed content with expressions'); console.log('-'.repeat(40)); const mixedContentWorkflow = { nodes: [ { id: '1', name: 'HTTP Request', type: 'n8n-nodes-base.httpRequest', typeVersion: 4, position: [0, 0], parameters: { url: 'https://api.example.com/users/{{ $json.userId }}', // INCORRECT headers: { 'Authorization': '=Bearer {{ $env.API_TOKEN }}' // CORRECT } } } ], connections: {} }; const result5 = await validator.validateWorkflow(mixedContentWorkflow); const urlError = result5.errors.find(e => e.message.includes('url') && e.message.includes('Expression format')); if (urlError) { console.log('βœ… Mixed content error detected for URL field'); console.log(' Should be: "=https://api.example.com/users/{{ $json.userId }}"'); } else { console.log('❌ Mixed content error not detected'); } console.log('\n' + '='.repeat(60)); console.log('\n✨ Expression Format Validation Summary:'); console.log(' - Detects missing = prefix in expressions'); console.log(' - Identifies fields needing resource locator format'); console.log(' - Provides clear correction examples'); console.log(' - Handles mixed literal and expression content'); // Close database db.close(); } runTests().catch(error => { console.error('Test failed:', error); process.exit(1); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/88-888/n8n-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server