ComfyUI MCP服务器

ComfyUI MCP服务器是一个通用的、治理驱动的模型上下文协议服务器,能够将ComfyUI工作流自动转换为强类型的AI工具,供任何LLM使用。

  • by raphiki
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 raphiki/ComfyUI-MCP-Server

使用说明

ComfyUI MCP服务器

状态: 积极开发 治理: 严格合规协议处于活动状态(请参阅 /docs)

通用的, 治理驱动 用于ComfyUI的模型上下文协议(MCP)服务器。此服务器充当“动态工具工厂”,自动转换ComfyUI工作流(.json)将其转化为任何LLM(Claude、Flowise等)都可以使用的强类型AI工具。

🚀 核心功能

  • 动态工具厂: 只需将工作流程JSON放入 ./workflows/,并且它成为原生Python工具(例如。, generate_cyberpunk(seed: int)).
  • 智能注射: 使用以下命令将抽象参数映射到特定的ComfyUI节点 MCP_Config 公约。
  • 双重发现: 将功能同时公开 资源 (comfy://list)以及 工具 (list_workflows)为了实现最大的客户端兼容性(ADR-003)。
  • 治理驱动: 由AI构建,用于AI。代码库通过一组严格的文档规则和上下文边界进行管理。

📂 治理结构

该项目遵循严格的 治理驱动发展(GDD) 工作流程。文件是唯一的真相来源。

/comfy-mcp-server
├── docs/
│   ├── governance/            # The "Efficiency Layer" (Token budgets, Context maps)
│   ├── features/              # The "Requirements" (F001, F002)
│   ├── architecture/          # The "Blueprints" (ADRs, C4 Diagrams)
│   └── implementation/        # The "Execution" (Plans, Logs, Rules)
└── workflows/                 # Drop ComfyUI JSONs here

🛠️ 快速开始

1.先决条件

  • Python 3.10+
  • ComfyUI在本地运行(默认值: http://127.0.0.1:8188)
  • Node.js(可选,用于MCP检查器)

2.安装

# Clone repository
git clone https://github.com/your-repo/comfy-mcp-server.git
cd comfy-mcp-server

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows

# Install dependencies (Strictly pinned in tech_stack.md)
pip install "mcp[cli]>=1.2.0" "pydantic>=2.10.0" "makefun>=1.15.0" "fastapi>=0.115.0" "uvicorn>=0.34.0" requests websocket-client

3.使用方法

SSE模式(建议用于Flowise/Web)

chmod +x start_sse.sh
./start_sse.sh

服务器将在以下时间可用 http://localhost:8000/sse.

标准模式(适用于克劳德桌面)

./venv/bin/python server.py

🤖 客户端配置(Flowise/Claude)

SSE设置(流式)

  1. 使用 MCP工具 Flowise中的节点。
  2. 将SSE URL设置为 http://localhost:8000/sse.
  3. 添加以下内容 系统消息 致您的代理人:

    “总是打电话 list_available_workflows 首先发现工具。使用关键字 LAST 在图像参数中引用先前生成的图像。"

🧩 工作流约定

要使ComfyUI工作流兼容,请添加 备注 节点标题 MCP_Config 使用以下JSON格式:

{
  "name": "generate_art",
  "description": "Generates art based on a prompt.",
  "parameters": [
    {
      "name": "prompt",
      "type": "string",
      "description": "What to draw",
      "target": "MCP_Positive",
      "required": true
    },
    {
      "name": "seed",
      "type": "int",
      "description": "Random seed",
      "target": "MCP_Sampler",
      "required": false
    }
  ]
}
  1. 目标节点: 确保ComfyUI工作流中的节点具有 标题 匹配 target JSON中的字段(例如,将KSampler重命名为 MCP_Sampler).
  2. 出口: 将工作流导出到 API格式(JSON) 并将其保存到 ./workflows/ 目录。

看 docs/architecture/adr/ADR-002-workflow-convention.md 了解详情。