ComfyUI MCP服务器
  ](https://badge.fury.io/py/comfy-mcp)  
通过模型上下文协议(MCP)对ComfyUI进行DSL首次工作流管理
一个生产就绪的MCP服务器,使AI代理能够使用人类可读的领域特定语言(DSL)管理ComfyUI工作流。核心设计理念是 DSL优先:代理完全以DSL格式工作,JSON转换透明进行。
🚀 快速开始
安装
pip install comfy-mcp使用Claude代码
- 创建MCP配置:
{
"mcpServers": {
"comfyui-workflows": {
"command": "comfy-mcp",
"args": [],
"env": {}
}
}
}- 使用MCP启动Claude代码:
claude --mcp-config mcp_config.json- 在对话中使用:
"Execute this workflow: [paste DSL]"
"List workflows in examples directory"
"Show ComfyUI queue status"✨ 特性
🔄 DSL第一设计
- 代理完全在人类可读的DSL中工作
- 自动JSON↔ DSL转换
- 无需考虑格式转换
📁 文件操作
read_workflow-自动将JSON转换为DSLwrite_workflow-将DSL保存为JSON/DSLlist_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 JSONJsonToDslConverter:将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设置
- 安装舒适装置
- 启动服务器:
python main.py --listen 0.0.0.0 - 确保模型安装在
models/checkpoints/
🤝 贡献
我们欢迎捐款!请看 贡献.md 作为指导方针。
开发工作流程
- 分叉存储库
- 创建要素分支:
git checkout -b feature-name - 进行更改并添加测试
- 运行测试和梳理:
pytest && black . && ruff check . - 提交拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
📈 路线图
- \[ \] v0.2.0版本:增强的DSL功能(模板、宏)
- \[ \] v0.3.0:用于工作流管理的Web UI
- \[ \] v0.4.0:用于工作流版本控制的Git集成
- \[ \] v0.5.0:ComfyUI节点发现和文档
- \[ \] v1.0.0:生产部署功能
______________________________________________________________________
内置❤️ 面向ComfyUI和AI自动化社区
