n8n_create_workflow
Create new n8n workflows with nodes and connections for automation, starting in inactive state for configuration before activation.
Instructions
Create a new workflow with nodes and connections. The workflow will be created in inactive state.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the workflow | |
| nodes | Yes | Array of node objects. Each node needs: id, name, type, typeVersion, position [x,y], parameters | |
| connections | Yes | Connection mapping between nodes. Format: { "sourceNode": { "main": [[{ "node": "targetNode", "type": "main", "index": 0 }]] } } | |
| settings | No | Optional workflow settings |
Implementation Reference
- src/tools/workflow-tools.ts:229-272 (handler)The async handler function that implements the core logic of n8n_create_workflow tool. Validates inputs, calls N8nApiClient.createWorkflow, and returns success response.n8n_create_workflow: async ( client: N8nApiClient, args: Record<string, unknown> ): Promise<ToolResult> => { const name = args.name as string; const nodes = args.nodes as N8nNode[]; const connections = args.connections as N8nConnections; const settings = args.settings as N8nWorkflowSettings | undefined; if (!name) { throw new Error('Workflow name is required'); } if (!nodes || !Array.isArray(nodes)) { throw new Error('Nodes array is required'); } if (!connections) { throw new Error('Connections object is required'); } const workflow = await client.createWorkflow({ name, nodes, connections, settings, }); return { content: [ { type: 'text' as const, text: JSON.stringify({ success: true, message: `Workflow "${workflow.name}" created successfully`, workflow: { id: workflow.id, name: workflow.name, active: workflow.active, nodeCount: workflow.nodes.length, }, }, null, 2), }, ], }; },
- src/tools/workflow-tools.ts:45-86 (schema)The ToolDefinition object specifying the input schema, description, and required parameters for the n8n_create_workflow tool.{ name: 'n8n_create_workflow', description: 'Create a new workflow with nodes and connections. The workflow will be created in inactive state.', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the workflow', }, nodes: { type: 'array', description: 'Array of node objects. Each node needs: id, name, type, typeVersion, position [x,y], parameters', items: { type: 'object', properties: { id: { type: 'string' }, name: { type: 'string' }, type: { type: 'string', description: 'e.g., "n8n-nodes-base.webhook", "n8n-nodes-base.httpRequest"' }, typeVersion: { type: 'number' }, position: { type: 'array', items: { type: 'number' } }, parameters: { type: 'object' }, }, required: ['id', 'name', 'type', 'typeVersion', 'position', 'parameters'], }, }, connections: { type: 'object', description: 'Connection mapping between nodes. Format: { "sourceNode": { "main": [[{ "node": "targetNode", "type": "main", "index": 0 }]] } }', }, settings: { type: 'object', description: 'Optional workflow settings', properties: { executionOrder: { type: 'string', enum: ['v0', 'v1'] }, timezone: { type: 'string' }, }, }, }, required: ['name', 'nodes', 'connections'], }, },
- src/server.ts:60-64 (registration)MCP server handler for listing tools, which includes the n8n_create_workflow schema from allTools.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: allTools, }; });
- src/server.ts:122-126 (registration)Dispatch logic in MCP tool call handler that routes calls to workflowToolHandlers, including n8n_create_workflow.if (name in workflowToolHandlers) { const handler = workflowToolHandlers[name as keyof typeof workflowToolHandlers]; return handler(client, args); }
- src/tools/index.ts:12-16 (registration)Aggregation of all tool definitions into allTools array, spreading workflowTools which includes n8n_create_workflow.export const allTools: ToolDefinition[] = [ ...documentationTools, // Documentation first for discoverability ...workflowTools, ...executionTools, ];