connect_nodes
Create connections between workflow nodes to establish data flow paths for testing and validation in n8n workflows.
Instructions
Create a main connection between two nodes in an existing workflow.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workflowId | Yes | ||
| source | Yes | ||
| target | Yes | ||
| sourceIndex | No | ||
| targetIndex | No |
Implementation Reference
- src/index.ts:246-256 (handler)MCP request handler for 'connect_nodes' tool - validates input parameters using Zod schema and calls the connectNodes function
if (name === 'connect_nodes') { const { workflowId, source, target, sourceIndex, targetIndex } = z.object({ workflowId: z.string(), source: z.string(), target: z.string(), sourceIndex: z.number().optional(), targetIndex: z.number().optional(), }).parse(args); const updated = await connectNodes(workflowId, source, target, sourceIndex ?? 0, targetIndex ?? 0); return { content: [{ type: 'text', text: JSON.stringify(updated, null, 2) }] }; } - src/n8n-client.ts:137-149 (handler)Core implementation of connectNodes - fetches workflow, manages connections array structure, adds new connection between source and target nodes, and updates the workflow via n8n API
export async function connectNodes(workflowId: string, source: string, target: string, sourceIndex = 0, targetIndex = 0) { const workflow = await getWorkflow(workflowId); const connections = workflow.connections && typeof workflow.connections === 'object' ? workflow.connections : {}; const existing = (connections[source] && connections[source].main) ? connections[source].main : []; const next = [...existing]; while (next.length <= sourceIndex) next.push([]); next[sourceIndex] = [ ...(Array.isArray(next[sourceIndex]) ? next[sourceIndex] : []), { node: target, type: 'main', index: targetIndex }, ]; workflow.connections = { ...connections, [source]: { main: next } }; return await updateWorkflow(workflowId, workflow); } - src/index.ts:85-99 (registration)Tool registration defining the 'connect_nodes' tool metadata and input schema with workflowId, source, target (required) and sourceIndex, targetIndex (optional) parameters
{ name: 'connect_nodes', description: 'Create a main connection between two nodes in an existing workflow.', inputSchema: { type: 'object', properties: { workflowId: { type: 'string' }, source: { type: 'string' }, target: { type: 'string' }, sourceIndex: { type: 'number' }, targetIndex: { type: 'number' } }, required: ['workflowId', 'source', 'target'], }, },