Integrates ComfyUI with WebSocket communication for on-demand image generation, enabling customizable requests with para...
Created byApr 22, 2025
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:
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
Run the MCP Server:
python server.py
Listens on ws://localhost:9000.
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:
Custom Requests:
Modify client.py s payload to change prompt, width, height, workflow_id, or model.
Example:
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
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: