Sandbox
@lalanikarim/comfy-mcp-server

MCP server for ComfyUI image generation

Comfy MCP Server connects an agent to a remote ComfyUI server through the MCP protocol. It uses a workflow JSON export, prompt node IDs, and output node IDs to submit image jobs and return either a URL or a file.

46 stars16 forksPythonUpdated 1y ago
Who it's for

People who want their agent to generate images from prompts through ComfyUI.

What it delivers

You can ask an agent to create images without leaving your ComfyUI workflow setup.

What it does

Prompt to image generation

Takes a prompt, loads a ComfyUI workflow JSON, and submits it to a remote Comfy server.

Result polling

Checks the job status until the image is ready, then returns the generated output.

Optional prompt generation with Ollama

Can use an Ollama model to expand a topic into a fuller image prompt.

Claude Desktop MCP setup

Includes an example MCP server config for connecting the server to Claude Desktop.

File or URL output

Supports returning the generated image as either a file or a URL through `OUTPUT_MODE`.

How to get it

  1. 1Comfy MCP Server can be launched by the following command
    uvx comfy-mcp-server

README

Comfy MCP Server

smithery badge

A server using FastMCP framework to generate images based on prompts via a remote Comfy server.

Overview

This script sets up a server using the FastMCP framework to generate images based on prompts using a specified workflow. It interacts with a remote Comfy server to submit prompts and retrieve generated images.

Prerequisites

  • uv package and project manager for Python.
  • Workflow file exported from Comfy UI. This code includes a sample Flux-Dev-ComfyUI-Workflow.json which is only used here as reference. You will need to export from your workflow and set the environment variables accordingly.

You can install the required packages for local development:

uvx mcp[cli]

Configuration

Set the following environment variables:

  • COMFY_URL to point to your Comfy server URL.
  • COMFY_WORKFLOW_JSON_FILE to point to the absolute path of the API export json file for the comfyui workflow.
  • PROMPT_NODE_ID to the id of the text prompt node.
  • OUTPUT_NODE_ID to the id of the output node with the final image.
  • OUTPUT_MODE to either url or file to select desired output.

Optionally, if you have an Ollama server running, you can connect to it for prompt generation.

  • OLLAMA_API_BASE to the url where ollama is running.
  • PROMPT_LLM to the name of the model hosted on ollama for prompt generation.

Example:

export COMFY_URL=http://your-comfy-server-url:port
export COMFY_WORKFLOW_JSON_FILE=/path/to/the/comfyui_workflow_export.json
export PROMPT_NODE_ID=6 # use the correct node id here
export OUTPUT_NODE_ID=9 # use the correct node id here
export OUTPUT_MODE=file

Usage

Comfy MCP Server can be launched by the following command:

uvx comfy-mcp-server

Example Claude Desktop Config

{
  "mcpServers": {
    "Comfy MCP Server": {
      "command": "/path/to/uvx",
      "args": [
        "comfy-mcp-server"
      ],
      "env": {
        "COMFY_URL": "http://your-comfy-server-url:port",
        "COMFY_WORKFLOW_JSON_FILE": "/path/to/the/comfyui_workflow_export.json",
        "PROMPT_NODE_ID": "6",
        "OUTPUT_NODE_ID": "9",
        "OUTPUT_MODE": "file",
      }
    }
  }
}

Functionality

generate_image(prompt: str, ctx: Context) -> Image | str

This function generates an image using a specified prompt. It follows these steps:

  1. Checks if all the environment variable are set.
  2. Loads a prompt template from a JSON file.
  3. Submits the prompt to the Comfy server.
  4. Polls the server for the status of the prompt processing.
  5. Retrieves and returns the generated image once it's ready.

generate_prompt(topic: str, ctx: Context) -> str

This function generates a comprehensive image generation prompt from specified topic.

Dependencies

  • mcp: For setting up the FastMCP server.
  • json: For handling JSON data.
  • urllib: For making HTTP requests.
  • time: For adding delays in polling.
  • os: For accessing environment variables.
  • langchain: For creating simple LLM Prompt chain to generate image generation prompt from topic.
  • langchain-ollama: For ollama specific modules for LangChain.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Files in the repo

Repository payload10 top-level entries
  • src
  • .gitignore
  • .python-version
  • Dockerfile
  • Flux-Dev-ComfyUI-Workflow.json
  • LICENSE
  • pyproject.toml
  • README.md
  • smithery.yaml
  • uv.lock

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More connectors

Open-source 3D architectural editor with a local CLI, MCP tools, and practical workflows for humans and AI agents.

23k
ahujasid/
blender-mcp

Community plugin to control Blender 3D with any LLM of your choice

28k

MCP server to provide Figma layout information to AI coding agents like Cursor

16k
grab/
cursor-talk-to-figma-mcp

TalkToFigma: MCP integration between AI Agent (Cursor, Claude Code, Codex) and Figma, allowing Agentic AI to communicate with Figma for reading designs and modifying them programmatically.

7k
mixelpixx/
Konnect

AI-assisted PCB design for KiCAD 10. Native KiCAD plugin — a single Rust binary exposing 217 schematic, layout, routing, placement, design-review, and manufacturing tools to Claude, or the LLM of your choosing

608
lucasastorian/
llmwiki

Open Source Implementation of Karpathy's LLM Wiki. Upload documents, connect your Claude account via MCP, and have it write your wiki !

1.6k