Skip to main content
Glama

write_workflow

Save ComfyUI workflows to disk by converting DSL content to JSON or DSL format for storage and reuse.

Instructions

Write a workflow to disk.

Takes DSL content and writes it to disk. By default, converts to JSON format. Can optionally save as .dsl format directly.

Args: filepath: Destination file path dsl: Workflow content in DSL format format: Output format ("json" or "dsl", default: "json")

Returns: Status dict with path, size, and format info

Examples: write_workflow("workflows/new_workflow.json", dsl_content) write_workflow("workflows/backup.dsl", dsl_content, format="dsl")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
dslYes
formatNojson

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'write_workflow' tool. It is decorated with @mcp.tool for registration and implements the logic to write DSL workflows to disk as JSON or DSL files, including conversion using DSLParser and DslToJsonConverter.
    @mcp.tool
    async def write_workflow(
        ctx: Context,
        filepath: str,
        dsl: str,
        format: str = "json"
    ) -> dict:
        """Write a workflow to disk.
    
        Takes DSL content and writes it to disk. By default, converts to JSON format.
        Can optionally save as .dsl format directly.
    
        Args:
            filepath: Destination file path
            dsl: Workflow content in DSL format
            format: Output format ("json" or "dsl", default: "json")
    
        Returns:
            Status dict with path, size, and format info
    
        Examples:
            write_workflow("workflows/new_workflow.json", dsl_content)
            write_workflow("workflows/backup.dsl", dsl_content, format="dsl")
        """
        await ctx.info(f"Writing workflow to {filepath}")
    
        try:
            path = validate_path(filepath)
    
            # Check if file exists
            if path.exists():
                await ctx.info(f"⚠️  File {filepath} already exists, will overwrite")
    
            if format == "dsl":
                # Write DSL directly
                path.write_text(dsl)
                await ctx.info(f"✓ Wrote DSL to {filepath}")
    
            elif format == "json":
                # Convert DSL to JSON
                await ctx.info("Converting DSL to JSON...")
    
                parser = DSLParser()
                workflow_ast = parser.parse(dsl)
    
                converter = DslToJsonConverter()
                json_workflow = converter.convert(workflow_ast)
    
                json_content = json.dumps(json_workflow, indent=2)
                path.write_text(json_content)
    
                await ctx.info(f"✓ Wrote JSON to {filepath}")
    
            else:
                raise ToolError(f"Unsupported format: {format}. Use 'json' or 'dsl'")
    
            return {
                "status": "success",
                "path": str(path),
                "size": path.stat().st_size,
                "format": format
            }
    
        except Exception as e:
            raise ToolError(f"Error writing workflow: {e}")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool writes to disk and converts formats, but lacks details on permissions, error handling, or side effects. It adds some context (e.g., default format) but is incomplete for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by concise sections for args, returns, and examples. Every sentence adds value without redundancy, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with 3 params, no annotations) and an output schema (implied by 'Returns' statement), the description is fairly complete. It covers purpose, parameters, and output, but could improve by addressing behavioral aspects like error cases or dependencies.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains all three parameters ('filepath', 'dsl', 'format') with meanings, default values, and options, adding significant value beyond the bare schema. However, it doesn't detail constraints like filepath formats or DSL syntax.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Write a workflow to disk') with the resource ('workflow') and distinguishes it from siblings like 'read_workflow' and 'execute_workflow'. It specifies the transformation from DSL content to disk files, making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by mentioning default behavior (converts to JSON) and an optional format, but does not explicitly state when to use this tool versus alternatives like 'read_workflow' or 'execute_workflow'. It provides basic context without exclusions or clear alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/christian-byrne/comfy-mcp'

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