Universe Imagine MCP
Enables AI image generation from text prompts by wrapping local ComfyUI as a Streamable HTTP MCP server, supporting synchronous generation, queue management, and history tracking.
README
Universe Imagine MCP
MCP server for AI image generation. Wraps local ComfyUI as a Streamable HTTP MCP server. Works with any MCP-compatible bot client.
Features
- Streamable HTTP — MCP
2024-11-05protocol, Bearer auth - Synchronous generation —
generate_imageblocks and returns the image URL directly - Background queue — multiple requests accepted, processed one at a time
- Idempotency keys — safe retries without duplicates
- Player-aware — reads
player_idfrom MCP initialize handshake - Generation history — SQLite, with
sincefilter for incremental queries - Health endpoint — reports backend status, queue depth, uptime
- Image serving — built-in static file server for generated images
- Idle watchdog — stops ComfyUI after 5 minutes of inactivity to free VRAM
- Warm start — ComfyUI starts in background when MCP server boots
- Discord webhook — optional generation notifications
Prerequisites
- Python 3.11+
- ComfyUI installed locally
- At least one model downloaded (e.g. Flux, SDXL, SD3, etc.)
Setup
# 1. Clone the repo
git clone https://github.com/BAWES-Universe/universe-imagine-mcp.git
cd universe-imagine-mcp
# 2. Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure
cp .env.example .env
# Edit .env — at minimum set DESIGNER_MCP_TOKEN and PUBLIC_URL_BASE
# Set MODEL_UNET, MODEL_CLIP, MODEL_VAE to match your ComfyUI models
# 5. Run
python3 designer_mcp.py
Configuration
All config goes in .env:
| Variable | Default | Description |
|---|---|---|
DESIGNER_MCP_TOKEN |
— | Bearer token for MCP auth (required) |
PUBLIC_URL_BASE |
— | Public base URL for image serving (required) |
HOST |
0.0.0.0 |
Listen address |
PORT |
8003 |
MCP server port |
COMFYUI_URL |
http://127.0.0.1:8188 |
ComfyUI API URL |
COMFYUI_DIR |
~/ComfyUI |
ComfyUI install directory |
DB_PATH |
./imagine.db |
SQLite database path |
OUTPUT_DIR |
~/ComfyUI/output |
ComfyUI output directory |
DISCORD_WEBHOOK_URL |
— | Discord webhook for generation notifications (optional) |
MODEL_UNET |
flux-2-klein-4b-fp8.safetensors |
UNet model filename |
MODEL_CLIP |
Qwen3-4B-Q4_K_M.gguf |
CLIP model filename |
MODEL_VAE |
flux2_klein_vae.safetensors |
VAE model filename |
Tools
generate_image(prompt, width=512, height=512, idempotency_key="") → JSON
Generate an image from a text prompt. Blocks until complete (typically 3-15 seconds) and returns the image URL directly. The image is auto-sent to the conversation by the bot.
Use idempotency_key to safely retry without duplicates — same key = cached result.
get_generation(generation_id) → JSON
Retrieve a past generation's full record by ID.
list_generations(limit=10, since="") → JSON array
List recent generations for the calling player. Optionally filter by ISO 8601 timestamp.
get_generation_status(generation_id) → JSON (legacy)
Legacy polling tool kept for backwards compatibility. The current generate_image is synchronous and returns the URL directly — polling is not needed.
DNS Rebinding — Monkey Patch
The server includes a monkey-patch for FastMCP's built-in DNS rebinding check (see designer_mcp.py lines 23-33). This is needed when running behind a reverse proxy or Cloudflare tunnel where the incoming Host header (e.g., imagine.yourdomain.com) doesn't match localhost.
If you're running behind a reverse proxy: The patch is safe because auth is handled by the BearerAuthMiddleware. Keep it.
If you're running on localhost only (no tunnel/proxy): Remove the patch entirely — delete lines 23-33 from designer_mcp.py.
The patch:
from mcp.server.transport_security import TransportSecurityMiddleware
_orig_validate = TransportSecurityMiddleware.validate_request
async def _patched_validate(self, request, is_post=False):
return None # Skip Host header validation
TransportSecurityMiddleware.validate_request = _patched_validate
Connecting to a Universe Bot
Register the MCP server on a bot via the admin API:
POST /api/bots/{botId}/mcp-servers
{
"serverUrl": "https://your-domain.com/mcp",
"transport": "streamable-http",
"authType": "bearer",
"authConfig": "your-token"
}
Player ID is sent automatically in the MCP initialize handshake — no extra config needed.
Architecture
┌─────────────┐ Streamable HTTP ┌──────────────────┐
│ Bot AI │ ◄─────────────────────── │ Imagine MCP │
│ (MCP client)│ /mcp (port 8003) │ (FastMCP) │
└─────────────┘ │ │
│ ┌────────────┐ │
┌─────────────┐ Static files │ │ Queue (1) │──┼──► _run_generation()
│ Browser │ ◄─────────────────────── │ └────────────┘ │
│ /images/* │ /images (port 8004) │ │ │
└─────────────┘ │ ▼ │
│ ┌────────────┐ │
curl /health │ │ ComfyUI │ │
─────────► /health (port 8005) │ │ (port 8188)│ │
│ └────────────┘ │
└──────────────────┘
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。