ComfyUI MCP server

Provides a bridge between AI systems and ComfyUI's image generation capabilities, enabling text-to-image creation with customizable parameters through WebSocket communication.
Back to servers
Provider
Overseer66
Release date
Apr 26, 2025
Language
Python
Stats
3 stars

The ComfyUI MCP Server provides integration between ComfyUI (a powerful stable diffusion interface) and MCP (Model Context Protocol). It enables you to run ComfyUI workflows through MCP, allowing AI agents to generate and manipulate images using natural language instructions.

Prerequisites

This server requires a running ComfyUI instance. You must either:

  • Host your own ComfyUI server
  • Have access to an existing ComfyUI server address

Installation and Configuration

Setting Up ComfyUI Connection

Edit the src/.env file to specify your ComfyUI server location:

COMFYUI_HOST=localhost
COMFYUI_PORT=8188

Adding Custom Workflows

To extend functionality with additional tools:

  1. Place your workflow JSON files in the workflows directory
  2. Declare them as new tools in the system

Running the Server

Using UV (Recommended)

Create an mcp.json file with the following configuration:

{
  "mcpServers": {
    "comfyui": {
      "command": "uv",
      "args": [
        "--directory",
        "PATH/MCP/comfyui",
        "run",
        "--with",
        "mcp",
        "--with",
        "websocket-client",
        "--with",
        "python-dotenv",
        "mcp",
        "run",
        "src/server.py:mcp"
      ]
    }
  }
}

Replace PATH/MCP/comfyui with the actual path to your installation.

Using Docker

Building a Docker Image

# First build image
docker image build -t mcp/comfyui .

Then configure your mcp.json:

{
  "mcpServers": {
    "comfyui": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-p",
        "3001:3000",
        "mcp/comfyui"
      ]
    }
  }
}

Using Pre-built Images

{
  "mcpServers": {
    "comfyui": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-p",
        "3001:3000",
        "overseer66/mcp-comfyui"
      ]
    }
  }
}

Docker Configuration Notes

When using Docker:

  • Set RETURN_URL=false in .env to receive image data as bytes
  • Set COMFYUI_HOST in .env to the appropriate address (e.g., host.docker.internal or your server's IP)
  • Be aware that large image payloads may exceed response limits

Using SSE Transport

Run the SSE server with Docker:

docker run -i --rm -p 8001:8000 overseer66/mcp-comfyui-sse

Configure mcp.json (change localhost to your IP or domain if needed):

{
  "mcpServers": {
    "comfyui": {
      "url": "http://localhost:8001/sse" 
    }
  }
}

Available Tools

text_to_image

Generates an image from text and returns the URL of the generated image.

To access the actual image:

  • Use the download_image tool, or
  • Access the URL directly in your browser

download_image

Downloads images generated by other tools (like text_to_image) using the image URL.

run_workflow_with_file

Run a custom workflow by providing the path to a workflow JSON file.

Example usage:

Run comfyui workflow with text_to_image.json

run_workflow_with_json

Run a workflow by providing the workflow JSON data directly.

Example usage:

Run comfyui workflow with this 
{
  "3": {
      "inputs": {
          "seed": 156680208700286,
          "steps": 20,
          ...
      }
  }
  ...
}

Debugging

ComfyUI Connection Testing

Test your ComfyUI connection:

python src/test_comfyui.py

MCP Debugging

Debug the MCP integration:

mcp dev src/server.py

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