Comfy.org_MCP-Server

yogocomfyorg/Comfy.org_MCP-Server

3.1

If you are the rightful owner of Comfy.org_MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

ComfyUI MCP Server is a comprehensive Model Context Protocol server designed for ComfyUI, offering advanced automation and intelligent workflow orchestration capabilities.

Tools
5
Resources
0
Prompts
0

🎨 ComfyUI MCP Server

License: MIT Node.js TypeScript ComfyUI

A comprehensive Model Context Protocol (MCP) server for ComfyUI with automatic agentic controlling capabilities, intelligent workflow orchestration

🌟 Key Highlights

  • 🤖 Fully Autonomous ComfyUI Control - Complete API automation with intelligent decision making
  • 🎭 Advanced Workflow Orchestration - Chain complex workflows with dependencies and error handling
  • 🖼️ Intelligent Image Routing - Automatic image bridging between workflows
  • 🔧 Smart Custom Node Management - Automated installation with dependency resolution
  • 📦 One-Click ComfyUI Installation - Complete setup with CUDA optimization options
  • 🚀 Performance Optimization - Triton and SageAttention integration
  • 🔍 Real-time Monitoring - System health and performance tracking

🎯 Core Capabilities

🤖 Autonomous AI Control

  • Intelligent Workflow Management: AI-driven workflow selection and optimization
  • Automatic Error Recovery: Smart error detection and resolution
  • Adaptive Performance Tuning: Dynamic optimization based on system capabilities

🎭 Advanced Workflow System

  • Workflow Orchestration: Chain multiple workflows with complex dependencies
  • Parameter Injection: Dynamic parameter modification for any workflow type
  • Image Routing: Intelligent bridging of images between workflow stages
  • Batch Processing: Execute multiple workflows with parallel processing

🔧 Complete ComfyUI Management

  • Model Download & Management: HuggingFace, Civitai, and custom model sources
  • Custom Node Ecosystem: Automated installation, updates, and dependency management
  • Configuration Management: Dynamic ComfyUI settings and optimization
  • System Integration: Terminal operations, file management, and monitoring

🚀 Performance & Optimization

  • CUDA Optimization: Multi-version CUDA support with automatic selection
  • Triton Integration: GPU kernel optimization for enhanced performance
  • SageAttention: Memory-efficient attention mechanisms
  • Resource Monitoring: Real-time CPU, RAM, and GPU utilization tracking

🚀 Quick Start

Option 1: Complete Installation (Recommended)

🎯 One-Click ComfyUI Setup with MCP Server

  1. Clone the repository:

    git clone https://github.com/your-org/comfyui-mcp-server.git
    cd comfyui-mcp-server
    
  2. Install ComfyUI with optimization options:

    # Run the comprehensive installer
    sandbox/Install_ComfyUI_Complete.bat
    

    The installer will guide you through:

    • CUDA Version Selection (11.8, 12.1, 12.4, 12.6, or CPU-only)
    • Triton & SageAttention optimization options
    • Build Tools validation and setup
    • Automatic Environment configuration
  3. Install MCP Server dependencies:

    npm install
    npm run build
    
  4. Start the MCP Server:

    npm start
    # or
    start-comfyui-mcp.bat
    

Option 2: MCP Server Only

If you already have ComfyUI installed:

  1. Clone and setup:

    git clone https://github.com/your-org/comfyui-mcp-server.git
    cd comfyui-mcp-server
    npm install
    npm run build
    
  2. Configure ComfyUI path in augment-mcp-config.json

  3. Start the server:

    npm start
    

📋 System Requirements

Minimum Requirements

  • Node.js: 18.0.0 or higher
  • Python: 3.10+ (for ComfyUI)
  • RAM: 8GB minimum, 16GB+ recommended
  • Storage: 20GB+ free space for models

Recommended for Optimal Performance

  • GPU: NVIDIA RTX 3060+ with 8GB+ VRAM
  • CUDA: 12.6 (latest) or 11.8+ (compatible)
  • RAM: 32GB+ for large models
  • Storage: SSD with 100GB+ free space
  • Build Tools: Visual Studio 2019/2022 (for Triton/SageAttention)

🎮 Usage Guide

🚀 Starting the System

