n8n-mcp 2.99.0 → 2.99.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/http-server-single-session.d.ts +1 -0
  2. package/dist/http-server-single-session.d.ts.map +1 -1
  3. package/dist/http-server-single-session.js +15 -11
  4. package/dist/http-server-single-session.js.map +1 -1
  5. package/dist/services/ai-node-validator.d.ts +10 -3
  6. package/dist/services/ai-node-validator.d.ts.map +1 -1
  7. package/dist/services/ai-node-validator.js +95 -42
  8. package/dist/services/ai-node-validator.js.map +1 -1
  9. package/dist/services/expression-validator.d.ts +3 -1
  10. package/dist/services/expression-validator.d.ts.map +1 -1
  11. package/dist/services/expression-validator.js +2 -1
  12. package/dist/services/expression-validator.js.map +1 -1
  13. package/dist/services/n8n-api-client.d.ts.map +1 -1
  14. package/dist/services/n8n-api-client.js +1 -2
  15. package/dist/services/n8n-api-client.js.map +1 -1
  16. package/dist/services/node-similarity-service.d.ts +1 -0
  17. package/dist/services/node-similarity-service.d.ts.map +1 -1
  18. package/dist/services/node-similarity-service.js +15 -7
  19. package/dist/services/node-similarity-service.js.map +1 -1
  20. package/dist/services/workflow-validator.d.ts +8 -0
  21. package/dist/services/workflow-validator.d.ts.map +1 -1
  22. package/dist/services/workflow-validator.js +118 -40
  23. package/dist/services/workflow-validator.js.map +1 -1
  24. package/dist/triggers/handlers/base-handler.d.ts +1 -0
  25. package/dist/triggers/handlers/base-handler.d.ts.map +1 -1
  26. package/dist/triggers/handlers/base-handler.js +13 -0
  27. package/dist/triggers/handlers/base-handler.js.map +1 -1
  28. package/dist/triggers/handlers/chat-handler.d.ts.map +1 -1
  29. package/dist/triggers/handlers/chat-handler.js +3 -0
  30. package/dist/triggers/handlers/chat-handler.js.map +1 -1
  31. package/dist/triggers/handlers/form-handler.d.ts.map +1 -1
  32. package/dist/triggers/handlers/form-handler.js +8 -0
  33. package/dist/triggers/handlers/form-handler.js.map +1 -1
  34. package/dist/triggers/handlers/webhook-handler.d.ts.map +1 -1
  35. package/dist/triggers/handlers/webhook-handler.js +3 -0
  36. package/dist/triggers/handlers/webhook-handler.js.map +1 -1
  37. package/dist/utils/ssrf-protection.d.ts +2 -0
  38. package/dist/utils/ssrf-protection.d.ts.map +1 -1
  39. package/dist/utils/ssrf-protection.js +19 -8
  40. package/dist/utils/ssrf-protection.js.map +1 -1
  41. package/package.json +1 -1
@@ -119,15 +119,26 @@ function collectMalformedConnectionErrors(connections) {
119
119
  }
120
120
  return errors;
121
121
  }
