n8n_create_workflow
Create automation workflows by defining nodes and connections. Specify workflow name, node array, and connection object to build and optionally activate workflows.
Instructions
Create a new automation workflow with nodes and connections. Provide workflow name, node array, and connection object. Optionally activate immediately. Returns new workflow with assigned ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Descriptive workflow name | |
| nodes | Yes | Array of node objects with type, parameters, position | |
| connections | Yes | Connection map linking node outputs to inputs | |
| active | No | Start workflow immediately (default: false) |
Implementation Reference
- src/n8n-client.ts:62-67 (handler)The createWorkflow method in N8nClient class that executes the tool logic. It makes a POST request to the n8n API endpoint /api/v1/workflows with the workflow data (name, nodes, connections, active) serialized as JSON.
async createWorkflow(workflow: any) { return this.request(`${this.apiBase}/workflows`, { method: 'POST', body: JSON.stringify(workflow), }); } - src/tools.ts:43-62 (schema)The tool definition/schema for n8n_create_workflow. Defines the tool name, description, inputSchema with required properties (name, nodes, connections) and optional 'active' property, plus annotations for MCP capabilities.
name: 'n8n_create_workflow', description: 'Create a new automation workflow with nodes and connections. Provide workflow name, node array, and connection object. Optionally activate immediately. Returns new workflow with assigned ID.', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Descriptive workflow name' }, nodes: { type: 'array', description: 'Array of node objects with type, parameters, position' }, connections: { type: 'object', description: 'Connection map linking node outputs to inputs' }, active: { type: 'boolean', description: 'Start workflow immediately (default: false)' }, }, required: ['name', 'nodes', 'connections'], }, annotations: { title: 'Create Workflow', readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, }, }, - src/server.ts:22-30 (registration)The handleToolCall function routes tool calls to appropriate handlers. Line 29-30 shows n8n_create_workflow case delegating to client.createWorkflow(args).
export async function handleToolCall(toolName: string, args: any, client: N8nClient): Promise<any> { switch (toolName) { // Workflow operations case 'n8n_list_workflows': return client.listWorkflows(args); case 'n8n_get_workflow': return client.getWorkflow(args.id); case 'n8n_create_workflow': return client.createWorkflow(args); - src/n8n-client.ts:25-47 (helper)The private request method that handles all HTTP requests to the n8n API. Includes authentication via X-N8N-API-KEY header, timeout handling, and error response handling.
private async request<T>( endpoint: string, options: RequestInit = {} ): Promise<T> { const url = `${this.config.apiUrl}${endpoint}`; const response = await fetch(url, { ...options, signal: AbortSignal.timeout(this.timeout), headers: { 'X-N8N-API-KEY': this.config.apiKey, 'Content-Type': 'application/json', ...options.headers, }, }); if (!response.ok) { const error = await response.text(); throw new Error(`n8n API Error (${response.status}): ${error}`); } return response.json() as Promise<T>; }