Skip to main content
Glama

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
NameRequiredDescriptionDefault
workflowIdYes
sourceYes
targetYes
sourceIndexNo
targetIndexNo

Implementation Reference

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

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/Souzix76/n8n-workflow-tester-safe'

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