舒适的 MCP 服务器
使用 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服务器,您可以连接到它来生成提示。
OLLAMA_API_BASE
到 ollama 运行的 url。PROMPT_LLM
为 ollama 上托管的用于生成提示的模型的名称。
例子:
用法
Comfy MCP Server 可以通过以下命令启动:
Claude 桌面配置示例
功能
generate_image(prompt: str, ctx: Context) -> Image | str
此函数使用指定的提示生成图像。它遵循以下步骤:
- 检查所有环境变量是否都已设置。
- 从 JSON 文件加载提示模板。
- 将提示提交给 Comfy 服务器。
- 轮询服务器以获取提示处理的状态。
- 一旦准备好,检索并返回生成的图像。
generate_prompt(topic: str, ctx: Context) -> str
此功能根据指定主题生成综合图像生成提示。
依赖项
mcp
:用于设置 FastMCP 服务器。json
:用于处理 JSON 数据。urllib
:用于发出 HTTP 请求。time
:用于增加轮询的延迟。os
:用于访问环境变量。langchain
:用于创建简单的 LLM Prompt 链以从主题生成图像生成提示。langchain-ollama
:用于 LangChain 的 ollama 特定模块。
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。
Related MCP Servers
- AsecurityFlicenseAqualityA 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 -1815Python
- AsecurityAlicenseAqualityAn 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 -1345073TypeScriptMIT License
- AsecurityFlicenseAqualityAn 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 -31TypeScript
- -securityFlicense-qualityAn 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 -1Python
Appeared in Searches
- Instructions for accessing Gmail messages programmatically using a cursor
- Exploring text-to-image generation techniques
- A flexible and user-friendly UI tool for extended functionalities
- A platform for finding and downloading stock images using keywords
- A platform for downloading images from Unsplash using specified keywords