工作流管理服务器

一个生产就绪的MCP服务器,通过模型上下文协议(MCP)为ComfyUI提供DSL优先的工作流管理,使AI代理能够使用人类可读的领域特定语言(DSL)管理ComfyUI工作流。

  • by christian-byrne
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 christian-byrne/comfy-mcp

使用说明

ComfyUI MCP服务器

通过模型上下文协议(MCP)对ComfyUI进行DSL首次工作流管理

一个生产就绪的MCP服务器,使AI代理能够使用人类可读的领域特定语言(DSL)管理ComfyUI工作流。核心设计理念是 DSL优先:代理完全以DSL格式工作,JSON转换透明进行。

🚀 快速开始

安装

pip install comfy-mcp

使用Claude代码

  1. 创建MCP配置:
{
  "mcpServers": {
    "comfyui-workflows": {
      "command": "comfy-mcp",
      "args": [],
      "env": {}
    }
  }
}
  1. 使用MCP启动Claude代码:
claude --mcp-config mcp_config.json
  1. 在对话中使用:
"Execute this workflow: [paste DSL]"
"List workflows in examples directory"
"Show ComfyUI queue status"

✨ 特性

🔄 DSL第一设计

  • 代理完全在人类可读的DSL中工作
  • 自动JSON↔ DSL转换
  • 无需考虑格式转换

📁 文件操作

  • read_workflow -自动将JSON转换为DSL
  • write_workflow -将DSL保存为JSON/DSL
  • list_workflows -发现工作流文件
  • validate_workflow -DSL语法验证
  • get_workflow_info -工作流分析

⚡ 执行操作

  • execute_workflow -在ComfyUI上运行DSL工作流
  • get_job_status -监控执行并下载图像
  • list_comfyui_queue -查看ComfyUI队列状态

🎨 DSL语法示例

## Model Loading

checkpoint: CheckpointLoaderSimple
  ckpt_name: sd_xl_base_1.0.safetensors

## Text Conditioning

positive: CLIPTextEncode
  text: a beautiful landscape, detailed, photorealistic
  clip: @checkpoint.clip

negative: CLIPTextEncode
  text: blurry, low quality
  clip: @checkpoint.clip

## Generation

latent: EmptyLatentImage
  width: 1024
  height: 1024

sampler: KSampler
  model: @checkpoint.model
  positive: @positive.conditioning
  negative: @negative.conditioning
  latent_image: @latent.latent
  seed: 42
  steps: 20

## Output

decode: VAEDecode
  samples: @sampler.latent
  vae: @checkpoint.vae

save: SaveImage
  images: @decode.image
  filename_prefix: output

🏗️ 建筑

┌─────────────────┐    ┌──────────────┐    ┌─────────────┐
│   AI Agent      │────│  MCP Server  │────│  ComfyUI    │
│   (Claude)      │    │              │    │   Server    │
└─────────────────┘    └──────────────┘    └─────────────┘
         │                       │                  │
         │ DSL Workflows         │ JSON API         │
         │                       │                  │
         ▼                       ▼                  ▼
   Natural Language ────► DSL Parser ────► JSON Converter

关键部件:

  • DSL解析器:将人类可读的DSL转换为抽象语法树
  • Json转换器:DSL和ComfyUI JSON之间的双向转换
  • MCP服务器:通过模型上下文协议公开工具
  • 执行引擎:与ComfyUI API集成以执行工作流

📖 文档

核心类

  • DSLParser:将DSL文本解析为抽象语法树
  • DslToJsonConverter:将DSL AST转换为ComfyUI JSON
  • JsonToDslConverter:将ComfyUI JSON转换为DSL AST

MCP工具

工具 说明 示例
read_workflow 读取工作流并将其转换为DSL read_workflow("workflow.json")
write_workflow 将DSL以JSON/DSL格式写入磁盘 write_workflow("output.json", dsl)
list_workflows 查找工作流文件 list_workflows("./workflows")
validate_workflow 检查DSL语法 validate_workflow(dsl_content)
get_workflow_info 分析结构 get_workflow_info(dsl_content)
execute_workflow 在ComfyUI上运行 execute_workflow(dsl_content)
get_job_status 监控执行情况 get_job_status(prompt_id)
list_comfyui_queue 查看队列 list_comfyui_queue()

🛠️ 发展

设置

git clone https://github.com/christian-byrne/comfy-mcp.git
cd comfy-mcp
pip install -e ".[dev]"
pre-commit install

测试

# Run all tests
pytest

# Run with coverage
pytest --cov=comfy_mcp --cov-report=html

# Run specific test types
pytest -m unit
pytest -m integration
pytest -m "not slow"

代码质量

# Format code
black .

# Lint code  
ruff check .

# Type checking
mypy comfy_mcp

文档

cd docs
make html

🔧 配置

环境变量

  • COMFYUI_SERVER:ComfyUI服务器地址(默认值: 127.0.0.1:8188)
  • MCP_DEBUG:启用调试日志记录
  • MCP_LOG_LEVEL:设置日志级别(调试、信息、警告、错误)

ComfyUI设置

  1. 安装舒适装置
  2. 启动服务器: python main.py --listen 0.0.0.0
  3. 确保模型安装在 models/checkpoints/

🤝 贡献

我们欢迎捐款!请看 贡献.md 作为指导方针。

开发工作流程

  1. 分叉存储库
  2. 创建要素分支: git checkout -b feature-name
  3. 进行更改并添加测试
  4. 运行测试和梳理: pytest && black . && ruff check .
  5. 提交拉取请求

📄 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

🙏 致谢

📈 路线图

  • [ ] v0.2.0版本:增强的DSL功能(模板、宏)
  • [ ] v0.3.0:用于工作流管理的Web UI
  • [ ] v0.4.0:用于工作流版本控制的Git集成
  • [ ] v0.5.0:ComfyUI节点发现和文档
  • [ ] v1.0.0:生产部署功能

内置❤️ 面向ComfyUI和AI自动化社区