Skip to main content
Glama

ComfyUI MCP 服务器

1.概述

  • 用于集成 ComfyUI 与 MCP 的服务器实现。

  • ⚠️ 重要提示:此服务器需要正在运行的 ComfyUI 服务器。

    • 您必须托管自己的 ComfyUI 服务器,

    • 或者访问现有的 ComfyUI 服务器地址。


Related MCP server: Stability AI MCP Server

2. 调试

2.1 ComfyUI 调试

python src/test_comfyui.py

2.2 MCP调试

mcp dev src/server.py

3.安装和配置

3.1 ComfyUI 配置

  • 编辑src/.env以设置 ComfyUI 主机和端口:

    COMFYUI_HOST=localhost COMFYUI_PORT=8188

3.2 添加自定义工作流程

  • 要添加新工具,请将工作流 JSON 文件放在workflows目录中,并在系统中将其声明为新工具。


4.内置工具

  • 文本转图像

    • 仅返回所生成图像的 URL。

    • 要获取实际图像:

      • 使用download_image工具,或者

      • 直接在浏览器中访问该 URL。

  • 下载图片

    • 使用图像 URL 下载由其他工具(如text_to_image )生成的图像。

  • 运行工作流与文件

    • 通过提供工作流 JSON 文件的路径来运行工作流。

      # You should ask to agent like this. Run comfyui workflow with text_to_image.json
    • CursorAI 的示例图像

  • 使用 json 运行工作流

    • 通过直接提供工作流 JSON 数据来运行工作流。

      # You should ask to agent like this. Run comfyui workflow with this { "3": { "inputs": { "seed": 156680208700286, "steps": 20, ... (workflow JSON example) }

5. 如何运行

5.1 使用紫外线(推荐)

  • 示例mcp.json

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

5.2 使用 Docker

  • 由于 Docker 容器不共享主机文件系统,因此使用download_image将图像下载到本地文件夹可能会很困难。

  • 使用 Docker 时,请考虑:

    1. .env中设置RETURN_URL=false以字节形式接收图像数据。

    2. .env中的COMFYUI_HOST设置为适当的地址(例如, host.docker.internal或服务器的 IP)。

    3. 注意:使用二进制数据时,大型图像有效载荷可能会超出响应限制。

5.2.1 构建 Docker 镜像

# First build image docker image build -t mcp/comfyui .
{ "mcpServers": { "comfyui": { "command": "docker", "args": [ "run", "-i", "--rm", "-p", "3001:3000", "mcp/comfyui" ] } } }

5.2.2 使用现有图像

您也可以使用预先构建的图像。

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

5.2.3 使用 SSE 传输

  1. 使用 Docker 运行 SSE 服务器:

    docker run -i --rm -p 8001:8000 overseer66/mcp-comfyui-sse
  2. 配置mcp.json (如果需要,将 localhost 更改为您的 IP 或域):

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

注意:当添加新的工作流程作为工具时,您需要重建并重新部署 Docker 镜像以使其可用。


One-click Deploy
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Overseer66/comfyui-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server