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.
This server requires a running ComfyUI instance. You must either:
Edit the src/.env
file to specify your ComfyUI server location:
COMFYUI_HOST=localhost
COMFYUI_PORT=8188
To extend functionality with additional tools:
workflows
directoryCreate 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.
# 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"
]
}
}
}
{
"mcpServers": {
"comfyui": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-p",
"3001:3000",
"overseer66/mcp-comfyui"
]
}
}
}
When using Docker:
RETURN_URL=false
in .env
to receive image data as bytesCOMFYUI_HOST
in .env
to the appropriate address (e.g., host.docker.internal
or your server's IP)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"
}
}
}
Generates an image from text and returns the URL of the generated image.
To access the actual image:
download_image
tool, orDownloads images generated by other tools (like text_to_image
) using the image URL.
Run a custom workflow by providing the path to a workflow JSON file.
Example usage:
Run comfyui workflow with text_to_image.json
Run a workflow by providing the workflow JSON data directly.
Example usage:
Run comfyui workflow with this
{
"3": {
"inputs": {
"seed": 156680208700286,
"steps": 20,
...
}
}
...
}
Test your ComfyUI connection:
python src/test_comfyui.py
Debug the MCP integration:
mcp dev src/server.py
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.
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.