Skip to main content
Glama

connect_nodes

Link workflow nodes to establish data flow between them in n8n automation processes. Specify source and destination nodes to create connections that enable automated task execution.

Instructions

Connect two nodes in an n8n workflow

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromYes
toYes
workflowIdYes

Implementation Reference

  • Core handler that connects nodes by modifying the workflow connections structure with optimistic concurrency control 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 that delegates to N8nClient.connectNodes and formats the JSON 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-213 (registration)
    Tool registration in the MCP server's ListTools response, including 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'] } },
  • TypeScript interfaces defining the request and response 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; }

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