Skip to main content
Glama

run_workflow

Execute saved ComfyUI workflows to generate images with optional input overrides and output node selection.

Instructions

Execute a saved workflow file.

    Args:
        workflow_name: Workflow filename (e.g., 'flux-dev.json')
        inputs: Optional input overrides, e.g., {"6": {"text": "new prompt"}}
        output_node_id: Node ID to get output from (uses default if not set)

    Returns the generated image or error message.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflow_nameYesWorkflow filename
inputsNoNode input overrides
output_node_idNoOutput node ID

Implementation Reference

  • The @mcp.tool()-decorated run_workflow function implementing the core tool logic: loads workflow from file, applies input overrides, validates format, determines output node, and delegates to _execute_workflow.
    @mcp.tool()
    def run_workflow(
        workflow_name: str = Field(description="Workflow filename"),
        inputs: dict = Field(default=None, description="Node input overrides"),
        output_node_id: str = Field(default=None, description="Output node ID"),
        ctx: Context = None,
    ):
        """Execute a saved workflow file.
    
        Args:
            workflow_name: Workflow filename (e.g., 'flux-dev.json')
            inputs: Optional input overrides, e.g., {"6": {"text": "new prompt"}}
            output_node_id: Node ID to get output from (uses default if not set)
    
        Returns the generated image or error message.
        """
        if not settings.workflows_dir:
            return "Error: COMFY_WORKFLOWS_DIR not configured"
    
        wf_path = Path(settings.workflows_dir) / workflow_name
        if not wf_path.exists():
            return f"Error: Workflow '{workflow_name}' not found"
    
        if ctx:
            ctx.info(f"Loading workflow: {workflow_name}")
    
        with open(wf_path) as f:
            workflow = json.load(f)
    
        # Check for UI format workflows
        if is_ui_format(workflow):
            return (
                f"Error: Workflow '{workflow_name}' is in UI format (has nodes/widgets_values). "
                "UI format uses positional arrays that can cause parameter misalignment errors. "
                "Please re-export the workflow from ComfyUI using 'Export (API Format)' or use "
                "convert_workflow_to_ui() to create a UI version from an API format workflow."
            )
    
        # Apply input overrides
        if inputs:
            for node_id, values in inputs.items():
                if node_id in workflow:
                    if isinstance(values, dict):
                        workflow[node_id]["inputs"].update(values)
                    else:
                        # Simple value - try to set text input
                        if "text" in workflow[node_id]["inputs"]:
                            workflow[node_id]["inputs"]["text"] = values
    
        out_node = output_node_id or settings.output_node_id
        if not out_node:
            return "Error: No output_node_id specified"
    
        return _execute_workflow(workflow, out_node, ctx)
  • Calls register_execution_tools(mcp) within register_all_tools, which executes the @mcp.tool() decorators to register run_workflow.
    register_execution_tools(mcp)
  • Top-level call to register_all_tools(mcp) that initiates the registration chain for all tools including run_workflow.
    register_all_tools(mcp)
  • Internal helper _execute_workflow that submits the prompt to ComfyUI API, polls for completion, handles output modes, and returns the generated Image.
    def _execute_workflow(workflow: dict, output_node_id: str, ctx: Context | None):
        """Internal function to execute workflow and return result."""
        # Submit workflow
        status, resp_data = comfy_post("/prompt", {"prompt": workflow})
    
        if status != 200:
            error_msg = resp_data.get("error", f"status {status}")
            return f"Failed to submit workflow: {error_msg}"
    
        prompt_id = resp_data.get("prompt_id")
        if not prompt_id:
            node_errors = resp_data.get("node_errors", {})
            if node_errors:
                return f"Workflow validation failed:\n{json.dumps(node_errors, indent=2)}"
            return "Failed to get prompt_id from response"
    
        if ctx:
            ctx.info(f"Submitted: {prompt_id}")
    
        # Poll callback for progress logging
        def on_poll(attempt: int, max_attempts: int):
            if ctx and attempt % 5 == 0:
                ctx.info(f"Waiting... ({attempt}/{max_attempts})")
    
        # Poll for result
        image_data = poll_for_result(prompt_id, output_node_id, on_poll=on_poll)
    
        if image_data:
            if ctx:
                ctx.info("Image generated successfully")
    
            if settings.output_mode.lower() == "url":
                # Return URL instead of image data
                history = comfy_get(f"/history/{prompt_id}")
                if prompt_id in history:
                    outputs = history[prompt_id].get("outputs", {})
                    if output_node_id in outputs:
                        images = outputs[output_node_id].get("images", [])
                        if images:
                            url_values = urllib.parse.urlencode(images[0])
                            return get_file_url(settings.comfy_url_external, url_values)
    
            return Image(data=image_data, format="png")
    
        return "Failed to generate image. Use get_queue_status() and get_history() to debug."
  • Helper function is_ui_format used by run_workflow to detect and reject UI-format workflows.
    def is_ui_format(workflow: dict) -> bool:
        """Detect if workflow is in UI format (has nodes/links) vs API format (has class_type/inputs)."""
        return "nodes" in workflow or "version" in workflow
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions that the tool 'Returns the generated image or error message,' which adds some behavioral context about outputs. However, it lacks details on execution behavior (e.g., synchronous/asynchronous, side effects, permissions, or error handling), which is insufficient for a mutation tool with zero annotation coverage.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded with the core purpose. The Args and Returns sections are structured clearly, though the formatting with indentation could be slightly improved for readability. Every sentence adds value without redundancy.

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

Completeness3/5

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

Given the complexity (3 parameters, no annotations, no output schema), the description is moderately complete. It covers the purpose and parameters well but lacks behavioral details (e.g., execution mode, error conditions) and doesn't fully compensate for the absence of annotations and output schema, leaving gaps for an execution tool.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters. The description adds value by providing examples (e.g., 'flux-dev.json' for workflow_name, '{"6": {"text": "new prompt"}}' for inputs) and clarifying that output_node_id 'uses default if not set,' which enhances understanding beyond the schema. This meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the verb ('Execute') and resource ('a saved workflow file'), making the purpose evident. It distinguishes from siblings like 'create_workflow' or 'load_workflow' by focusing on execution, but could be more specific about what 'execute' entails compared to similar tools like 'execute_workflow' or 'submit_workflow'.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. With siblings like 'execute_workflow' and 'submit_workflow', the description lacks context on differences, prerequisites, or exclusions, leaving the agent to infer usage from tool names alone.

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/IO-AtelierTech/comfyui-mcp'

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