122
+ const MAX_LOOP_BACK_STEPS = 1000000;
122
123
  class WorkflowValidator {
123
124
  constructor(nodeRepository, nodeValidator) {
124
125
  this.nodeRepository = nodeRepository;
125
126
  this.nodeValidator = nodeValidator;
126
127
  this.currentWorkflow = null;
128
+ this.loopBackReach = new Map();
129
+ this.loopBackSteps = 0;
130
+ this.loopBackIncompleteReported = false;
131
+ this.lowerCaseNames = new Map();
132
+ this.mainInputTargets = null;
127
133
  this.similarityService = new node_similarity_service_1.NodeSimilarityService(nodeRepository);
128
134
  }
129
135
  async validateWorkflow(workflow, options = {}) {
130
136
  this.currentWorkflow = workflow;
137
+ this.loopBackReach = new Map();
138
+ this.loopBackSteps = MAX_LOOP_BACK_STEPS;
139
+ this.loopBackIncompleteReported = false;
140
+ this.lowerCaseNames = new Map();
141
+ this.mainInputTargets = null;
131
142
  const { validateNodes = true, validateConnections = true, validateExpressions = true, profile = 'runtime' } = options;
132
143
  const result = {
133
144
  valid: true,
@@ -366,6 +377,20 @@ class WorkflowValidator {
366
377
  });
367
378
  }
368
379
  async validateAllNodes(workflow, result, profile) {
380
+ const reportedErrors = new Map();
381
+ let reportedErrorsIndexed = 0;
382
+ const hasReportedError = (nodeName, message) => {
383
+ for (; reportedErrorsIndexed < result.errors.length; reportedErrorsIndexed++) {
384
+ const e = result.errors[reportedErrorsIndexed];
385
+ let messages = reportedErrors.get(e.nodeName);
386
+ if (!messages) {
387
+ messages = new Set();
388
+ reportedErrors.set(e.nodeName, messages);
389
+ }
390
+ messages.add(e.message);
391
+ }
392
+ return reportedErrors.get(nodeName)?.has(message) ?? false;
393
+ };
369
394
  for (const node of workflow.nodes) {
370
395
  const storedNodeInfo = this.nodeRepository.getNode(node_type_normalizer_1.NodeTypeNormalizer.normalizeToFullForm(node.type));
371
396
  this.checkDeprecatedNode(node, storedNodeInfo, result);
@@ -546,7 +571,7 @@ class WorkflowValidator {
546
571
  this.checkHttpRequestCredential(node, profile, result);
547
572
  if (node.type === 'n8n-nodes-base.if' || node.type === 'n8n-nodes-base.switch' || node.type === 'n8n-nodes-base.filter') {
548
573
  for (const err of (0, n8n_validation_1.validateConditionNodeStructure)(node)) {
549
- if (result.errors.some(e => e.nodeName === node.name && e.message === err))
574
+ if (hasReportedError(node.name, err))
550
575
  continue;
551
576
  result.errors.push({
552
577
  type: 'error',
@@ -1181,12 +1206,10 @@ class WorkflowValidator {
1181
1206
  this.flagOrphanedNodes(workflow, result);
1182
1207
  return;
1183
1208
  }
1184
- const reachable = new Set();
1185
- const queue = [...triggerNodes];
1186
- for (const t of triggerNodes)
1187
- reachable.add(t);
1188
- while (queue.length > 0) {
1189
- const current = queue.shift();
1209
+ const reachable = new Set(triggerNodes);
1210
+ const queue = [...reachable];
1211
+ for (let head = 0; head < queue.length; head++) {
1212
+ const current = queue[head];
1190
1213
  const neighbors = adjacency.get(current);
1191
1214
  if (neighbors) {
1192
1215
  for (const neighbor of neighbors) {
@@ -1214,8 +1237,9 @@ class WorkflowValidator {
1214
1237
  }
1215
1238
  hasCycle(workflow) {
1216
1239
  const visited = new Set();
1217
- const recursionStack = new Set();
1240
+ const pathPosition = new Map();
1218
1241
  const path = [];
1242
+ const exitCounts = [0];
1219
1243
  const nodeTypeMap = new Map();
1220
1244
  const nodeMap = new Map();
1221
1245
  workflow.nodes.forEach(node => {
@@ -1261,9 +1285,16 @@ class WorkflowValidator {
1261
1285
  const outputCount = node ? this.getMainOutputCount(node) : null;
1262
1286
  return outputCount !== null && outputCount > 1;
1263
1287
  };
1288
+ const pathFromHasExit = (start) => {
1289
+ while (exitCounts.length <= path.length) {
1290
+ const k = exitCounts.length - 1;
1291
+ exitCounts.push(exitCounts[k] + (isPotentialCycleExit(path[k]) ? 1 : 0));
1292
+ }
1293
+ return exitCounts[path.length] > exitCounts[start];
1294
+ };
1264
1295
  const hasCycleDFS = (nodeName) => {
1265
1296
  visited.add(nodeName);
1266
- recursionStack.add(nodeName);
1297
+ pathPosition.set(nodeName, path.length);
1267
1298
  path.push(nodeName);
1268
1299
  const connections = workflow.connections[nodeName];
1269
1300
  if (connections) {
@@ -1281,16 +1312,17 @@ class WorkflowValidator {
1281
1312
  if (hasCycleDFS(target))
1282
1313
  return true;
1283
1314
  }
1284
- else if (recursionStack.has(target)) {
1285
- const cycleNodes = path.slice(path.indexOf(target));
1286
- if (!cycleNodes.some(isPotentialCycleExit)) {
1315
+ else if (pathPosition.has(target)) {
1316
+ if (!pathFromHasExit(pathPosition.get(target))) {
1287
1317
  return true;
1288
1318
  }
1289
1319
  }
1290
1320
  }
1291
1321
  }
1292
- recursionStack.delete(nodeName);
1322
+ pathPosition.delete(nodeName);
1293
1323
  path.pop();
1324
+ if (exitCounts.length > path.length + 1)
1325
+ exitCounts.length = path.length + 1;
1294
1326
  return false;
1295
1327
  };
1296
1328
  for (const node of workflow.nodes) {
@@ -1302,7 +1334,7 @@ class WorkflowValidator {
1302
1334
  return false;
1303
1335
  }
1304
1336
  validateExpressions(workflow, result, profile = 'runtime') {
1305
- const nodeNames = workflow.nodes.map(n => n.name);
1337
+ const nodeNameSet = new Set(workflow.nodes.map(n => n.name));
1306
1338
  for (const node of workflow.nodes) {
1307
1339
  if (node.disabled || (0, node_classification_1.isNonExecutableNode)(node.type))
1308
1340
  continue;
@@ -1311,7 +1343,7 @@ class WorkflowValidator {
1311
1343
  continue;
1312
1344
  }
1313
1345
  const context = {
1314
- availableNodes: nodeNames.filter(n => n !== node.name),
1346
+ availableNodes: { has: (name) => name !== node.name && nodeNameSet.has(name) },
1315
1347
  currentNodeName: node.name,
1316
1348
  hasInputData: this.nodeHasInput(node.name, workflow),
1317
1349
  isInLoop: false
@@ -1380,16 +1412,18 @@ class WorkflowValidator {
1380
1412
  return count;
1381
1413
  }
1382
1414
  nodeHasInput(nodeName, workflow) {
1383
- for (const [sourceName, outputs] of Object.entries(workflow.connections)) {
1384
- if (outputs.main) {
1385
- for (const outputConnections of outputs.main) {
1386
- if (outputConnections?.some(conn => conn.node === nodeName)) {
1387
- return true;
1415
+ if (this.mainInputTargets?.workflow !== workflow) {
1416
+ const targets = new Set();
1417
+ for (const outputs of Object.values(workflow.connections)) {
1418
+ if (outputs.main) {
1419
+ for (const outputConnections of outputs.main) {
1420
+ outputConnections?.forEach(conn => targets.add(conn.node));
1388
1421
  }
1389
1422
  }
1390
1423
  }
1424
+ this.mainInputTargets = { workflow, targets };
1391
1425
  }
1392
- return false;
1426
+ return this.mainInputTargets.targets.has(nodeName);
1393
1427
  }
1394
1428
  checkWorkflowPatterns(workflow, result, profile = 'runtime') {
1395
1429
  const advisoryProfile = this.isAdvisoryProfile(profile);
@@ -1427,6 +1461,7 @@ class WorkflowValidator {
1427
1461
  }
1428
1462
  }
1429
1463
  workflowHasErrorHandling(workflow) {
1464
+ const hasWiredMainOutput = new Map();
1430
1465
  return workflow.nodes.some(node => {
1431
1466
  if (node.disabled)
1432
1467
  return false;
@@ -1443,7 +1478,12 @@ class WorkflowValidator {
1443
1478
  return false;
1444
1479
  const errorOutputIndex = this.getMainOutputCount(node);
1445
1480
  if (errorOutputIndex === null) {
1446
- return mainOutputs.some(conns => Array.isArray(conns) && conns.length > 0);
1481
+ let wired = hasWiredMainOutput.get(node.name);
1482
+ if (wired === undefined) {
1483
+ wired = mainOutputs.some(conns => Array.isArray(conns) && conns.length > 0);
1484
+ hasWiredMainOutput.set(node.name, wired);
1485
+ }
1486
+ return wired;
1447
1487
  }
1448
1488
  const errorConnections = mainOutputs[errorOutputIndex];
1449
1489
  return Array.isArray(errorConnections) && errorConnections.length > 0;
@@ -1790,13 +1830,20 @@ class WorkflowValidator {
1790
1830
  result.suggestions.push('Replace "continueOnFail: true" with "onError: \'continueRegularOutput\'" for better UI compatibility and control.');
1791
1831
  }
1792
1832
  }
1833
+ lowerCaseNodeNames(node) {
1834
+ let names = this.lowerCaseNames.get(node);
1835
+ if (!names) {
1836
+ names = { type: node.type.toLowerCase(), name: node.name.toLowerCase() };
1837
+ this.lowerCaseNames.set(node, names);
1838
+ }
1839
+ return names;
1840
+ }
1793
1841
  validateSplitInBatchesConnection(sourceNode, outputIndex, connection, nodeMap, result) {
1794
1842
  const targetNode = nodeMap.get(connection.node);
1795
1843
  if (!targetNode)
1796
1844
  return;
1797
1845
  if (outputIndex === 0) {
1798
- const targetType = targetNode.type.toLowerCase();
1799
- const targetName = targetNode.name.toLowerCase();
1846
+ const { type: targetType, name: targetName } = this.lowerCaseNodeNames(targetNode);
1800
1847
  if (targetType.includes('function') ||
1801
1848
  targetType.includes('code') ||
1802
1849
  targetType.includes('item') ||
@@ -1804,7 +1851,10 @@ class WorkflowValidator {
1804
1851
  targetName.includes('transform') ||
1805
1852
  targetName.includes('handle')) {
1806
1853
  const hasLoopBack = this.checkForLoopBack(targetNode.name, sourceNode.name, nodeMap);
1807
- if (hasLoopBack) {
1854
+ if (hasLoopBack === null) {
1855
+ this.reportIncompleteLoopBackCheck(result);
1856
+ }
1857
+ else if (hasLoopBack) {
1808
1858
  result.errors.push({
1809
1859
  type: 'error',
1810
1860
  nodeId: sourceNode.id,
@@ -1823,8 +1873,7 @@ class WorkflowValidator {
1823
1873
  }
1824
1874
  }
1825
1875
  else if (outputIndex === 1) {
1826
- const targetType = targetNode.type.toLowerCase();
1827
- const targetName = targetNode.name.toLowerCase();
1876
+ const { type: targetType, name: targetName } = this.lowerCaseNodeNames(targetNode);
1828
1877
  if (targetType.includes('aggregate') ||
1829
1878
  targetType.includes('merge') ||
1830
1879
  targetType.includes('email') ||
@@ -1841,7 +1890,10 @@ class WorkflowValidator {
1841
1890
  });
1842
1891
  }
1843
1892
  const hasLoopBack = this.checkForLoopBack(targetNode.name, sourceNode.name, nodeMap);
1844
- if (!hasLoopBack) {
1893
+ if (hasLoopBack === null) {
1894
+ this.reportIncompleteLoopBackCheck(result);
1895
+ }
1896
+ else if (!hasLoopBack) {
1845
1897
  result.warnings.push({
1846
1898
  type: 'warning',
1847
1899
  nodeId: sourceNode.id,
@@ -1851,35 +1903,61 @@ class WorkflowValidator {
1851
1903
  }
1852
1904
  }
1853
1905
  }
1854
- checkForLoopBack(startNode, targetNode, nodeMap, visited = new Set(), maxDepth = 50) {
1906
+ checkForLoopBack(startNode, targetNode, nodeMap) {
1907
+ let entry = this.loopBackReach.get(startNode);
1908
+ if (!entry) {
1909
+ const reached = new Set();
1910
+ const complete = this.collectLoopBackReach(startNode, nodeMap, new Set(), 50, reached);
1911
+ entry = { reached, complete };
1912
+ this.loopBackReach.set(startNode, entry);
1913
+ }
1914
+ if (entry.reached.has(targetNode))
1915
+ return true;
1916
+ return entry.complete ? false : null;
1917
+ }
1918
+ collectLoopBackReach(startNode, nodeMap, visited, maxDepth, reached) {
1855
1919
  if (maxDepth <= 0)
1856
- return false;
1920
+ return true;
1857
1921
  if (visited.has(startNode))
1858
- return false;
1922
+ return true;
1859
1923
  visited.add(startNode);
1860
1924
  const node = nodeMap.get(startNode);
1861
1925
  if (!node)
1862
- return false;
1926
+ return true;
1863
1927
  const connections = this.currentWorkflow?.connections[startNode];
1864
1928
  if (!connections)
1929
+ return true;
1930
+ if (this.loopBackSteps <= 0)
1865
1931
  return false;
1866
- for (const [outputType, outputs] of Object.entries(connections)) {
1932
+ for (const outputs of Object.values(connections)) {
1933
+ if (--this.loopBackSteps < 0)
1934
+ return false;
1867
1935
  if (!Array.isArray(outputs))
1868
1936
  continue;
1869
1937
  for (const outputConnections of outputs) {
1938
+ if (--this.loopBackSteps < 0)
1939
+ return false;
1870
1940
  if (!Array.isArray(outputConnections))
1871
1941
  continue;
1872
1942
  for (const conn of outputConnections) {
1873
- if (conn.node === targetNode) {
1874
- return true;
1875
- }
1876
- if (this.checkForLoopBack(conn.node, targetNode, nodeMap, visited, maxDepth - 1)) {
1877
- return true;
1878
- }
1943
+ if (--this.loopBackSteps < 0)
1944
+ return false;
1945
+ reached.add(conn.node);
1946
+ if (!this.collectLoopBackReach(conn.node, nodeMap, visited, maxDepth - 1, reached))
1947
+ return false;
1879
1948
  }
1880
1949
  }
1881
1950
  }
1882
- return false;
1951
+ return true;
1952
+ }
1953
+ reportIncompleteLoopBackCheck(result) {
1954
+ if (this.loopBackIncompleteReported)
1955
+ return;
1956
+ this.loopBackIncompleteReported = true;
1957
+ result.warnings.push({
1958
+ type: 'warning',
1959
+ message: 'The workflow\'s loop structure is too large to check fully. Some SplitInBatches loop-back checks were skipped.'
1960
+ });
1883
1961
  }
1884
1962
  addErrorRecoverySuggestions(result) {
1885
1963
  const errorTypes = {