read_workflow
Convert ComfyUI workflow files from JSON to human-readable DSL format for easier editing and management. Supports automatic format detection and transparent conversion.
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
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes |
Implementation Reference
- comfy_mcp/mcp/server.py:56-116 (handler)The core handler function for the 'read_workflow' tool. It reads workflow files (.json or .dsl), handles path validation, detects format, and converts JSON workflows to DSL format before returning the content.@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}")
- comfy_mcp/mcp/server.py:44-52 (helper)Helper function used by read_workflow to validate that file paths are within the allowed workflows directory for security.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")
- comfy_mcp/mcp/__init__.py:1-28 (registration)Package __init__.py that documents and exposes the MCP server instance where read_workflow is registered via import from server.py."""MCP Server package for ComfyUI workflow management. This package provides a Model Context Protocol (MCP) server that exposes ComfyUI workflow management tools to AI agents. The server provides both file operations and execution capabilities: File Operations: - read_workflow: Read JSON/DSL files, convert to DSL - write_workflow: Write DSL as JSON/DSL files - list_workflows: Discover workflow files - validate_workflow: Validate DSL syntax - get_workflow_info: Analyze workflow structure Execution Operations: - execute_workflow: Run DSL workflows on ComfyUI - get_job_status: Monitor execution & download images - list_comfyui_queue: View ComfyUI queue status Example: Start the MCP server: >>> from comfy_mcp.mcp.server import mcp >>> if __name__ == "__main__": ... mcp.run() """ from .server import mcp, DEFAULT_COMFYUI_SERVER