Skip to main content
Glama

execute_workflow

Executes programmatically built ComfyUI workflows to generate images from workflow dictionaries, returning the output or error messages for automated image generation.

Instructions

Execute an arbitrary workflow dict.

    Args:
        workflow: Workflow dict in ComfyUI API format
        output_node_id: Node ID that outputs the final image

    Returns the generated image or error message.
    Use this for programmatically built workflows.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflowYesComplete workflow dict
output_node_idYesNode ID to get output from

Implementation Reference

  • The main handler for the 'execute_workflow' tool. Validates input format and delegates execution to the internal _execute_workflow helper.
    @mcp.tool()
    def execute_workflow(
        workflow: dict = Field(description="Complete workflow dict"),
        output_node_id: str = Field(description="Node ID to get output from"),
        ctx: Context = None,
    ):
        """Execute an arbitrary workflow dict.
    
        Args:
            workflow: Workflow dict in ComfyUI API format
            output_node_id: Node ID that outputs the final image
    
        Returns the generated image or error message.
        Use this for programmatically built workflows.
        """
        # Check for UI format workflows
        if is_ui_format(workflow):
            return (
                "Error: Workflow is in UI format (has nodes/widgets_values). "
                "UI format uses positional arrays that can cause parameter misalignment errors. "
                "Please provide workflow in API format with explicit 'class_type' and 'inputs'."
            )
    
        if ctx:
            ctx.info("Executing custom workflow...")
        return _execute_workflow(workflow, output_node_id, ctx)
  • Core implementation logic for executing the workflow: submits to ComfyUI API, polls for completion, handles output as image or URL.
    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."
  • Registration call for execution tools (including execute_workflow) within the register_all_tools function.
    register_execution_tools(mcp)
  • Top-level registration of all tools, which includes the execute_workflow tool via the execution tools module.
    register_all_tools(mcp)
  • Helper function used by execute_workflow to validate workflow format (API vs UI).
    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 permissions, rate limits, side effects (e.g., queue impact), or error handling. For a tool that executes workflows with no annotation coverage, this is insufficient.

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 concise and well-structured: it starts with the purpose, lists args and returns, and ends with usage guidance. Each sentence adds value, with no wasted words. However, it could be slightly more front-loaded by emphasizing the 'programmatically built workflows' aspect earlier.

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 (executing workflows with nested objects), no annotations, and no output schema, the description is moderately complete. It covers the basic purpose, parameters, and return values, but lacks details on behavioral aspects like error conditions, performance, or integration with sibling tools. It's adequate but has clear gaps for a tool of this nature.

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 both parameters ('workflow' and 'output_node_id') with descriptions. The description adds minimal value by specifying 'workflow dict in ComfyUI API format' and 'Node ID that outputs the final image', which slightly clarifies formats but doesn't provide deep semantic insights beyond the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

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 tool's purpose: 'Execute an arbitrary workflow dict' with the verb 'Execute' and resource 'workflow dict'. It distinguishes from siblings like 'run_workflow' and 'submit_workflow' by specifying 'programmatically built workflows', though the distinction could be more explicit. The purpose is specific but not fully differentiated from all similar tools.

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 provides some usage guidance: 'Use this for programmatically built workflows.' This implies when to use it (for programmatic workflows) but doesn't explicitly state when not to use it or name alternatives like 'run_workflow' or 'submit_workflow'. The guidance is present but incomplete, leaving room for ambiguity.

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