create_workflow
Build and store new workflows by specifying a workflow name and project directory, enabling efficient process automation with n8n.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workflow_name | Yes | The name for the new workflow | |
| workspace_dir | Yes | Absolute path to the project root directory where workflow_data will be stored |
Implementation Reference
- src/tools/workflowCreation.js:35-96 (handler)The core handler function that implements the create_workflow tool logic. It logs security event, generates UUID, builds initial n8n workflow JSON structure, determines file path, saves via workflowStorage, and returns workflow ID, data, and path.const createWorkflowExecute = async (params) => { const { name, workflow_filename, description = '', active = false, settings = {}, userId } = params; // Security logging logSecurityEvent({ level: 'info', eventType: 'workflow_create', userId: userId || 'anonymous', details: { name, active, workflow_filename } }); // Generate a unique ID for the workflow const workflowId = uuidv4(); // Create basic workflow structure const workflow = { id: workflowId, name, description, active, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), settings: { saveExecutionProgress: true, saveManualExecutions: true, saveDataErrorExecution: 'all', saveDataSuccessExecution: 'all', executionTimeout: 3600, ...settings }, nodes: [], connections: {}, pinData: {}, staticData: null, tags: [] }; // Determine the file path let filePath; if (workflow_filename) { // Ensure filename ends with .json const filename = workflow_filename.endsWith('.json') ? workflow_filename : `${workflow_filename}.json`; filePath = path.join(DEFAULT_WORKFLOW_DIR, filename); } else { filePath = path.join(DEFAULT_WORKFLOW_DIR, `${workflowId}.json`); } // Save the workflow await workflowStorage.saveWorkflow(workflowId, workflow, filePath); logger.info(`Created new workflow: ${name} (${workflowId}) at ${filePath}`); return { workflowId, workflowData: workflow, filePath }; };
- src/tools/toolDefinitions.js:62-109 (schema)Schema and definition for the 'workflow_create' tool, including input parameters (name required, others optional) and output structure (workflowId, workflowData, filePath). Note: this is in individualToolDefinitions, may be for reference.workflow_create: { name: 'workflow_create', description: 'Create a new workflow', execute: createWorkflowExecute, input_schema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the workflow' }, workflow_filename: { type: 'string', description: 'Custom filename for the workflow (optional)' }, description: { type: 'string', description: 'Description of the workflow' }, active: { type: 'boolean', description: 'Whether the workflow should be active' }, settings: { type: 'object', description: 'Workflow settings' } }, required: ['name'] }, output_schema: { type: 'object', properties: { workflowId: { type: 'string', description: 'ID of the created workflow' }, workflowData: { type: 'object', description: 'Full workflow data' }, filePath: { type: 'string', description: 'Path where the workflow file was saved' } } } },
- src/tools/toolDefinitions.js:125-144 (registration)In the 'workflow_manage' tool, the 'create' operation is registered to call createWorkflowExecute with the rest of parameters. This provides create_workflow functionality within the consolidated workflow_manage tool.execute: async (params) => { const { operation, ...rest } = params; // Route to appropriate handler based on operation switch (operation) { case 'create': return createWorkflowExecute(rest); case 'save': return saveWorkflowExecute(rest); case 'load': return loadWorkflowExecute(rest); case 'list': return listWorkflowsExecute(rest); case 'delete': return deleteWorkflowExecute(rest); case 'generate': return generateWorkflow(rest); default: throw new Error(`Unknown workflow operation: ${operation}`); }
- src/tools/__index.js:36-42 (registration)Registers 'create' operation/tool as createWorkflowTool (imported from workflowCreation.js) within workflowTools object, likely for internal or alternative tool grouping.const workflowTools = { create: createWorkflowTool, save: workflowStorageTools.saveWorkflowTool, load: workflowStorageTools.loadWorkflowTool, list: workflowStorageTools.listWorkflowsTool, delete: workflowStorageTools.deleteWorkflowTool, generate: generateWorkflowTool
- src/tools/workflowCreation.js:98-100 (helper)Exports the createWorkflowExecute handler for use in tool definitions and registrations.module.exports = { createWorkflowExecute };