Skip to main content
Glama

export

Export n8n workflows to JSON files for backup, sharing, or migration. Specify individual workflows or export all at once with customizable output formatting.

Instructions

Export workflows from n8n - replaces "n8n export:workflow" command

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNoWorkflow ID to export
allNoExport all workflows
outputPathNoOutput directory path (defaults to workflows/flows)
prettyNoFormat JSON output prettily (default: true)

Implementation Reference

  • Core implementation of the export tool: executes n8n CLI export:workflow command, handles single workflow by ID or all workflows, saves them as separate JSON files in the specified output directory (defaults to workflows/flows), preserving workflow IDs.
    async exportWorkflow(options: { id?: string; all?: boolean; outputPath?: string; pretty?: boolean; } = {}): Promise<any> { try { const outputDir = options.outputPath || path.join(this.workflowsPath, 'flows'); // Ensure output directory exists await fs.mkdir(outputDir, { recursive: true }); // Build command - n8n requires a file path, not directory let command = 'n8n export:workflow'; if (options.all) { // For all workflows, we need to export to a temp file and process const tempFile = path.join('/tmp', `n8n-export-${Date.now()}.json`); command += ` --all --output="${tempFile}"`; if (options.pretty !== false) { command += ' --pretty'; } console.error(`Executing: ${command}`); const { stdout, stderr } = await execAsync(command); if (this.hasRealError(stderr, stdout)) { throw new Error(stderr); } // Read the exported data const exportedData = await fs.readFile(tempFile, 'utf-8'); const workflows = JSON.parse(exportedData); // Save each workflow separately, preserving ID for (const workflow of workflows) { const fileName = `${workflow.name.toLowerCase().replace(/\s+/g, '-')}.json`; const filePath = path.join(outputDir, fileName); // Store the full workflow object with ID await fs.writeFile(filePath, JSON.stringify(workflow, null, 2)); } // Clean up temp file await fs.unlink(tempFile).catch(() => {}); return { content: [{ type: 'text', text: `✅ Exported ${workflows.length} workflows to ${outputDir}` }] }; } else if (options.id) { // For single workflow, export directly const tempFile = path.join('/tmp', `n8n-export-${Date.now()}.json`); command += ` --id=${options.id} --output="${tempFile}"`; if (options.pretty !== false) { command += ' --pretty'; } console.error(`Executing: ${command}`); const { stdout, stderr } = await execAsync(command); if (this.hasRealError(stderr, stdout)) { throw new Error(stderr); } // Read the exported data const exportedData = await fs.readFile(tempFile, 'utf-8'); const workflows = JSON.parse(exportedData); const workflow = Array.isArray(workflows) ? workflows[0] : workflows; // Save with the workflow's name, preserving ID const fileName = `${workflow.name.toLowerCase().replace(/\s+/g, '-')}.json`; const filePath = path.join(outputDir, fileName); // Store the full workflow object with ID await fs.writeFile(filePath, JSON.stringify(workflow, null, 2)); // Clean up temp file await fs.unlink(tempFile).catch(() => {}); return { content: [{ type: 'text', text: `✅ Exported workflow: ${workflow.name}\n` + `📁 File: ${fileName}\n` + `🆔 ID: ${workflow.id}` }] }; } // If no specific options, show error return { content: [{ type: 'text', text: '❌ Please specify either --id or --all for export' }] }; } catch (error: any) { throw new Error(`Failed to export workflow: ${error.message}`); } }
  • ToolHandler switch case that receives tool calls for 'export' and delegates to N8nManager.exportWorkflow with parsed arguments.
    case 'export': return await this.n8nManager.exportWorkflow({ id: args?.id as string, all: args?.all as boolean, outputPath: args?.outputPath as string, pretty: args?.pretty as boolean, });
  • Tool schema definition including name, description, and input schema for the 'export' tool, returned by getToolDefinitions().
    { name: 'export', description: 'Export workflows from n8n - replaces "n8n export:workflow" command', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Workflow ID to export', }, all: { type: 'boolean', description: 'Export all workflows', }, outputPath: { type: 'string', description: 'Output directory path (defaults to workflows/flows)', }, pretty: { type: 'boolean', description: 'Format JSON output prettily (default: true)', }, }, }, },
  • Registers the tools (including 'export') with the MCP server by handling ListToolsRequest (via getToolDefinitions) and CallToolRequest (via ToolHandler).
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: getToolDefinitions(), })); this.server.setRequestHandler(CallToolRequestSchema, async (request) => { return await this.toolHandler.handleTool( request.params.name, request.params.arguments ); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mckinleymedia/mcflow-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server