create_workflow
Build automated workflows by defining nodes and connections to streamline business processes and integrate applications.
Instructions
Create a new n8n workflow
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| nodes | Yes | ||
| connections | Yes | ||
| active | No | ||
| tags | No |
Implementation Reference
- src/index.ts:71-71 (registration)Registration of the 'create_workflow' MCP tool, including 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:400-404 (handler)MCP server handler for 'create_workflow': calls N8nClient.createWorkflow, adds numeric ID alias, returns JSON responseprivate 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/index.ts:230-231 (handler)Switch case in CallToolRequestHandler dispatching 'create_workflow' calls to the handler methodcase 'create_workflow': return await this.handleCreateWorkflow(request.params.arguments as Omit<N8nWorkflow, 'id'>);
- src/n8n-client.ts:175-194 (helper)Core N8nClient implementation: resolves credential aliases, sanitizes workflow (settings/tags/active), POSTs to n8n /workflows endpointasync 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/types.ts:1-13 (schema)TypeScript interface N8nWorkflow defining the structure expected for create_workflow input (Omit<..., 'id'>)export interface N8nWorkflow { id?: string | number; name: string; nodes: N8nNode[]; connections: N8nConnections; active?: boolean; settings?: Record<string, any>; staticData?: Record<string, any>; tags?: string[]; pinData?: Record<string, any>; versionId?: string; meta?: Record<string, any>; }