add_node
Add functional n8n nodes to workflows by specifying file path, node configuration, and positioning for enhanced automation development.
Instructions
Add a REAL n8n node to workflow (no mock/placeholder nodes allowed)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the workflow file | |
| node | Yes | The node to add | |
| position | No | Position for the new node |
Implementation Reference
- src/workflows/operations.ts:4-45 (handler)Core implementation of the add_node tool: reads workflow JSON, appends the provided node (with auto-positioning if not specified), persists changes to file, returns success 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}`); } }
- src/tools/handler.ts:82-88 (handler)ToolHandler switch case that routes 'add_node' tool invocations to the addNodeToWorkflow implementation, passing workflowsPath and parsed arguments.case 'add_node': return await addNodeToWorkflow( this.workflowsPath, args?.path as string, args?.node as any, args?.position as any );
- src/tools/registry.ts:122-147 (registration)Registers the 'add_node' MCP tool including its name, description, and input schema validation.{ 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'], }, },
- src/tools/registry.ts:125-146 (schema)Input schema defining parameters for add_node: path (required), node (required), optional position with x/y coordinates.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'], },