Skip to main content
Glama

get_result_image

Retrieve generated images from completed ComfyUI workflows by specifying prompt and output 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 core handler function for the 'get_result_image' tool, decorated with @mcp.tool(). It fetches the prompt history from ComfyUI, verifies completion and outputs, downloads the image from the first available output, and returns it as an MCP Image object or an error string.
    @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, ) -> Image | str: """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}"
  • Call to register_execution_tools(mcp) within register_all_tools, which defines and registers the get_result_image tool using @mcp.tool() decorator.
    register_execution_tools(mcp)
  • Top-level registration: imports and calls register_all_tools(mcp), which chains to registering the execution tools including get_result_image.
    from .tools import register_all_tools # Configure logging logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", ) logger = logging.getLogger(__name__) # Server instructions for Claude Code SERVER_INSTRUCTIONS = """ ## ComfyUI MCP Server - Workflow Guide ### Workflow Formats (CRITICAL) - **API format**: `{"node_id": {"class_type": "...", "inputs": {...}}}` - For MCP execution - **UI format**: `{"nodes": [...], "links": [...], "version": ...}` - For ComfyUI editor only - **IMPORTANT**: Only API format can be executed. UI format will be rejected with an error. ### Creating Workflows (Step-by-Step) 1. **CREATE** - Start empty or from template: ``` wf = create_workflow() # Or: wf = get_workflow_template("fal-flux-dev") ``` 2. **DISCOVER** - Find nodes and parameters: ``` list_nodes(filter="Luma") # Find node names get_node_info("LumaImageToVideoNode") # Get required inputs ``` 3. **BUILD** - Add nodes with connections: ``` wf = add_node(wf, "1", "LoadImage", {"image": "input.jpg"}) wf = add_node(wf, "2", "SomeNode", { "param": "value", "input_image": ["1", 0] # Connect to node "1", output 0 }) ``` 4. **VALIDATE** - Check before saving: ``` validation = validate_workflow(wf) # Check validation["valid"] and validation["errors"] ``` 5. **SAVE** - Choose format by purpose: ``` save_workflow(wf, "name", format="api") # → workflows-api/ (execution) save_workflow(wf, "name", format="ui") # → workflows-ui/ (editor) ``` ### Execution - `run_workflow("name.json", inputs={...})` - Run saved API workflow - `execute_workflow(wf, output_node_id="9")` - Run workflow dict directly - `generate_image("prompt")` - Simple interface with default workflow ### Common Errors - "UI format detected": Use API format for execution - "Unknown node type": Check with list_nodes() - "Missing required input": Check with get_node_info() ### Node Connections Format Connections are `["source_node_id", output_index]`: - `"image": ["1", 0]` connects to node "1", first output (index 0) """ # Initialize MCP server with instructions mcp = FastMCP("Comfy MCP Server", instructions=SERVER_INSTRUCTIONS) # Register all tools register_all_tools(mcp)

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