mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-03-20 17:33:08 +00:00
Add transferWorkflow diff operation to move workflows between n8n projects:
- TransferWorkflowOperation type with destinationProjectId field
- WorkflowDiffEngine validates and tracks transfer intent
- Handler calls PUT /workflows/{id}/transfer after update
- N8nApiClient.transferWorkflow() method
- Zod schema validates destinationProjectId is non-empty
- Tool description and documentation updated
- inferIntentFromOperations case for transfer
Also fixes two pre-existing bugs found during review:
- continueOnError path now properly extracts/propagates activation flags
- Debug log in updateConnectionReferences shows correct old name
Based on work by @djakielski in PR #645.
Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en
This commit is contained in:
committed by
GitHub
parent
14962a39b6
commit
47a1cb135d
30
dist/services/workflow-diff-engine.js
vendored
30
dist/services/workflow-diff-engine.js
vendored
@@ -23,6 +23,7 @@ class WorkflowDiffEngine {
|
||||
this.removedNodeNames.clear();
|
||||
this.tagsToAdd = [];
|
||||
this.tagsToRemove = [];
|
||||
this.transferToProjectId = undefined;
|
||||
const workflowCopy = JSON.parse(JSON.stringify(workflow));
|
||||
const nodeOperationTypes = ['addNode', 'removeNode', 'updateNode', 'moveNode', 'enableNode', 'disableNode'];
|
||||
const nodeOperations = [];
|
||||
@@ -81,6 +82,10 @@ class WorkflowDiffEngine {
|
||||
failed: failedIndices
|
||||
};
|
||||
}
|
||||
const shouldActivate = workflowCopy._shouldActivate === true;
|
||||
const shouldDeactivate = workflowCopy._shouldDeactivate === true;
|
||||
delete workflowCopy._shouldActivate;
|
||||
delete workflowCopy._shouldDeactivate;
|
||||
const success = appliedIndices.length > 0;
|
||||
return {
|
||||
success,
|
||||
@@ -91,8 +96,11 @@ class WorkflowDiffEngine {
|
||||
warnings: this.warnings.length > 0 ? this.warnings : undefined,
|
||||
applied: appliedIndices,
|
||||
failed: failedIndices,
|
||||
shouldActivate: shouldActivate || undefined,
|
||||
shouldDeactivate: shouldDeactivate || undefined,
|
||||
tagsToAdd: this.tagsToAdd.length > 0 ? this.tagsToAdd : undefined,
|
||||
tagsToRemove: this.tagsToRemove.length > 0 ? this.tagsToRemove : undefined
|
||||
tagsToRemove: this.tagsToRemove.length > 0 ? this.tagsToRemove : undefined,
|
||||
transferToProjectId: this.transferToProjectId || undefined
|
||||
};
|
||||
}
|
||||
else {
|
||||
@@ -181,7 +189,8 @@ class WorkflowDiffEngine {
|
||||
shouldActivate: shouldActivate || undefined,
|
||||
shouldDeactivate: shouldDeactivate || undefined,
|
||||
tagsToAdd: this.tagsToAdd.length > 0 ? this.tagsToAdd : undefined,
|
||||
tagsToRemove: this.tagsToRemove.length > 0 ? this.tagsToRemove : undefined
|
||||
tagsToRemove: this.tagsToRemove.length > 0 ? this.tagsToRemove : undefined,
|
||||
transferToProjectId: this.transferToProjectId || undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -220,6 +229,8 @@ class WorkflowDiffEngine {
|
||||
case 'addTag':
|
||||
case 'removeTag':
|
||||
return null;
|
||||
case 'transferWorkflow':
|
||||
return this.validateTransferWorkflow(workflow, operation);
|
||||
case 'activateWorkflow':
|
||||
return this.validateActivateWorkflow(workflow, operation);
|
||||
case 'deactivateWorkflow':
|
||||
@@ -285,6 +296,9 @@ class WorkflowDiffEngine {
|
||||
case 'replaceConnections':
|
||||
this.applyReplaceConnections(workflow, operation);
|
||||
break;
|
||||
case 'transferWorkflow':
|
||||
this.applyTransferWorkflow(workflow, operation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
validateAddNode(workflow, operation) {
|
||||
@@ -699,6 +713,15 @@ class WorkflowDiffEngine {
|
||||
applyDeactivateWorkflow(workflow, operation) {
|
||||
workflow._shouldDeactivate = true;
|
||||
}
|
||||
validateTransferWorkflow(_workflow, operation) {
|
||||
if (!operation.destinationProjectId) {
|
||||
return 'transferWorkflow requires a non-empty destinationProjectId string';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
applyTransferWorkflow(_workflow, operation) {
|
||||
this.transferToProjectId = operation.destinationProjectId;
|
||||
}
|
||||
validateCleanStaleConnections(workflow, operation) {
|
||||
return null;
|
||||
}
|
||||
@@ -806,9 +829,10 @@ class WorkflowDiffEngine {
|
||||
for (let connIndex = 0; connIndex < connectionsAtIndex.length; connIndex++) {
|
||||
const connection = connectionsAtIndex[connIndex];
|
||||
if (renames.has(connection.node)) {
|
||||
const oldTargetName = connection.node;
|
||||
const newTargetName = renames.get(connection.node);
|
||||
connection.node = newTargetName;
|
||||
logger.debug(`Updated connection: ${sourceName}[${outputType}][${outputIndex}][${connIndex}].node: "${connection.node}" → "${newTargetName}"`);
|
||||
logger.debug(`Updated connection: ${sourceName}[${outputType}][${outputIndex}][${connIndex}].node: "${oldTargetName}" → "${newTargetName}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user