connect
Create connections between workflow nodes to establish data flow paths and define execution sequences in n8n automation processes.
Instructions
Create a connection between two nodes in a workflow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the workflow file | |
| sourceNode | Yes | ID of the source node | |
| sourceOutput | No | Output type from source node (default: main) | |
| targetInput | No | Input type for target node (default: main) | |
| targetNode | Yes | ID of the target node |
Implementation Reference
- src/workflows/operations.ts:47-96 (handler)The core handler function that implements the 'connect' tool logic: reads the workflow JSON, adds the specified connection between source and target nodes in the connections object, writes the updated workflow back to file, and returns a success message.export async function connectNodes( workflowsPath: string, workflowPath: string, sourceNode: string, targetNode: string, sourceOutput: string = 'main', targetInput: string = 'main' ): Promise<any> { try { const fullPath = path.join(workflowsPath, workflowPath); const content = await fs.readFile(fullPath, 'utf-8'); const workflow = JSON.parse(content); if (!workflow.connections) { workflow.connections = {}; } if (!workflow.connections[sourceNode]) { workflow.connections[sourceNode] = {}; } if (!workflow.connections[sourceNode][sourceOutput]) { workflow.connections[sourceNode][sourceOutput] = []; } const outputIndex = 0; if (!workflow.connections[sourceNode][sourceOutput][outputIndex]) { workflow.connections[sourceNode][sourceOutput][outputIndex] = []; } workflow.connections[sourceNode][sourceOutput][outputIndex].push({ node: targetNode, type: targetInput, index: 0, }); await fs.writeFile(fullPath, JSON.stringify(workflow, null, 2)); return { content: [ { type: 'text', text: `Connected ${sourceNode} -> ${targetNode}`, }, ], }; } catch (error) { throw new Error(`Failed to connect nodes: ${error}`); } }
- src/tools/registry.ts:149-177 (schema)The tool schema definition including name, description, and inputSchema for validation in getToolDefinitions().name: 'connect', description: 'Create a connection between two nodes in a workflow', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file', }, sourceNode: { type: 'string', description: 'ID of the source node', }, targetNode: { type: 'string', description: 'ID of the target node', }, sourceOutput: { type: 'string', description: 'Output type from source node (default: main)', }, targetInput: { type: 'string', description: 'Input type for target node (default: main)', }, }, required: ['path', 'sourceNode', 'targetNode'], }, },
- src/tools/handler.ts:90-98 (registration)The dispatch/registration in ToolHandler.handleTool switch statement that handles 'connect' tool calls by invoking the connectNodes implementation.case 'connect': return await connectNodes( this.workflowsPath, args?.path as string, args?.sourceNode as string, args?.targetNode as string, args?.sourceOutput as string, args?.targetInput as string );