connect
Create connections between workflow nodes to establish data flow and automate processes in McFlow's n8n workflow management system.
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 | |
| targetNode | Yes | ID of the target node | |
| sourceOutput | No | Output type from source node (default: main) | |
| targetInput | No | Input type for target node (default: main) |
Implementation Reference
- src/workflows/operations.ts:47-96 (handler)Core handler function that implements the connect tool logic: reads workflow JSON, adds connection from sourceNode to targetNode, writes back the file, and returns 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:148-177 (schema)Schema definition for the 'connect' tool, including input parameters and requirements.{ 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/server/mcflow.ts:76-85 (registration)MCP server registration: sets handlers for listing tools (schemas via getToolDefinitions()) and calling tools (dispatches to ToolHandler.handleTool).this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: getToolDefinitions(), })); this.server.setRequestHandler(CallToolRequestSchema, async (request) => { return await this.toolHandler.handleTool( request.params.name, request.params.arguments ); });
- src/tools/handler.ts:90-98 (handler)ToolHandler switch case that handles 'connect' tool calls by invoking the connectNodes function.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 );