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.jsonwhich 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_URLto point to your Comfy server URL.COMFY_WORKFLOW_JSON_FILEto point to the absolute path of the API export json file for the comfyui workflow.PROMPT_NODE_IDto the id of the text prompt node.OUTPUT_NODE_IDto the id of the output node with the final image.OUTPUT_MODEto eitherurlorfileto select desired output.
Optionally, if you have an Ollama server running, you can connect to it for prompt generation.
OLLAMA_API_BASEto the url where ollama is running.PROMPT_LLMto 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:
- Checks if all the environment variable are set.
- Loads a prompt template from a JSON file.
- Submits the prompt to the Comfy server.
- Polls the server for the status of the prompt processing.
- 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
mcp: For setting up the FastMCP server.json: For handling JSON data.urllib: For making HTTP requests.time: For adding delays in polling.os: For accessing environment variables.langchain: For creating simple LLM Prompt chain to generate image generation prompt from topic.langchain-ollama: For ollama specific modules for LangChain.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for comfy-mcp-server 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| comfy_mcp_server-0.1.11.tar.gz | 92.1 kB | Without provenance | Details for comfy_mcp_server-0.1.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| comfy_mcp_server-0.1.11-py3-none-any.whl | Python 3 | none | any | Details for comfy_mcp_server-0.1.11-py3-none-any.whl |
Total release size: 97.3 kB
Release files / comfy_mcp_server-0.1.11.tar.gz
| Download URL | comfy_mcp_server-0.1.11.tar.gz |
|---|---|
| Size | 92.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f60f48e759460705b0e934e5f7aadcd30a8e2e883d27baa4fc290a07d17311e1
|
|
BLAKE2b-256 checksum How to use checksums |
9d1b186548066310b75046afe2784d58a54d53bf16bacec35bd1c104e8a3bb74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.14
|
Release files / comfy_mcp_server-0.1.11-py3-none-any.whl
| Download URL | comfy_mcp_server-0.1.11-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cea3532b58de56c069ff6dbdee24e900222c37fc0f8a2b977df5a66c58124fb
|
|
BLAKE2b-256 checksum How to use checksums |
639ff1aaab4c6d86f366d03bce8c7395918b98779ad28bcc808c44618d51ade2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.14
|
Security for comfy-mcp-server 0.1.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.