Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesPath to the workflow file
sourceNodeYesID of the source node
sourceOutputNoOutput type from source node (default: main)
targetInputNoInput type for target node (default: main)
targetNodeYesID of the target node

Implementation Reference

  • 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}`); } }
  • 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'], }, },
  • 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 );

Latest Blog Posts

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/mckinleymedia/mcflow-mcp'

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