Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

comfyui-mcp-server

MCP.Pizza Chef: joenorton

comfyui-mcp-server is a lightweight Python-based MCP server that connects AI agents to a local ComfyUI instance for programmatic image generation. It uses the MCP protocol over WebSocket to handle dynamic image generation requests with customizable parameters like prompt, dimensions, and model selection, returning image URLs served by ComfyUI. Designed for seamless integration, it requires Python 3.10+, ComfyUI running locally, and standard Python dependencies.

Use This MCP server To

Generate images programmatically via AI agent requests Customize image generation with dynamic prompts and parameters Integrate ComfyUI image workflows into AI-enhanced applications Serve generated images through URLs for easy access Automate image creation in local AI pipelines

README

ComfyUI MCP Server

A lightweight Python-based MCP (Model Context Protocol) server that interfaces with a local ComfyUI instance to generate images programmatically via AI agent requests.

Overview

This project enables AI agents to send image generation requests to ComfyUI using the MCP protocol over WebSocket. It supports:

  • Flexible workflow selection (e.g., basic_api_test.json).
  • Dynamic parameters: prompt, width, height, and model.
  • Returns image URLs served by ComfyUI.

Prerequisites

  • Python 3.10+
  • ComfyUI: Installed and running locally (e.g., on localhost:8188).
  • Dependencies: requests, websockets, mcp (install via pip).

Setup

  1. Clone the Repository: git clone cd comfyui-mcp-server

  2. Install Dependencies:

    pip install requests websockets mcp

  3. Start ComfyUI:

  • Install ComfyUI (see ComfyUI docs).
  • Run it on port 8188:
    cd <ComfyUI_dir>
    python main.py --port 8188
    
  1. Prepare Workflows:
  • Place API-format workflow files (e.g., basic_api_test.json) in the workflows/ directory.
  • Export workflows from ComfyUI’s UI with “Save (API Format)” (enable dev mode in settings).

Usage

  1. Run the MCP Server: python server.py
  • Listens on ws://localhost:9000.
  1. Test with the Client: python client.py
  • Sends a sample request: "a dog wearing sunglasses" with 512x512 using sd_xl_base_1.0.safetensors.
  • Output example:
    Response from server:
    {
      "image_url": "http://localhost:8188/view?filename=ComfyUI_00001_.png&subfolder=&type=output"
    }
    
  1. Custom Requests:
  • Modify client.py’s payload to change prompt, width, height, workflow_id, or model.
  • Example:
    "params": json.dumps({
        "prompt": "a cat in space",
        "width": 768,
        "height": 768,
        "workflow_id": "basic_api_test",
        "model": "v1-5-pruned-emaonly.ckpt"
    })
    

Project Structure

  • server.py: MCP server with WebSocket transport and lifecycle support.
  • comfyui_client.py: Interfaces with ComfyUI’s API, handles workflow queuing.
  • client.py: Test client for sending MCP requests.
  • workflows/: Directory for API-format workflow JSON files.

Notes

  • Ensure your chosen model (e.g., v1-5-pruned-emaonly.ckpt) exists in <ComfyUI_dir>/models/checkpoints/.
  • The MCP SDK lacks native WebSocket transport; this uses a custom implementation.
  • For custom workflows, adjust node IDs in comfyui_client.py’s DEFAULT_MAPPING if needed.

Contributing

Feel free to submit issues or PRs to enhance flexibility (e.g., dynamic node mapping, progress streaming).

License

Apache License

comfyui-mcp-server FAQ

How do I install comfyui-mcp-server?
Clone the repository, install dependencies with pip, and ensure ComfyUI is running locally.
What are the prerequisites for running comfyui-mcp-server?
Python 3.10+, a local ComfyUI instance, and Python packages requests, websockets, and mcp.
How does comfyui-mcp-server communicate with ComfyUI?
It uses the MCP protocol over WebSocket to send image generation requests and receive results.
Can I customize image generation parameters?
Yes, you can specify prompt, width, height, and model dynamically in requests.
Does comfyui-mcp-server support multiple image generation workflows?
Yes, it supports flexible workflow selection like basic_api_test.json.
How are generated images accessed?
The server returns URLs pointing to images served by the local ComfyUI instance.
Is comfyui-mcp-server limited to specific operating systems?
No, it runs wherever Python 3.10+ and ComfyUI are supported, typically cross-platform.
Can I extend comfyui-mcp-server for other MCP clients?
Yes, it is designed to interface with any MCP-compliant AI agent over WebSocket.