Method 1: Complete System Startup
# Start ComfyUI instance (if using our installer)
sandbox/ComfyUI_cuda126/Launch_ComfyUI_CUDA126.bat

# In another terminal, start MCP Server
npm start
# or
start-comfyui-mcp.bat
Method 2: Direct MCP Server
npm start
# or
node build/index.js

🎛️ Server Configuration

Environment Variables

Create a .env file in the project root:

# ComfyUI Configuration
COMFYUI_PATH=C:/path/to/ComfyUI
COMFYUI_URL=http://127.0.0.1:8188
COMFYUI_MODELS_PATH=C:/path/to/ComfyUI/models

# Performance Settings
MAX_CONCURRENT_WORKFLOWS=3
WORKFLOW_TIMEOUT=300000
IMAGE_ROUTING_CONFIDENCE=0.7

# Monitoring
ENABLE_PERFORMANCE_MONITORING=true
LOG_LEVEL=info

# DGM Integration
ENABLE_DGM_OPTIMIZATION=true
RECURSIVE_IMPROVEMENT_CYCLES=5
Advanced Configuration

Modify src/config.ts for advanced settings:

export const config = {
  comfyui: {
    defaultUrl: 'http://127.0.0.1:8188',
    timeout: 30000,
    retryAttempts: 3
  },
  workflows: {
    directory: './workflows',
    maxConcurrent: 3,
    defaultParameters: {
      batch_size: 1,
      steps: 20,
      cfg: 7.0
    }
  },
  optimization: {
    enableTriton: true,
    enableSageAttention: true,
    autoOptimize: true
  }
};

🛠️ Available Tools

🎯 Core Workflow Management

ToolDescriptionKey Features
run_workflow_with_parametersExecute workflows with dynamic parameter injection✅ Parameter modification, ✅ Preset configurations
run_workflowBasic workflow execution from workflows folder✅ Simple execution, ✅ API format support
create_workflow_chainCreate complex workflow orchestration chains✅ Dependencies, ✅ Error handling, ✅ Conditional execution
execute_workflow_chainExecute workflow chains with monitoring✅ Progress tracking, ✅ Dry run mode
load_workflowLoad and validate workflow files✅ Structure validation, ✅ Error detection
optimize_workflowAI-powered workflow optimization✅ Performance tuning, ✅ Resource optimization

🖼️ Intelligent Image Routing

ToolDescriptionKey Features
fetch_latest_imageSmart image detection and routing✅ Auto-detection, ✅ Node routing, ✅ Path resolution
smart_route_imageML-like image routing with confidence scoring✅ Confidence thresholds, ✅ Learning mode
batch_route_imagesBatch image processing and routing✅ Pattern matching, ✅ Multi-workflow support
orchestrate_workflow_with_imagesComplete workflow orchestration with image bridging✅ Automatic chaining, ✅ Image flow management
analyze_output_imagesImage analysis with metadata extraction✅ Metadata parsing, ✅ Workflow grouping

🔧 Custom Node Ecosystem

ToolDescriptionKey Features
install_customnodes🌟 FEATURED Intelligent custom node installation✅ Git clone, ✅ Dependency resolution, ✅ README parsing
list_custom_nodesComprehensive custom node inventory✅ Detailed info, ✅ Status checking
update_custom_nodeSmart custom node updates✅ Git pull, ✅ Dependency updates
remove_custom_nodeSafe custom node removal✅ Complete cleanup, ✅ Confirmation prompts
install_requirementsIntelligent dependency installation✅ README analysis, ✅ Environment detection

📦 Model Management

ToolDescriptionKey Features
download_huggingface_modelHuggingFace model downloads✅ Authentication, ✅ Progress tracking
list_installed_modelsModel inventory and organization✅ Type filtering, ✅ Size information
check_disk_spaceStorage monitoring✅ Space analysis, ✅ Cleanup suggestions

🚀 ComfyUI Server Management

ToolDescriptionKey Features
start_comfyui_in_terminalIntelligent ComfyUI startup✅ Auto-detection, ✅ Multiple methods
get_server_statusServer health monitoring✅ API status, ✅ Performance metrics
queue_workflowWorkflow queue management✅ Priority handling, ✅ Client tracking
clear_queueQueue management and cleanup✅ Selective clearing, ✅ Process termination
kill_comfyui_processesProcess and port cleanup✅ Force termination, ✅ Port cleanup

