LC

lalanikarim/comfy-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

46 stars 17 forks 质量 66 趋势 0MIT

lalanikarim/comfy-mcp-server 是从 https://github.com/lalanikarim/comfy-mcp-server. 导入的 MCP 服务器候选

概览

lalanikarim/comfy-mcp-server 是从 https://github.com/lalanikarim/comfy-mcp-server. 导入的 MCP 服务器候选

概述(AI 翻译)

一台使用FastMCP框架,通过远程Comfy服务器根据提示生成图像的服务器。

概述

该脚本利用FastMCP框架搭建服务器,根据指定工作流程生成提示生成图像。它与远程Comfy服务器交互,提交提示并检索生成图像。

先修条件

  • Python 的 uv 包和项目管理器。
  • 从 Comfy UI 导出的工作流文件。本代码包含一个示例 Flux-Dev-ComfyUI-Workflow.json,仅作为参考使用。你需要从工作流程导出并相应设置环境变量。

您可以安装本地开发所需的软件包:

配置

设置以下环境变量:

  • COMFY_URL 指向你的 Comfy 服务器 URL。
  • COMFY_WORKFLOW_JSON_FILE 指向 comfyui 工作流程 API 导出 json 文件的绝对路径。
  • PROMPT_NODE_ID 到文本提示节点的 ID。
  • OUTPUT_NODE_ID 映射到带有最终图像的输出节点的 ID。
  • OUTPUT_MODE 切换到 url 或 file 以选择所需输出。

可选地,如果你有运行的 Ollama 服务器,可以连接它进行提示生成。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Comfy MCP Server

A server using FastMCP framework to generate images based on prompts via a remote Comfy server.

Overview

This script sets up a server using the FastMCP framework to generate images based on prompts using a specified workflow. It interacts with a remote Comfy server to submit prompts and retrieve generated images.

Prerequisites

  • uv package and project manager for Python.
  • Workflow file exported from Comfy UI. This code includes a sample Flux-Dev-ComfyUI-Workflow.json which is only used here as reference. You will need to export from your workflow and set the environment variables accordingly.

You can install the required packages for local development:

uvx mcp[cli]

Configuration

Set the following environment variables:

  • COMFY_URL to point to your Comfy server URL.
  • COMFY_WORKFLOW_JSON_FILE to point to the absolute path of the API export json file for the comfyui workflow.
  • PROMPT_NODE_ID to the id of the text prompt node.
  • OUTPUT_NODE_ID to the id of the output node with the final image.
  • OUTPUT_MODE to either url or file to select desired output.

Optionally, if you have an Ollama server running, you can connect to it for prompt generation.

  • OLLAMA_API_BASE to the url where ollama is running.
  • PROMPT_LLM to the name of the model hosted on ollama for prompt generation.

Example:

export COMFY_URL=http://your-comfy-server-url:port
export COMFY_WORKFLOW_JSON_FILE=/path/to/the/comfyui_workflow_export.json
export PROMPT_NODE_ID=6 # use the correct node id here
export OUTPUT_NODE_ID=9 # use the correct node id here
export OUTPUT_MODE=file

Usage

Comfy MCP Server can be launched by the following command:

uvx comfy-mcp-server

Example Claude Desktop Config

{
  "mcpServers": {
    "Comfy MCP Server": {
      "command": "/path/to/uvx",
      "args": [
        "comfy-mcp-server"
      ],
      "env": {
        "COMFY_URL": "http://your-comfy-server-url:port",
        "COMFY_WORKFLOW_JSON_FILE": "/path/to/the/comfyui_workflow_export.json",
        "PROMPT_NODE_ID": "6",
        "OUTPUT_NODE_ID": "9",
        "OUTPUT_MODE": "file",
      }
    }
  }
}

Functionality

generate_image(prompt: str, ctx: Context) -> Image | str

This function generates an image using a specified prompt. It follows these steps:

  1. Checks if all the environment variable are set.
  2. Loads a prompt template from a JSON file.
  3. Submits the prompt to the Comfy server.
  4. Polls the server for the status of the prompt processing.
  5. Retrieves and returns the generated image once it’s ready.

generate_prompt(topic: str, ctx: Context) -> str

This function generates a comprehensive image generation prompt from specified topic.

Dependencies

在 GitHub 查看完整 README

安装

uvx mcp[cli]
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "Comfy MCP Server": { "command": "/path/to/uvx", "args": [ "comfy-mcp-server" ], "env": { "COMFY_URL": "http://your-comfy-server-url:port", "COMFY_WORKFLOW_JSON_FILE": "/path/to/the/comfyui_workflow_export.json", "PROMPT_NODE_ID": "6", "OUTPUT_NODE_ID": "9", "OUTPUT_MODE": "file", } } } }