comfyui-mcp-server
by: joenorton
comfyui mcp server
📌Overview
Purpose: To provide a lightweight server that allows AI agents to programmatically generate images through ComfyUI using the Model Context Protocol (MCP) via WebSockets.
Overview: The ComfyUI MCP Server facilitates seamless communication between AI agents and ComfyUI for image generation, leveraging the MCP protocol to allow for a flexible and dynamic image generation workflow.
Key Features:
-
Flexible Workflow Selection: Supports various workflow formats (e.g.,
basic_api_test.json
), allowing users to choose different image generation processes easily. -
Dynamic Parameters: Users can customize requests with adjustable parameters such as
prompt
,width
,height
, andmodel
, providing great flexibility for image generation. -
Image URL Response: The server returns generated image URLs directly from ComfyUI, simplifying the process of accessing and using generated images.
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 and dynamic parameters: prompt
, width
, height
, and model
.
Prerequisites
- Python 3.10+
- ComfyUI: Installed and running locally (e.g., on
localhost:8188
). - Dependencies: Install via pip:
pip install requests websockets mcp
Setup
-
Clone the Repository:
git clone <your-repo-url> cd comfyui-mcp-server
-
Start ComfyUI:
- Run it on port 8188:
cd <ComfyUI_dir> python main.py --port 8188
-
Prepare Workflows:
- Place API-format workflow files (e.g.,
basic_api_test.json
) in theworkflows/
directory.
- Place API-format workflow files (e.g.,
Usage
-
Run the MCP Server:
python server.py
- Listens on
ws://localhost:9000
.
- Listens on
-
Test with the Client:
python client.py
- Sends a sample request with a specified prompt.
-
Custom Requests:
- Modify
client.py
’spayload
to change the request parameters.
- Modify
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
exists in<ComfyUI_dir>/models/checkpoints/
. - The MCP SDK uses a custom implementation for WebSocket transport.
- For custom workflows, adjust node IDs in
comfyui_client.py
if needed.
Contributing
Feel free to submit issues or PRs to enhance flexibility.
License
Apache License.