The ComfyUI MCP Server provides a bridge between AI agents and ComfyUI, allowing programmatic image generation through the Model Context Protocol (MCP). This lightweight Python server accepts WebSocket requests and translates them into ComfyUI workflows, returning generated image URLs.
requests
, websockets
, and mcp
First, ensure ComfyUI is installed and running:
# Install ComfyUI (if not already installed)
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
# Start ComfyUI on port 8188
python main.py --port 8188
# Clone the repository
git clone <your-repo-url>
cd comfyui-mcp-server
# Install dependencies
pip install requests websockets mcp
The server needs workflow files to process image generation requests:
workflows/
directory of the MCP serverRun the server to begin listening for WebSocket connections:
python server.py
The server will be available at ws://localhost:9000
.
A test client is included to verify the server works correctly:
python client.py
This sends a sample request to generate an image of "a dog wearing sunglasses" at 512×512 resolution using the SD XL model.
When successful, you'll receive a response like:
{
"image_url": "http://localhost:8188/view?filename=ComfyUI_00001_.png&subfolder=&type=output"
}
You can open this URL in a browser to view the generated image.
Modify the payload in client.py
to create custom image generation requests:
"params": json.dumps({
"prompt": "a cat in space", # Text description of the image
"width": 768, # Image width in pixels
"height": 768, # Image height in pixels
"workflow_id": "basic_api_test", # Workflow JSON file (without extension)
"model": "v1-5-pruned-emaonly.ckpt" # Stable Diffusion model to use
})
Make sure the specified model (e.g., v1-5-pruned-emaonly.ckpt
) exists in your ComfyUI installation's models/checkpoints/
directory.
localhost:8188
before starting the MCP serverworkflows/
directoryThere are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.