Skip to main content
Glama

Comfy MCP Server

by lalanikarim

舒适的 MCP 服务器

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

概述

此脚本使用 FastMCP 框架搭建了一个服务器,用于根据指定的工作流程,根据提示生成图像。该脚本与远程 Comfy 服务器交互,以提交提示并检索生成的图像。

先决条件

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

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

uvx mcp[cli]

配置

设置以下环境变量:

  • COMFY_URL指向您的 Comfy 服务器 URL。
  • COMFY_WORKFLOW_JSON_FILE指向 comfyui 工作流的 API 导出 json 文件的绝对路径。
  • PROMPT_NODE_ID为文本提示节点的id。
  • OUTPUT_NODE_ID为具有最终图像的输出节点的 id。
  • OUTPUT_MODEurlfile来选择所需的输出。

或者,如果您正在运行Ollama服务器,您可以连接到它来生成提示。

  • OLLAMA_API_BASE到 ollama 运行的 url。
  • PROMPT_LLM为 ollama 上托管的用于生成提示的模型的名称。

例子:

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

用法

Comfy MCP Server 可以通过以下命令启动:

uvx comfy-mcp-server

Claude 桌面配置示例

{ "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", } } } }

功能

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

此函数使用指定的提示生成图像。它遵循以下步骤:

  1. 检查所有环境变量是否都已设置。
  2. 从 JSON 文件加载提示模板。
  3. 将提示提交给 Comfy 服务器。
  4. 轮询服务器以获取提示处理的状态。
  5. 一旦准备好,检索并返回生成的图像。

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

此功能根据指定主题生成综合图像生成提示。

依赖项

  • mcp :用于设置 FastMCP 服务器。
  • json :用于处理 JSON 数据。
  • urllib :用于发出 HTTP 请求。
  • time :用于增加轮询的延迟。
  • os :用于访问环境变量。
  • langchain :用于创建简单的 LLM Prompt 链以从主题生成图像生成提示。
  • langchain-ollama :用于 LangChain 的 ollama 特定模块。

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Comfy MCP 服务器使用 FastMCP 框架通过与远程 Comfy 服务器交互从提示生成图像,从而允许根据工作流配置自动创建图像。

  1. 概述
    1. 先决条件
      1. 配置
        1. 用法
          1. Claude 桌面配置示例
        2. 功能
          1. generate_image(prompt: str, ctx: Context) -> Image | str
          2. generate_prompt(topic: str, ctx: Context) -> str
        3. 依赖项
          1. 执照

            Related MCP Servers

            • A
              security
              F
              license
              A
              quality
              A FastMCP server implementation that facilitates resource-based access to AI model inference, focusing on image generation through the Replicate API, with features like real-time updates, webhook integration, and secure API key management.
              Last updated -
              18
              15
              Python
              • Apple
            • A
              security
              A
              license
              A
              quality
              An MCP Server that integrates with Stability AI's API to provide high-quality image generation, editing, and manipulation capabilities including background removal, outpainting, search-and-replace, and upscaling.
              Last updated -
              13
              450
              73
              TypeScript
              MIT License
              • Apple
            • A
              security
              F
              license
              A
              quality
              An MCP server that generates images based on text prompts using Black Forest Lab's FLUX model, allowing for customized image dimensions, prompt upsampling, safety settings, and batch generation.
              Last updated -
              3
              1
              TypeScript
            • -
              security
              F
              license
              -
              quality
              An MCP image generation server based on the Flux Schnell model that provides API access for generating images from text prompts with customizable dimensions and seeds.
              Last updated -
              1
              Python
              • Linux
              • Apple

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/lalanikarim/comfy-mcp-server'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server