Skip to main content
Glama

connect

Create connections between workflow nodes to establish data flow and automate processes in McFlow's n8n workflow management system.

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

Implementation Reference

  • Core handler function that implements the connect tool logic: reads workflow JSON, adds connection from sourceNode to targetNode, writes back the file, and returns 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}`);
      }
    }
  • Schema definition for the 'connect' tool, including input parameters and requirements.
    {
      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'],
      },
    },
  • MCP server registration: sets handlers for listing tools (schemas via getToolDefinitions()) and calling tools (dispatches to ToolHandler.handleTool).
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: getToolDefinitions(),
    }));
    
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      return await this.toolHandler.handleTool(
        request.params.name,
        request.params.arguments
      );
    });
  • ToolHandler switch case that handles 'connect' tool calls by invoking the connectNodes function.
    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