Skip to main content
Glama

get_result_image

Retrieve generated images from completed ComfyUI workflows by specifying prompt and node IDs.

Instructions

Get the result image from a completed prompt.

    Args:
        prompt_id: The prompt ID from submit_workflow()
        output_node_id: Node ID that produced the image

    Returns the image if available, or error message.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
prompt_idYesPrompt ID
output_node_idYesOutput node ID

Implementation Reference

  • The handler function for the 'get_result_image' tool. It retrieves the prompt history from ComfyUI, verifies completion, extracts the image filename from the output node, downloads the image data, and returns it as an MCP Image object.
    @mcp.tool()
    def get_result_image(
        prompt_id: str = Field(description="Prompt ID"),
        output_node_id: str = Field(description="Output node ID"),
        ctx: Context = None,
    ):
        """Get the result image from a completed prompt.
    
        Args:
            prompt_id: The prompt ID from submit_workflow()
            output_node_id: Node ID that produced the image
    
        Returns the image if available, or error message.
        """
        if ctx:
            ctx.info(f"Getting result: {prompt_id}")
    
        try:
            history = comfy_get(f"/history/{prompt_id}")
            if prompt_id not in history:
                return "Prompt not found in history"
    
            entry = history[prompt_id]
            status = entry.get("status", {})
    
            if not status.get("completed"):
                return "Prompt not yet completed"
    
            outputs = entry.get("outputs", {})
            if output_node_id not in outputs:
                return f"No output from node {output_node_id}"
    
            images = outputs[output_node_id].get("images", [])
            if not images:
                return "No images in output"
    
            # Download image
            url = get_file_url(settings.comfy_url, images[0])
            from ..api import download_file
    
            image_data = download_file(url)
            if image_data:
                return Image(data=image_data, format="png")
            return "Failed to download image"
    
        except Exception as e:
            return f"Error: {e}"
  • Registration call for execution tools, including 'get_result_image', within the register_all_tools function.
    register_execution_tools(mcp)
  • Top-level registration of all tools by calling register_all_tools(mcp), which indirectly registers 'get_result_image'.
    register_all_tools(mcp)
  • Input schema defined via Pydantic Field descriptions for prompt_id and output_node_id parameters.
    def get_result_image(
        prompt_id: str = Field(description="Prompt ID"),
        output_node_id: str = Field(description="Output node ID"),
        ctx: Context = None,
    ):

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