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
| Name | Required | Description | Default |
|---|---|---|---|
| node | Yes | The node to add | |
| path | Yes | Path to the workflow file | |
| position | No | Position 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
- src/workflows/operations.ts:4-45 (handler)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}`); } }
- src/tools/registry.ts:123-147 (registration)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'], }, },
- src/tools/handler.ts:82-88 (handler)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 );
- src/tools/registry.ts:125-147 (schema)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'], }, },