comfyui-mcp

comfyui-mcp

Exposes ComfyUI workflows as callable MCP tools, enabling LLMs to run image generation workflows via API.

Category
访问服务器

README

comfyui-mcp

A Model Context Protocol(MCP) server that exposes ComfyUI workflows as callable MCP tools. Built using FastMCP and comfyui-utils.

PyPI Version Python Versions License: MIT CI


Installation

Contents of this package require Python 3.11 or higher.

pip install comfyui-mcp

Quick Start

mcpo --port 8000 --api-key "AwesomeKey" -- python3 -m comfyui_mcp.server

Arguments

ComfyUI Connection (--comfyui.*)

  • --comfyui.host (default: 127.0.0.1:8188) - ComfyUI host and port
  • --comfyui.request_timeout (default: 5) - Timeout in seconds for ComfyUI API requests
  • --comfyui.use_remote_workflow (default: True) - Pull workflows from ComfyUI API (True) or load from local directory (False)
  • --comfyui.workflow_directory (default: workflows) - Local directory path for workflow JSON files

Output Formatting (--generate.*)

  • --generate.audio_url_template - Template for audio output URLs (vars: {index}, {url})
  • --generate.image_url_template - Template for image output URLs (vars: {index}, {url})
  • --generate.unknown_url_template - Template for unknown output types (vars: {index}, {url})
  • --generate.nothing_generated_message - Message when workflow executes but produces no output
  • --generate.reply_include_workflow (default: True) - Include executed workflow parameters in response
  • --generate.reply_workflow_format_indent (default: 2) - JSON indentation for workflow output
  • --generate.reply_workflow_format_sort_keys (default: True) - Sort JSON keys in workflow output
  • --generate.reply_workflow_template - Template for workflow parameters section (vars: {workflow_params})
  • --generate.result_generated_message_template - Overall message template (vars: {image_list})

Architecture Overview

src/comfyui_mcp/
  • __about__.py: Version and license metadata
  • argument_parser.py: CLI argument definitions using pydantic
  • base_types.py: Shared type aliases
  • function_utils.py: Dynamic function wrapper generation
  • workflow_loader.py: Load workflows from disk or ComfyUI API
  • workflow_utils.py: Workflow preparation and invocation
  • server.py: FastMCP server entry point

How It Works

  1. Workflow Preparation:

    • For local workflows: Export your ComfyUI workflow in API format (use "Save (API Format)" in ComfyUI's menu). Place the JSON file in your configured workflows directory.
    • For remote workflows: Build and save your workflow in ComfyUI, then start or restart the MCP server. The server will automatically fetch and register available workflows from the ComfyUI instance.
  2. Tool Registration: The server parses workflow JSON and automatically detects parameters by scanning for:

    • Primitive nodes (PrimitiveFloat, PrimitiveInt, PrimitiveString, etc.) - extracted as typed parameters
    • LoadImageOutput nodes - exposed as image input parameters
    • Node titles (from _meta.title) become the parameter names in the MCP tool
  3. Workflow Execution: When a tool is invoked:

    • User-provided parameters are mapped back to their corresponding primitive nodes
    • The workflow is deep-copied and parameter values are injected into inputs.value fields
    • The prepared workflow is submitted to ComfyUI's API
    • Results are polled until completion
    • Generated outputs are returned as accessible URLs (format is user-configurable)
  4. Batch Processing: Supports submit_batch parameter for generating multiple variations:

    • Automatically randomizes seeds for each generation
    • Executes workflows sequentially
    • Collects and returns all results together

Development

pip setup -hatch
hatch test
hatch build
hatch run release

Contributing

  1. Fork the repo on GitHub.
  2. Make changes, add tests, and build
  3. Run hatch test to ensure all passes
  4. Submit a PR

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选