Skip to main content
Glama

add_node

Add a functional n8n node to workflow files with specified position, enabling workflow development and automation.

Instructions

Add a REAL n8n node to workflow (no mock/placeholder nodes allowed)

Input Schema

NameRequiredDescriptionDefault
nodeYesThe node to add
pathYesPath to the workflow file
positionNoPosition for the new node

Input Schema (JSON Schema)

{ "properties": { "node": { "description": "The node to add", "type": "object" }, "path": { "description": "Path to the workflow file", "type": "string" }, "position": { "description": "Position for the new node", "properties": { "x": { "type": "number" }, "y": { "type": "number" } }, "type": "object" } }, "required": [ "path", "node" ], "type": "object" }

Implementation Reference

  • The core handler function that reads the workflow JSON, appends the new node (setting position if provided), writes back to file, and returns a confirmation message.
    export async function addNodeToWorkflow( workflowsPath: string, workflowPath: string, node: any, position?: any ): Promise<any> { try { const fullPath = path.join(workflowsPath, workflowPath); const content = await fs.readFile(fullPath, 'utf-8'); const workflow = JSON.parse(content); if (!workflow.nodes) { workflow.nodes = []; } if (position) { node.position = [position.x || 250, position.y || 300]; } else { const lastNode = workflow.nodes[workflow.nodes.length - 1]; if (lastNode && lastNode.position) { node.position = [lastNode.position[0] + 250, lastNode.position[1]]; } else { node.position = [250, 300]; } } workflow.nodes.push(node); await fs.writeFile(fullPath, JSON.stringify(workflow, null, 2)); return { content: [ { type: 'text', text: `Node added to workflow: ${node.id}`, }, ], }; } catch (error) { throw new Error(`Failed to add node: ${error}`); } }
  • Registers the 'add_node' tool in the MCP tool definitions array, including its description and input schema.
    name: 'add_node', description: 'Add a REAL n8n node to workflow (no mock/placeholder nodes allowed)', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file', }, node: { type: 'object', description: 'The node to add', }, position: { type: 'object', properties: { x: { type: 'number' }, y: { type: 'number' }, }, description: 'Position for the new node', }, }, required: ['path', 'node'], }, },
  • Dispatches the 'add_node' tool call within the main ToolHandler.handleTool switch statement, passing workflow path, node, and position to the implementation function.
    case 'add_node': return await addNodeToWorkflow( this.workflowsPath, args?.path as string, args?.node as any, args?.position as any );
  • Defines the input schema for the 'add_node' tool, specifying required path and node parameters, optional position.
    inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file', }, node: { type: 'object', description: 'The node to add', }, position: { type: 'object', properties: { x: { type: 'number' }, y: { type: 'number' }, }, description: 'Position for the new node', }, }, required: ['path', 'node'], }, },

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