ComfyUI MCP server

Integrates ComfyUI with WebSocket communication for on-demand image generation, enabling customizable requests with parameters like prompt, width, and height.
Back to servers
Provider
Joe Norton
Release date
Mar 06, 2025
Language
Python
Stats
59 stars

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.

Prerequisites

  • Python 3.10 or newer
  • ComfyUI running on your local machine
  • Required Python packages: requests, websockets, and mcp

Installation

1. Set Up ComfyUI

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

2. Install the MCP Server

# Clone the repository
git clone <your-repo-url>
cd comfyui-mcp-server

# Install dependencies
pip install requests websockets mcp

3. Prepare Workflows

The server needs workflow files to process image generation requests:

  1. Enable developer mode in ComfyUI settings
  2. Create workflows in ComfyUI
  3. Export them using "Save (API Format)"
  4. Place these JSON files in the workflows/ directory of the MCP server

Using the MCP Server

Starting the Server

Run the server to begin listening for WebSocket connections:

python server.py

The server will be available at ws://localhost:9000.

Testing with the Sample Client

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.

Sample Response

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.

Customizing Requests

Request Parameters

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
})

Available Models

Make sure the specified model (e.g., v1-5-pruned-emaonly.ckpt) exists in your ComfyUI installation's models/checkpoints/ directory.

Troubleshooting

  • Ensure ComfyUI is running and accessible at localhost:8188 before starting the MCP server
  • Check that your workflow files are correctly formatted and placed in the workflows/ directory
  • Verify that the model specified in your request is available in ComfyUI

How to add this MCP server to Cursor

There 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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later