Skip to main content
Glama

read_workflow

Convert ComfyUI workflow files between JSON and DSL formats for AI agents to manage workflows through natural language interactions.

Instructions

Read a workflow file and return it as DSL format.

Supports both JSON and DSL input files. Automatically detects format and converts JSON to DSL transparently.

Args: filepath: Path to workflow file (.json or .dsl)

Returns: Workflow content in DSL format

Examples: read_workflow("workflows/my_workflow.json") read_workflow("../dsl/examples/dsl/simple.dsl")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'read_workflow' tool, decorated with @mcp.tool for registration. Reads workflow files (.json or .dsl), auto-converts JSON to DSL using JsonToDslConverter, handles path validation, errors, and logging.
    @mcp.tool
    async def read_workflow(ctx: Context, filepath: str) -> str:
        """Read a workflow file and return it as DSL format.
    
        Supports both JSON and DSL input files. Automatically detects format
        and converts JSON to DSL transparently.
    
        Args:
            filepath: Path to workflow file (.json or .dsl)
    
        Returns:
            Workflow content in DSL format
    
        Examples:
            read_workflow("workflows/my_workflow.json")
            read_workflow("../dsl/examples/dsl/simple.dsl")
        """
        await ctx.info(f"Reading workflow from {filepath}")
    
        try:
            path = Path(filepath).resolve()
    
            # Allow access to dsl/examples directory
            if "examples" not in str(path):
                path = validate_path(filepath)
    
            if not path.exists():
                raise ToolError(f"File not found: {filepath}")
    
            content = path.read_text()
    
            # If already DSL, return as-is
            if path.suffix == ".dsl":
                await ctx.info("File is already in DSL format")
                return content
    
            # If JSON, convert to DSL
            if path.suffix == ".json":
                await ctx.info("Converting JSON to DSL...")
    
                workflow = json.loads(content)
    
                # Handle full ComfyUI format
                if is_full_workflow_format(workflow):
                    workflow = full_workflow_to_simplified(workflow)
    
                # Convert to DSL
                converter = JsonToDslConverter()
                workflow_ast = converter.convert(workflow)
                dsl_text = str(workflow_ast)
    
                await ctx.info(f"✓ Converted to DSL ({len(dsl_text)} chars)")
                return dsl_text
    
            raise ToolError(f"Unsupported file format: {path.suffix}")
    
        except json.JSONDecodeError as e:
            raise ToolError(f"Invalid JSON in {filepath}: {e}")
        except Exception as e:
            raise ToolError(f"Error reading workflow: {e}")
  • The @mcp.tool decorator registers the read_workflow function as an MCP tool.
    @mcp.tool
  • Helper function validate_path used by read_workflow for security path validation.
    def validate_path(filepath: str, base: Path = WORKFLOWS_BASE) -> Path:
        """Validate file path is within allowed directory"""
        path = Path(filepath).resolve()
        try:
            path.relative_to(base.resolve())
            return path
        except ValueError:
            raise ToolError(f"Access denied: {filepath} is outside allowed directory")
Behavior4/5

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

With no annotations provided, the description carries full burden. It discloses key behavioral traits: automatic format detection, transparent JSON-to-DSL conversion, and file format support (.json or .dsl). However, it doesn't mention error handling, file size limits, or authentication requirements.

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 with clear sections (purpose, format support, Args, Returns, Examples). Every sentence earns its place by providing essential information without redundancy. The front-loaded purpose statement immediately communicates core functionality.

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 1 parameter with 0% schema coverage and no annotations, the description does well by explaining parameter semantics, return format, and behavioral aspects. Since an output schema exists, the description doesn't need to detail return values. The main gap is lack of error/edge-case handling information.

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 provides clear semantics for the single parameter 'filepath' including purpose ('Path to workflow file'), supported extensions (.json or .dsl), and examples. This adds substantial value beyond the bare schema.

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 ('Read a workflow file'), the resource ('workflow file'), and the output format ('return it as DSL format'). It distinguishes from siblings like 'get_workflow_info' (which likely provides metadata) and 'write_workflow' (which creates/modifies).

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 support for both JSON and DSL input files, but doesn't explicitly state when to use this tool versus alternatives like 'get_workflow_info' or 'validate_workflow'. No explicit when-not-to-use guidance or prerequisite context is provided.

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