🔍 System Monitoring & Diagnostics

ToolDescriptionKey Features
monitor_system_resourcesReal-time system monitoring✅ CPU/RAM/GPU tracking, ✅ Performance alerts
health_checkComprehensive system health analysis✅ Multi-component checking, ✅ Issue detection
execute_commandSafe command execution✅ Timeout handling, ✅ Output capture

🎛️ Configuration & Settings

ToolDescriptionKey Features
get_comfyui_configConfiguration management✅ Settings retrieval, ✅ Validation
api_key_managementAPI key and credential management✅ Secure storage, ✅ Validation

🔄 Batch Operations & Automation

ToolDescriptionKey Features
batch_workflow_executionMulti-workflow batch processing✅ Concurrent execution, ✅ Progress tracking
create_directoryDirectory management✅ Recursive creation, ✅ Permission handling
list_directoryFile system exploration✅ Detailed listings, ✅ Hidden file support

🎯 Pro Tip: Use workflow chains with image routing for complete automation pipelines. The system can automatically generate images, route them through upscaling, apply effects, and organize outputs - all with a single command!

🏗️ Architecture

🔧 Modular Design

The server follows a clean, modular architecture for maximum maintainability and extensibility:

📁 comfyui-mcp-server/
├── 📁 src/
│   ├── 📄 index.ts                 # 🚀 Main MCP server entry point
│   ├── 📁 core/
│   │   ├── 📄 server.ts            # Core MCP server implementation
│   │   ├── 📄 config.ts            # Configuration management
│   │   └── 📄 utils.ts             # Shared utilities
│   └── 📁 tools/
│       ├── 📄 workflowExecution.ts # 🎭 Workflow orchestration & execution
│       ├── 📄 imageRouting.ts      # 🖼️ Intelligent image routing
│       ├── 📄 customNodes.ts       # 🔧 Custom node management
│       ├── 📄 modelManagement.ts   # 📦 Model download & organization
│       ├── 📄 serverManagement.ts  # 🚀 ComfyUI server control
│       ├── 📄 systemMonitoring.ts  # 🔍 Performance monitoring
│       ├── 📄 fileOperations.ts    # 📁 File & directory operations
│       └── 📄 batchOperations.ts   # 🔄 Batch processing
├── 📁 build/                       # 🏗️ Compiled JavaScript output
├── 📁 workflows/                   # 🎭 Workflow templates
├── 📁 sandbox/                     # 📦 Installation scripts
└── 📁 state/                       # 💾 Runtime state management

🔄 Data Flow Architecture

graph TD
    A[MCP Client] --> B[MCP Server]
    B --> C[Tool Router]
    C --> D[Workflow Engine]
    C --> E[Image Router]
    C --> F[Node Manager]
    C --> G[Model Manager]

    D --> H[ComfyUI API]
    E --> H
    F --> I[Git Operations]
    G --> J[HuggingFace/Civitai]

    H --> K[ComfyUI Instance]
    K --> L[Generated Images]
    L --> E

🧠 Intelligent Systems

Image Routing Intelligence
Image Detection → Compatibility Analysis → Confidence Scoring → Route Selection → Execution

🛠️ Development

🚀 Quick Development Setup

# Clone and setup
git clone https://github.com/your-org/comfyui-mcp-server.git
cd comfyui-mcp-server

# Install dependencies
npm install

# Development mode with hot reload
npm run dev

# Build for production
npm run build

# Run tests
npm test

# Lint and format
npm run lint
npm run format

🔧 Development Scripts

CommandDescriptionUsage
npm run devDevelopment mode with TypeScript watchingReal-time development
npm run buildCompile TypeScript to JavaScriptProduction builds
npm testRun Jest test suiteQuality assurance
npm run lintESLint code analysisCode quality
npm run formatPrettier code formattingCode consistency

🧪 Testing Strategy

# Unit tests
npm run test:unit

# Integration tests
npm run test:integration

# End-to-end tests
npm run test:e2e

# Coverage report
npm run test:coverage

🛡️ Error Handling & Reliability

