Skip to main content
Glama

connect_nodes

Link two nodes in an n8n workflow to establish data flow between automation steps.

Instructions

Connect two nodes in an n8n workflow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflowIdYes
fromYes
toYes

Implementation Reference

  • Core implementation of connect_nodes tool. Updates the workflow's connections by linking the output of the 'from' node to the input of the 'to' node, with optimistic concurrency via performWorkflowUpdate.
    async connectNodes(request: ConnectNodesRequest): Promise<ConnectNodesResponse> { await this.performWorkflowUpdate(request.workflowId, (workflow) => { const fromNode = workflow.nodes.find((node) => node.id === request.from.nodeId); const toNode = workflow.nodes.find((node) => node.id === request.to.nodeId); if (!fromNode) throw new Error(`Source node ${request.from.nodeId} not found in workflow ${request.workflowId}`); if (!toNode) throw new Error(`Target node ${request.to.nodeId} not found in workflow ${request.workflowId}`); const connections: any = workflow.connections as any; if (!connections[fromNode.name]) connections[fromNode.name] = {}; const fromMain = connections[fromNode.name].main || []; connections[fromNode.name].main = fromMain; const outputIndex = request.from.outputIndex ?? 0; if (!fromMain[outputIndex]) fromMain[outputIndex] = []; const connection = { node: toNode.name, type: 'main', index: request.to.inputIndex ?? 0 }; const exists = fromMain[outputIndex].some((conn: any) => conn.node === connection.node && conn.index === connection.index); if (!exists) fromMain[outputIndex].push(connection); }); return { ok: true }; }
  • MCP server handler method that receives the tool call and delegates to N8nClient.connectNodes, formatting the response.
    private async handleConnectNodes(args: ConnectNodesRequest) { const result = await this.n8nClient.connectNodes(args); return { content: [ { type: 'text', text: JSON.stringify(jsonSuccess(result), null, 2), }, ], };
  • src/index.ts:213-215 (registration)
    Tool registration in the listTools handler, defining name, description, and input schema.
    { name: 'connect_nodes', description: 'Connect two nodes in an n8n workflow', inputSchema: { type: 'object', properties: { workflowId: { oneOf: [{ type: 'string' }, { type: 'number' }] }, from: { type: 'object', properties: { nodeId: { type: 'string' }, outputIndex: { type: 'number' } }, required: ['nodeId'] }, to: { type: 'object', properties: { nodeId: { type: 'string' }, inputIndex: { type: 'number' } }, required: ['nodeId'] } }, required: ['workflowId', 'from', 'to'] } }, { name: 'delete_node', description: 'Delete a node from an n8n workflow', inputSchema: { type: 'object', properties: { workflowId: { oneOf: [{ type: 'string' }, { type: 'number' }] }, nodeId: { type: 'string' } }, required: ['workflowId', 'nodeId'] } }, { name: 'set_node_position', description: 'Set the position of a node in an n8n workflow', inputSchema: { type: 'object', properties: { workflowId: { oneOf: [{ type: 'string' }, { type: 'number' }] }, nodeId: { type: 'string' }, x: { type: 'number' }, y: { type: 'number' } }, required: ['workflowId', 'nodeId', 'x', 'y'] } },
  • TypeScript interfaces defining the input (ConnectNodesRequest) and output (ConnectNodesResponse) shapes for the connect_nodes tool.
    export interface ConnectNodesRequest { workflowId: string | number; from: { nodeId: string; outputIndex?: number; }; to: { nodeId: string; inputIndex?: number; }; } export interface ConnectNodesResponse { ok: true; }
  • src/index.ts:319-320 (registration)
    Tool dispatch routing in the CallToolRequest handler switch statement.
    case 'connect_nodes': return await this.handleConnectNodes(request.params.arguments as unknown as ConnectNodesRequest);

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/get2knowio/n8n-mcp'

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