create_workflow
Create a new n8n workflow by defining nodes, connections, and configuration to automate business processes and data flows.
Instructions
Create a new n8n workflow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active | No | ||
| connections | Yes | ||
| name | Yes | ||
| nodes | Yes | ||
| tags | No |
Implementation Reference
- src/index.ts:71-71 (registration)Tool registration in list_tools response, including name, description, and input schema definition{ name: 'create_workflow', description: 'Create a new n8n workflow', inputSchema: { type: 'object', properties: { name: { type: 'string' }, nodes: { type: 'array', items: { type: 'object' } }, connections: { type: 'object' }, active: { type: 'boolean', default: false }, tags: { type: 'array', items: { type: 'string' } } }, required: ['name', 'nodes', 'connections'] } },
- src/index.ts:230-231 (handler)Handler dispatch in CallToolRequestSchema switch statement routing create_workflow callscase 'create_workflow': return await this.handleCreateWorkflow(request.params.arguments as Omit<N8nWorkflow, 'id'>);
- src/index.ts:400-403 (handler)Primary MCP tool handler function that delegates to n8nClient.createWorkflow and formats response with alias and JSON success wrapperprivate async handleCreateWorkflow(args: Omit<N8nWorkflow, 'id'>) { const workflow = await this.n8nClient.createWorkflow(args); this.withAlias(workflow); return { content: [{ type: 'text', text: JSON.stringify(jsonSuccess(workflow), null, 2) }] };
- src/n8n-client.ts:175-194 (helper)Core implementation in N8nClient that preprocesses workflow (credentials, settings, tags, active), calls n8n /workflows POST API, and normalizes responseasync createWorkflow(workflow: Omit<N8nWorkflow, 'id'>): Promise<N8nWorkflow> { // Resolve credential aliases before creating the workflow await this.resolveCredentialsInWorkflow(workflow); // Ensure required fields expected by n8n API if ((workflow as any).settings == null) { (workflow as any).settings = {}; } // Some n8n deployments may not accept non-numeric tag values on create. // If tags are provided as strings (names), omit them here; users can set numeric tag IDs via setWorkflowTags. if (Array.isArray((workflow as any).tags) && (workflow as any).tags.some((t: any) => typeof t !== 'number')) { delete (workflow as any).tags; } // 'active' is managed via dedicated activate/deactivate endpoints; omit on create if ('active' in (workflow as any)) { delete (workflow as any).active; } const response = await this.api.post<N8nApiResponse<N8nWorkflow> | N8nWorkflow>('/workflows', workflow); const payload: any = response.data as any; return (payload && typeof payload === 'object' && 'data' in payload) ? payload.data : payload; }
- src/n8n-client.ts:253-270 (helper)Supporting helper that resolves credential aliases in workflow nodes before API submissionasync resolveCredentialsInWorkflow(workflow: Omit<N8nWorkflow, 'id'> | Partial<N8nWorkflow>): Promise<void> { if (!workflow.nodes) return; for (const node of workflow.nodes) { if (node.credentials) { for (const [credType, credValue] of Object.entries(node.credentials)) { // If the value doesn't look like an ID (not all digits), try to resolve as alias if (credValue && !/^\d+$/.test(credValue)) { try { node.credentials[credType] = await this.resolveCredentialAlias(credValue); } catch (error) { throw new Error(`Failed to resolve credential alias '${credValue}' for node '${node.name}': ${error instanceof Error ? error.message : String(error)}`); } } } } } }