Enables AI-powered image generation for game development via ComfyUI workflows, allowing generation of character portraits, item icons, environment textures, and other game assets dynamically during development or runtime in Godot 3.x and 4.x projects.
ComfyUI MCP Server
AI-powered image generation for game development via ComfyUI and the Model Context Protocol
Overview
ComfyUI MCP Server is a Model Context Protocol (MCP) server that bridges ComfyUI's powerful workflow-based AI image generation with modern development workflows. Originally designed for Godot game development, it can be used with any MCP-compatible client to generate game assets, concept art, and visual content dynamically.
Key Features
MCP Integration: Expose ComfyUI workflows as standardized MCP tools
Python API Client: Full-featured async ComfyUI API client with type safety
Workflow Templates: Pre-built templates for common game assets (characters, items, environments)
Async Operations: Non-blocking generation with real-time progress updates via WebSockets
Flexible Configuration: TOML files, environment variables, or Python code
Type Safe: Full type hints with strict mypy validation
Well Tested: Comprehensive test coverage with pytest
Production Ready: Retry logic, error handling, and logging built-in
Use Cases
Character Generation: NPC portraits, character sprites, concept art
Item Icons: Unique item icons from text descriptions
Environment Art: Background textures, tileable patterns, landscapes
Dynamic Content: Procedural asset generation during gameplay
Concept Art: Rapid visual prototyping and iteration
Batch Processing: Generate multiple asset variations efficiently
Table of Contents
Quick Start
Prerequisites
Python 3.10 or higher
python --version # Should be 3.10+ComfyUI installed and running
Download: ComfyUI GitHub
Default URL:
http://localhost:8188Verify: Open
http://localhost:8188in your browser
Stable Diffusion models
Download models and place in ComfyUI's
models/checkpoints/directoryRecommended: Stable Diffusion 1.5 or 2.1 for game assets
Installation
Basic Configuration
Option 1: Environment Variables (Recommended for getting started)
Option 2: TOML Configuration File
Create comfyui.toml in your project root:
See docs/CONFIGURATION.md for comprehensive configuration options.
Your First Generation
Using the Python API
Using the MCP Server
1. Configure MCP Server
Add to your .mcp.json:
More Configuration Examples:
Complete .mcp.json configuration examples are available in examples/mcp/:
Example | Description | Use Case |
Minimal configuration | Quick start, local development | |
Development setup | Game project development | |
Production deployment | Remote servers, teams | |
Custom workflow templates | Game-specific workflows | |
Multiple MCP instances | Large projects, asset categories | |
Docker/container setup | Containerized deployment | |
Windows environment | Windows development |
See examples/mcp/README.md for detailed documentation of each configuration.
2. Use via Claude Code or MCP Client
Installation
From Source (Development)
From PyPI (Coming Soon)
Dependencies
Core:
Python 3.10+
aiohttp- Async HTTP client for ComfyUI APIpydantic- Data validation and settings managementtomli- TOML configuration file parsingwebsockets- WebSocket support for real-time updates
Development:
pytest- Testing frameworkpytest-asyncio- Async test supportpytest-cov- Code coveragemypy- Static type checkingruff- Fast linting and formattingpre-commit- Git hooks for code quality
Configuration
ComfyUI MCP Server supports three configuration methods:
1. TOML Configuration File (Recommended for Projects)
Create comfyui.toml:
Configuration file locations (searched in order):
./comfyui.toml(current directory)~/.config/comfyui/comfyui.toml(user config)/etc/comfyui/comfyui.toml(system-wide)
2. Environment Variables (Recommended for Deployment)
3. Python Code (Programmatic Configuration)
Configuration Priority
When multiple methods are used:
Python code (highest priority)
Environment variables
TOML configuration file
Default values (lowest priority)
Example Configuration Files
Complete example configuration files are available in examples/config/:
File | Description | Use Case |
| Minimal configuration with only required settings | Quick start, beginners |
| Standard configuration with common options | General development |
| Development environment settings | Local development |
| Production environment settings | Production deployment |
| Testing and CI/CD configuration | Automated testing |
| Docker and Kubernetes deployment | Containerized environments |
| Comprehensive reference with all options | Complete documentation |
| Environment variables template | Docker, CI/CD |
Quick start:
See docs/CONFIGURATION.md for comprehensive configuration documentation.
Usage
MCP Server Usage
The MCP server exposes ComfyUI functionality as standardized MCP tools.
Available MCP Tools
Tool | Description |
| Generate images using workflow templates |
| List available workflow templates |
| Check generation progress and status |
| Cancel a running workflow |
| Load and use a custom workflow file |
Example: Generate Image Tool
Starting the MCP Server
Python API Client
Direct programmatic access to ComfyUI API.
Basic Usage
Submitting Workflows
Queue Management
Retrieving Generated Images
Error Handling
See docs/API.md for complete API documentation.
Workflow Templates
Pre-built workflow templates for common game asset types.
Available Templates
Template | Description | Size | Use Case |
| Character portraits and avatars | 512x512 | RPG character art, NPC portraits |
| Centered item icons | 512x512 | Inventory items, UI icons |
| Tileable environment textures | 1024x1024 | Backgrounds, terrain textures |
| Upscaled pixel art style | 256x256 | Retro games, pixel art assets |
Using Templates
Creating Custom Templates
See docs/workflow-templates.md for template creation guide.
Documentation
Comprehensive documentation is available in the docs/ directory:
API Reference - Complete Python API documentation
ComfyUIClient methods and parameters
Pydantic models and data structures
Exception handling
Type hints and examples
Configuration Guide - Configuration options and best practices
TOML file format and schema
Environment variables
Configuration priority
Example configurations
ComfyUI API Integration - ComfyUI REST API patterns
API endpoints and methods
Workflow structure
Queue management
WebSocket integration
MCP Tool Usage - Complete MCP tool reference and usage guide
All 5 MCP tools documented
Integration patterns and examples
Best practices and troubleshooting
Workflow Creation Tutorial - Comprehensive guide to creating ComfyUI workflows
Understanding workflow structure and node system
Creating workflows from scratch
Parameter substitution and templates
Advanced techniques (LoRA, ControlNet, batching)
Integration with MCP server
Complete examples for characters, items, and environments
Workflow Template System - Complete workflow template system documentation
Template structure and file format
Creating and using templates
Built-in templates (character, item, environment, pixel art)
Parameter substitution engine
WorkflowTemplateManager usage
Best practices and advanced topics
Complete examples and troubleshooting
Godot Integration (coming soon) - Godot plugin and examples
Examples
Practical examples are available in the examples/ directory:
Example Projects
Character Portrait Generation - Generate RPG character portraits
Item Icon Batch Generation - Batch generate inventory icons
Environment Textures - Create tileable background textures
Real-time Godot Integration - Live generation in Godot engine
Procedural Sprite Variation - Generate sprite variations
Running Examples
Development
Setup Development Environment
Running Tests
Code Quality Checks
Project Structure
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Quick contribution checklist:
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Write tests for your changes
Ensure all tests pass (
pytest tests/)Run type checking (
mypy src/)Run linting (
ruff check src/ tests/)Format code (
ruff format src/ tests/)Commit changes (
git commit -m 'feat: add amazing feature')Push to branch (
git push origin feature/amazing-feature)Open a Pull Request
Troubleshooting
Common Issues
ComfyUI Server Connection Failed
Problem: ConnectionError: Cannot connect to ComfyUI server at http://localhost:8188
Solutions:
Verify ComfyUI is running: Open
http://localhost:8188in browserCheck URL configuration: Ensure
COMFYUI_URLis correctCheck firewall settings: Allow connections on port 8188
Try explicit localhost: Use
http://127.0.0.1:8188instead ofhttp://localhost:8188
Workflow Execution Timeout
Problem: TimeoutError: Workflow execution exceeded timeout of 120.0 seconds
Solutions:
Increase timeout in configuration:
[comfyui] timeout = 300.0 # 5 minutesReduce workflow complexity (fewer steps, lower resolution)
Check ComfyUI server logs for errors
Ensure models are downloaded and accessible
Module Import Errors
Problem: ModuleNotFoundError: No module named 'comfyui_mcp'
Solutions:
Reinstall package:
pip install -e .Activate virtual environment:
source venv/bin/activateCheck Python path:
echo $PYTHONPATH
Type Checking Errors
Problem: mypy reports type errors
Solutions:
Update type stubs:
pip install --upgrade types-allCheck mypy configuration in
pyproject.tomlUse
# type: ignorefor false positives (sparingly)
Debug Mode
Enable debug logging:
Getting Help
GitHub Issues: Report bugs or request features
GitHub Discussions: Ask questions and share ideas
Documentation: Read the docs
Roadmap
See GitHub Milestones for upcoming features.
Planned Features
Phase 1: Foundation (Current)
✅ ComfyUI API client
✅ MCP server implementation
✅ Basic workflow templates
✅ Configuration system
✅ Comprehensive documentation
Phase 2: Advanced Features (Next)
WebSocket support for real-time progress
Advanced workflow template system
Image post-processing pipeline
Generation caching
Batch processing optimization
Phase 3: Godot Integration (Future)
Godot GDScript helper library
Godot plugin for ComfyUI integration
Editor tools for workflow testing
Asset pipeline integration
Phase 4: Production Enhancements (Future)
Authentication and API key support
Rate limiting and queue management
Monitoring and metrics
Docker containerization
Kubernetes deployment support
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
ComfyUI - Powerful workflow-based Stable Diffusion UI by comfyanonymous
Godot Engine - Open-source game engine
Model Context Protocol - Universal AI integration standard by Anthropic
Pydantic - Data validation using Python type hints
Ruff - Fast Python linter and formatter
Support
Issues: GitHub Issues
Discussions: GitHub Discussions
Documentation: docs/
Status: Alpha - Active Development
Built with ❤️ by Purlieu Studios