Skip to main content
Glama

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
NameRequiredDescriptionDefault
nameYes
workflowYes
descriptionNo
tagsNo
overwriteNo

Implementation Reference

  • 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,
    },
  • 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);

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/Nikolaibibo/claude-comfyui-mcp'

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