comfy_save_workflow
Store workflow JSON in the MCP library with metadata for organization and future reuse.
Instructions
Save a workflow JSON to the MCP library for later reuse. Includes metadata like description and tags for organization.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| workflow | Yes | ||
| description | No | ||
| tags | No | ||
| overwrite | No |
Implementation Reference
- src/tools/workflows.ts:20-91 (handler)The main handler function for the 'comfy_save_workflow' tool. Validates input, processes the workflow JSON, checks for overwrites, creates metadata, and saves it to the workflow library using saveWorkflowToLibrary.export async function handleSaveWorkflow(input: SaveWorkflowInput) { try { // Validate workflow name if (!validateWorkflowName(input.name)) { throw ComfyUIErrorBuilder.validationError( 'Invalid workflow name. Use only alphanumeric characters, hyphens, and underscores.' ); } // Parse and validate workflow const processor = new WorkflowProcessor(); const workflow = processor.parseWorkflow(input.workflow); if (!validateWorkflowJSON(workflow)) { throw ComfyUIErrorBuilder.invalidWorkflow('Invalid workflow structure'); } // Check if exists and overwrite is false const config = getConfig(); const libraryPath = getFullPath(config.paths.workflow_library); const filePath = join(libraryPath, `${input.name}.json`); if (existsSync(filePath) && !input.overwrite) { throw ComfyUIErrorBuilder.validationError( `Workflow "${input.name}" already exists. Set overwrite=true to replace it.` ); } // Create metadata const now = new Date().toISOString(); const metadata = { name: input.name, description: input.description, tags: input.tags || [], created_at: existsSync(filePath) ? JSON.parse(require('fs').readFileSync(filePath, 'utf-8')).created_at : now, updated_at: now, workflow }; // Save to library const savedPath = saveWorkflowToLibrary(input.name, metadata); return { content: [{ type: "text", text: JSON.stringify({ name: input.name, path: savedPath, message: `Workflow "${input.name}" saved successfully` }, null, 2) }] }; } catch (error: any) { if (error.error) { return { content: [{ type: "text", text: JSON.stringify(error, null, 2) }], isError: true }; } return { content: [{ type: "text", text: JSON.stringify(ComfyUIErrorBuilder.executionError(error.message), null, 2) }], isError: true }; } }
- src/server.ts:93-96 (registration)Registration of the 'comfy_save_workflow' tool in the MCP server, including name, description, and input schema reference.name: 'comfy_save_workflow', description: 'Save a workflow JSON to the MCP library for later reuse. Includes metadata like description and tags for organization.', inputSchema: zodToJsonSchema(SaveWorkflowSchema) as any, },
- src/types/tools.ts:85-91 (schema)Zod schema defining the input structure for the 'comfy_save_workflow' tool, including validation for name, workflow, description, tags, and overwrite flag.export const SaveWorkflowSchema = z.object({ name: z.string().regex(/^[a-zA-Z0-9_-]+$/), workflow: z.union([z.string(), z.record(z.any())]), description: z.string().optional(), tags: z.array(z.string()).optional(), overwrite: z.boolean().optional().default(false) });
- src/server.ts:164-165 (registration)Switch case in the tool call handler that routes 'comfy_save_workflow' calls to the handleSaveWorkflow function.case 'comfy_save_workflow': return await handleSaveWorkflow(args as any);