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
| Name | Required | Description | Default |
|---|---|---|---|
| prompt_id | Yes | Prompt ID | |
| output_node_id | Yes | Output 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}"
- src/comfy_mcp_server/tools/__init__.py:28-28 (registration)Registration call for execution tools, including 'get_result_image', within the register_all_tools function.register_execution_tools(mcp)
- src/comfy_mcp_server/__init__.py:92-92 (registration)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, ):