🔒 Comprehensive Error Management

  • Graceful Degradation: System continues operating even when components fail
  • Detailed Logging: Comprehensive error tracking with context
  • Automatic Recovery: Self-healing mechanisms for common issues
  • Performance Monitoring: Real-time system health tracking
  • Timeout Handling: Prevents hanging operations
  • Resource Cleanup: Automatic cleanup of failed operations

🔍 Monitoring & Diagnostics

// Built-in health monitoring
{
  "system": {
    "status": "healthy",
    "uptime": "2h 34m",
    "memory": "1.2GB / 16GB",
    "cpu": "15%",
    "gpu": "45%"
  },
  "comfyui": {
    "status": "running",
    "queue": 2,
    "processing": true
  },
  "workflows": {
    "completed": 156,
    "failed": 3,
    "success_rate": "98.1%"
  }
}

🚀 Performance Optimization

⚡ CUDA & GPU Acceleration

The installation script provides multiple CUDA options for optimal performance:

CUDA VersionCompatibilityPerformanceRecommended For
CUDA 12.6Latest GPUs⭐⭐⭐⭐⭐RTX 40 series, Latest hardware
CUDA 12.4Modern GPUs⭐⭐⭐⭐RTX 30/40 series
CUDA 12.1Balanced⭐⭐⭐Most modern GPUs
CUDA 11.8Wide compatibility⭐⭐Older GPUs, Stability
CPU OnlyUniversalTesting, CPU-only systems

🔥 Advanced Optimizations

  • Triton Integration: GPU kernel optimization for 20-40% performance boost
  • SageAttention: Memory-efficient attention for large models
  • Automatic Mixed Precision: Reduces memory usage while maintaining quality
  • Dynamic Batching: Optimizes batch sizes based on available VRAM

📚 Examples & Use Cases

🎨 Creative Workflows

// Generate and enhance artwork pipeline
{
  "name": "artistic_enhancement_pipeline",
  "steps": [
    {
      "id": "base_generation",
      "workflow": "text2img_api",
      "parameters": {
        "prompt": "digital art, concept art style",
        "steps": 30,
        "cfg": 8.0
      }
    },
    {
      "id": "upscale_enhance",
      "workflow": "upscaling_api",
      "dependencies": ["base_generation"],
      "routeFromPrevious": true
    }
  ]
}

📸 Photography Enhancement

// Photo restoration and enhancement
{
  "workflow": "photo_enhancement",
  "batch_processing": true,
  "input_directory": "./photos",
  "output_directory": "./enhanced",
  "parameters": {
    "denoise_strength": 0.7,
    "upscale_factor": 2.0,
    "color_correction": true
  }
}

🎬 Video Frame Processing

// Video frame extraction and processing
{
  "pipeline": "video_frame_enhancement",
  "input": "video.mp4",
  "frame_extraction": {
    "fps": 24,
    "quality": "high"
  },
  "processing": {
    "workflow": "frame_enhancement_api",
    "batch_size": 8
  }
}

🤝 Contributing

🔧 Development Contribution

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Implement your changes with tests
  4. Ensure all tests pass: npm test
  5. Submit a pull request with detailed description

📝 Documentation Contribution

  • Improve README sections
  • Add workflow examples
  • Create tutorial content
  • Update API documentation

🐛 Bug Reports

Please include:

  • System specifications
  • ComfyUI version
  • Error logs and stack traces
  • Steps to reproduce

💡 Feature Requests

  • Describe the use case
  • Explain expected behavior
  • Provide implementation suggestions

📄 License

MIT License - see file for details.

This project is open source and welcomes contributions from the community.

🆘 Support & Community

📞 Getting Help

🔧 Troubleshooting

Common Issues
IssueSolution
ComfyUI not startingCheck CUDA installation and Python environment
Models not downloadingVerify internet connection and API keys
Workflows failingValidate workflow JSON format and node compatibility
Performance issuesEnable Triton/SageAttention optimizations
Debug Mode
# Enable verbose logging
DEBUG=comfyui:* npm start

# Check system health
npm run health-check

# Validate installation
npm run validate-setup

🌟 Community

Join our growing community of AI artists, developers, and researchers using ComfyUI MCP Server for creative and technical projects.


⭐ Star this repository if you find it useful!

🔄 Watch for updates and new features

🤝 Contribute to make it even better