DiffuGen

by cloudwerx-dev

10 stars
648 downloads
Not rated
GitHub Website

About

CloudWerx's DiffuGen provides a flexible image generation server that supports multiple stable diffusion models with advanced configuration options for prompt engineering and generation parameters.

Details

Author
cloudwerx-dev
Repository
CLOUDWERX-DEV/DiffuGen
GitHub stars
10
Downloads
648
License
MIT License
Categories
Developer Tools, AI, Other, Productivity, Design, Media, Cloud Service, Infrastructure
Tags
#content-creation

- Multiple Model Support: Generate images using various models including Flux Schnell, Flux Dev, SDXL, SD3, and SD1.5
- MCP Integration: Seamlessly integrates with IDEs that support MCP (Cursor, Windsurf, Roo Code, Cline, etc.)
- OpenAPI Server: Additional REST API interface for direct HTTP access to image generation capabilities
- Cross-Platform: Works on Linux, macOS, and Windows (via native or WSL)
- Parameter Control: Fine-tune your generations with controls for:
- Image dimensions (width/height)
- Sampling steps
- CFG scale
- Seed values
- Negative prompts (for SD models only, Flux does not support negative prompts.)
- Sampling methods
- CUDA Acceleration: Utilizes GPU acceleration for faster image generation
- Natural Language Interface: Generate images using simple natural language commands
- Smart Error Recovery: Robust error handling with operation-aware recovery procedures
- User-Friendly Setup: Interactive setup script with improved interrupt handling
- Resource Tracking: Session-aware resource management for efficient cleanup
- Customizable Interface: Support for custom ANSI art logos and visual enhancements

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name DiffuGen
    Command (node, npx, python, etc.) /home/cloudwerxlab/Desktop/Servers/MCP/Tools/DiffuGen/diffugen.sh
    Environment
    • SD_CPP_PATH path/to/stable-diffusion.cpp
    • default_model flux-schnell
    • CUDA_VISIBLE_DEVICES 0

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

The easiest way to install DiffuGen is using the provided setup script:

git clone https://github.com/CLOUDWERX-DEV/diffugen.git
cd DiffuGen
chmod +x diffugen.sh
chmod +x setup_diffugen.sh
./setup_diffugen.sh

Follow the interactive prompts to complete the installation.

The setup script will:
- Install necessary dependencies
- Clone and build stable-diffusion.cpp
- Set up a Python virtual environment
- Download selected models (Note: Some models require Clip\VAE Models as well)
- Configure file paths for your system

If you prefer to install manually, follow these steps:

1. Clone the repositories:

git clone https://github.com/CLOUDWERX-DEV/diffugen.git
cd DiffuGen
git clone --recursive https://github.com/leejet/stable-diffusion.cpp

2. Build stable-diffusion.cpp:

cd stable-diffusion.cpp
mkdir -p build && cd build

With CUDA:

cmake .. -DCMAKE_BUILD_TYPE=Release -DSD_CUDA=ON
make -j$(nproc)
cd ../..

Without CUDA:

cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
cd ../..

3. Create and activate a Python virtual environment:

python3 -m venv diffugen_env
source diffugen_env/bin/activate  # On Windows: diffugen_env\Scripts\activate
pip install -r requirements.txt

4. Download required models (structure shown below):

stable-diffusion.cpp/models/
├── ae.sft                           # VAE model
├── clip_l.safetensors               # CLIP model
├── flux/
│   ├── flux1-schnell-q8_0.gguf     # Flux Schnell model (default)
│   └── flux1-dev-q8_0.gguf          # Flux Dev model
├── sd3-medium.safetensors           # SD3 model
├── sdxl-1.0-base.safetensors        # SDXL model
├── sdxl_vae-fp16-fix.safetensors    # SDXL VAE
├── t5xxl_fp16.safetensors           # T5 model
└── v1-5-pruned-emaonly.safetensors  # SD1.5 model

You can download the models from the following sources:

```bash

generate_stable_diffusion_image

Generate an image using Stable Diffusion models.

generate_flux_image

Generate an image using Flux models.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "diffugen": {
            "env": {
                "SD_CPP_PATH": "path/to/stable-diffusion.cpp",
                "default_model": "flux-schnell",
                "CUDA_VISIBLE_DEVICES": "0"
            },
            "args": [],
            "command": "/home/cloudwerxlab/Desktop/Servers/MCP/Tools/DiffuGen/diffugen.sh"
        }
    }
}

Linux

{
    "env": {
        "SD_CPP_PATH": "path/to/stable-diffusion.cpp",
        "default_model": "flux-schnell",
        "CUDA_VISIBLE_DEVICES": "0"
    },
    "args": [],
    "command": "/home/cloudwerxlab/Desktop/Servers/MCP/Tools/DiffuGen/diffugen.sh"
}

Macos

{
    "env": {
        "SD_CPP_PATH": "path/to/stable-diffusion.cpp",
        "default_model": "flux-schnell",
        "CUDA_VISIBLE_DEVICES": "0"
    },
    "args": [],
    "command": "/home/cloudwerxlab/Desktop/Servers/MCP/Tools/DiffuGen/diffugen.sh"
}

Windows

{
    "env": {
        "SD_CPP_PATH": "path/to/stable-diffusion.cpp",
        "default_model": "flux-schnell",
        "CUDA_VISIBLE_DEVICES": "0"
    },
    "args": [],
    "command": "/home/cloudwerxlab/Desktop/Servers/MCP/Tools/DiffuGen/diffugen.sh"
}

DiffuGen - Advanced Local Image Generator with MCP Integration

Your AI art studio embedded directly in code. Generate, iterate, and perfect visual concepts through this powerful MCP server for Cursor, Windsurf, and other compatible IDEs, utilizing cutting-edge Flux and Stable Diffusion models without disrupting your development process.

New: Now includes OpenAPI server support and OpenWebUI OpenAPI Tools (OWUI Version 0.60.0 Required) integration for seamless image generation and display in chat interfaces! The OpenAPI is seperate from the MCP server and allowss for initigrations into your own projects!

- Introduction
-
Understanding MCP and DiffuGen
-
Features
-
System Requirements
-
Installation
-
IDE Setup Instructions
-
Usage

- OpenAPI Server Usage
-
Default Parameters by Model
-
Asking a LLM to Generate Images
-
Parameter Reference
-
Model-Specific Parameter Recommendations
-
Default Parameter Changes
-
Command Line Usage Notes

- Configuration Approach
-
Environment Variable Overrides
-
Setting IDE-Specific Configurations
-
Key Configuration Elements
-
IDE-Specific Options
-
Customizing Default Parameters
-
Updating Configuration Files

DiffuGen is a powerful MCP-based image generation system that brings cutting-edge AI models directly into your development workflow. It seamlessly integrates both Flux models (Flux Schnell, Flux Dev) and Stable Diffusion variants (SDXL, SD3, SD1.5) into a unified interface, allowing you to leverage the unique strengths of each model family without switching tools. With comprehensive parameter control and multi-GPU support, DiffuGen scales from rapid concept sketches on modest hardware to production-quality visuals on high-performance systems.

Built on top of the highly optimizedstable-diffusion.cppimplementation, DiffuGen offers exceptional performance even on modest hardware while maintaining high-quality output.

MCP (Model Context Protocol) is a protocol that enables LLMs (Large Language Models) to access custom tools and services. In simple terms, an MCP client (like Cursor, Windsurf, Roo Code, or Cline) can make requests to MCP servers to access tools that they provide.

DiffuGen functions as an MCP server that provides text-to-image generation capabilities. It implements the MCP protocol to allow compatible IDEs to send generation requests and receive generated images.
- generate_stable_diffusion_image: Generate with Stable Diffusion models
- generate_flux_image: Generate with Flux models

DiffuGen consists of several key components:

- setup-diffugen.sh: The complete install utility and model downloader and manager
- diffugen.py: The core Python script that implements the MCP server functionality and defines the generation tools
- diffugen.sh: A shell script launcher that sets up the environment and launches the Python server
- diffugen.json: Template configuration file for MCP integration with various IDEs (to be copied into IDE's MCP configuration)
- stable-diffusion.cpp: The optimized C++ implementation of Stable Diffusion used for actual image generation
- Receiving prompt and parameter data from an MCP client
- Processing the request through the Python server
- Calling the stable-diffusion.cpp binary with appropriate parameters
- Saving the generated image to a configured output directory
- Returning the path and metadata of the generated image to the client

stable-diffusion.cppis a highly optimized C++ implementation of the Stable Diffusion algorithm. Compared to the Python reference implementation, it offers:

- Significantly faster inference speed (up to 3-4x faster)
- Lower memory usage (works on GPUs with as little as 4GB VRAM)
- Optimized CUDA kernels for NVIDIA GPUs
- Support for various sampling methods and model formats
- Support for model quantization for better performance
- No Python dependencies for the core generation process

This allows DiffuGen to provide high-quality image generation with exceptional performance, even on modest hardware setups.

- Multiple Model Support: Generate images using various models including Flux Schnell, Flux Dev, SDXL, SD3, and SD1.5
- MCP Integration: Seamlessly integrates with IDEs that support MCP (Cursor, Windsurf, Roo Code, Cline, etc.)
- OpenAPI Server: Additional REST API interface for direct HTTP access to image generation capabilities
- Cross-Platform: Works on Linux, macOS, and Windows (via native or WSL)
- Parameter Control: Fine-tune your generations with controls for:

- Image dimensions (width/height)
- Sampling steps
- CFG scale
- Seed values
- Negative prompts (for SD models only, Flux does not support negative prompts.)
- Sampling methods

- CPU: 4-core processor (Intel i5/AMD Ryzen 5 or equivalent)
- RAM: 8GB system memory
- Storage: 5GB free disk space (SSD preferred for faster model loading)
- Python: 3.8 or newer
- GPU: Integrated graphics or entry-level dedicated GPU (optional)
- Network: Broadband connection for model downloads (5+ Mbps)

- CPU: 8+ core processor (Intel i7/i9 or AMD Ryzen 7/9)
- RAM: 16GB+ system memory
- GPU: NVIDIA GPU with 6GB+ VRAM (RTX 2060 or better for optimal performance)
- Storage: 20GB+ free SSD space
- Python: 3.10 or newer (3.11 offers best performance)
- Network: High-speed connection (20+ Mbps) for efficient model downloads

The easiest way to install DiffuGen is using the provided setup script:

git clone https://github.com/CLOUDWERX-DEV/diffugen.git cd DiffuGen chmod +x diffugen.sh chmod +x setup_diffugen.sh ./setup_diffugen.sh

Follow the interactive prompts to complete the installation.

- Install necessary dependencies
- Clone and build stable-diffusion.cpp
- Set up a Python virtual environment
- Download selected models (Note: Some models require Clip\VAE Models as well)
- Configure file paths for your system

If you prefer to install manually, follow these steps:

git clone https://github.com/CLOUDWERX-DEV/diffugen.git cd DiffuGen git clone --recursive https://github.com/leejet/stable-diffusion.cpp
cd stable-diffusion.cpp mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DSD_CUDA=ON make -j$(nproc) cd ../..
cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) cd ../..

- Create and activate a Python virtual environment:

python3 -m venv diffugen_env source diffugen_env/bin/activate # On Windows: diffugen_env\Scripts\activate pip install -r requirements.txt

- Download required models (structure shown below):

stable-diffusion.cpp/models/ ├── ae.sft # VAE model ├── clip_l.safetensors # CLIP model ├── flux/ │ ├── flux1-schnell-q8_0.gguf # Flux Schnell model (default) │ └── flux1-dev-q8_0.gguf # Flux Dev model ├── sd3-medium.safetensors # SD3 model ├── sdxl-1.0-base.safetensors # SDXL model ├── sdxl_vae-fp16-fix.safetensors # SDXL VAE ├── t5xxl_fp16.safetensors # T5 model └── v1-5-pruned-emaonly.safetensors # SD1.5 model

You can download the models from the following sources:

# Create model directories mkdir -p stable-diffusion.cpp/models/flux # Flux models # Flux Schnell - Fast generation model (Q8 Quantized,requires t5xxl, clip-l, vae) curl -L https://huggingface.co/leejet/FLUX.1-schnell-gguf/resolve/main/flux1-schnell-q8_0.gguf -o stable-diffusion.cpp/models/flux/flux1-schnell-q8_0.gguf # Flux Dev - Development model with better quality (Q8 QUantized, requires t5xxl, clip-l, vae) curl -L https://huggingface.co/leejet/FLUX.1-dev-gguf/resolve/main/flux1-dev-q8_0.gguf -o stable-diffusion.cpp/models/flux/flux1-dev-q8_0.gguf # Required models for Flux # T5XXL Text Encoder curl -L https://huggingface.co/Sanami/flux1-dev-gguf/resolve/main/t5xxl_fp16.safetensors -o stable-diffusion.cpp/models/t5xxl_fp16.safetensors # CLIP-L Text Encoder curl -L https://huggingface.co/Sanami/flux1-dev-gguf/resolve/main/clip_l.safetensors -o stable-diffusion.cpp/models/clip_l.safetensors # VAE for image decoding curl -L https://huggingface.co/pretentioushorsefly/flux-models/resolve/main/models/vae/ae.safetensors -o stable-diffusion.cpp/models/ae.sft # Stable Diffusion models # SDXL 1.0 Base Model (requires sdxl-vae) curl -L https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -o stable-diffusion.cpp/models/sd_xl_base_1.0.safetensors # SDXL VAE (required for SDXL) curl -L https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16-fix.safetensors -o stable-diffusion.cpp/models/sdxl_vae-fp16-fix.safetensors # Stable Diffusion 1.5 (standalone) curl -L https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors -o stable-diffusion.cpp/models/v1-5-pruned-emaonly.safetensors # Stable Diffusion 3 Medium (standalone) curl -L https://huggingface.co/leo009/stable-diffusion-3-medium/resolve/main/sd3_medium_incl_clips_t5xxlfp16.safetensors -o stable-diffusion.cpp/models/sd3_medium_incl_clips_t5xxlfp16.safetensors

Note: Model download may take a long time depending on your internet connection. The SDXL model is approximately 6GB, SD3 is about 13GB, SD1.5 is around 4GB, and Flux models are 8-13GB each.

Configuration Approach: DiffuGen uses a single configuration file (diffugen.json) as the source of truth for all settings. The workflow is:
- Editdiffugen.jsonin the DiffuGen root directory with your desired settings
- Run option 5 insetup_diffugen.shto automatically update paths in this file
- Copy the content ofdiffugen.jsonto your IDE's MCP configuration file

The file contains all necessary settings:

- File paths (command, SD_CPP_PATH, models_dir, output_dir)
- Default model parameters (steps, cfg_scale, sampling_method)
- VRAM usage settings
- Metadata for IDE integration

{ "mcpServers": { "diffugen": { "command": "/home/cloudwerxlab/Desktop/Servers/MCP/Tools/DiffuGen/diffugen.sh", "args": [], "env": { "CUDA_VISIBLE_DEVICES": "0", "SD_CPP_PATH": "path/to/stable-diffusion.cpp", "default_model": "flux-schnell" }, "resources": { "models_dir": "path/to/stable-diffusion.cpp/models", "output_dir": "path/to/outputs", "vram_usage": "adaptive" }, "metadata": { "name": "DiffuGen", "version": "1.0", "description": "Your AI art studio embedded directly in code. Generate, iterate, and perfect visual concepts through this powerful MCP server for Cursor, Windsurf, and other compatible IDEs, utilizing cutting-edge Flux and Stable Diffusion models without disrupting your development process.", "author": "CLOUDWERX LAB", "homepage": "https://github.com/CLOUDWERX-DEV/diffugen", "usage": "Generate images using two primary methods:\n1. Standard generation: 'generate an image of [description]' with optional parameters:\n - model: Choose from flux-schnell (default), flux-dev, sdxl, sd3, sd15\n - dimensions: width and height (default: 512x512)\n - steps: Number of diffusion steps (default: 20, lower for faster generation)\n - cfg_scale: Guidance scale (default: 7.0, lower for more creative freedom)\n - seed: For reproducible results (-1 for random)\n - sampling_method: euler, euler_a (default), heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, lcm\n - negative_prompt: Specify elements to avoid in the image\n2. Quick Flux generation: 'generate a flux image of [description]' for faster results with fewer steps (default: 4)" }, "cursorOptions": { "autoApprove": true, "category": "Image Generation", "icon": "🖼️", "displayName": "DiffuGen" }, "windsurfOptions": { "displayName": "DiffuGen", "icon": "🖼️", "category": "Creative Tools" }, "default_params": { "steps": { "flux-schnell": 8, "flux-dev": 20, "sdxl": 20, "sd3": 20, "sd15": 20 }, "cfg_scale": { "flux-schnell": 1.0, "flux-dev": 1.0, "sdxl": 7.0, "sd3": 7.0, "sd15": 7.0 }, "sampling_method": { "flux-schnell": "euler", "flux-dev": "euler", "sdxl": "euler", "sd3": "euler", "sd15": "euler" } } } } }

- Download and installCursor
- Go to Cursor Settings > MCP and click "Add new global MCP server"
- Copy the contents of your DiffuGen'sdiffugen.jsonfileand paste it into~/.cursor/mcp.json
- Refresh MCP Servers in Settings > MCP
- Use DiffuGen by opening the AI chat panel (Ctrl+K or Cmd+K) and requesting image generation
- Download and install
Windsurf
- Navigate to Windsurf > Settings > Advanced Settings or Command Palette > Open Windsurf Settings Page
- Scroll down to the Cascade section and click "Add Server" > "Add custom server +"
- Copy the contents of your DiffuGen'sdiffugen.jsonfileand paste into~/.codeium/windsurf/mcp_config.json
- Use DiffuGen through the Cascade chat interface
- Download and install
Roo Code
- Locate the MCP configuration file for Roo Code
- Copy the contents of your DiffuGen'sdiffugen.jsonfileinto Roo Code's MCP configuration
- Use DiffuGen through the AI assistant feature
- Download and install
Cline
- Copy the contents of your DiffuGen'sdiffugen.jsonfileinto Cline's MCP settings
- Use DiffuGen through the AI chat or command interface

Setting up with Claude in Anthropic Console

Claude can use DiffuGen if you've set it up as an MCP server on your system. When asking Claude to generate images, be specific about using DiffuGen and provide the parameters you want to use.

You should see:DiffuGen readywhen the server is successfully started.

The OpenAPI server provides a REST API interface for direct HTTP access to DiffuGen's image generation capabilities. This is in addition to the MCP integration and can be useful for:

- Direct HTTP API access
- Integration with other tools that don't support MCP
- Custom applications that need programmatic access

For detailed setup instructions and advanced configuration options, see theOpenAPI Integration Guide.

The server can be configured to use a different host or port if needed. By default, it runs on:

The server will be available athttp://0.0.0.0:8080with interactive documentation athttp://0.0.0.0:8080/docs.

Generated images are saved to the/outputdirectory by default. If this directory is not accessible, the server will automatically create anoutputdirectory in the current working directory. Images are served through the/imagesendpoint.
- Open OpenWebUI Settings (gear icon)
- Navigate to the "Tools" section
- Click the "+" button to add a new tool server
- Enter the following details:

- URL:http://0.0.0.0:5199
- API Key: (leave empty)

Once added, DiffuGen will appear in the available tools list when clicking the tools icon in the chat interface. The following endpoints will be available:

- generate_stable_image_generate_stable_post: Generate with Stable Diffusion
- generate_flux_image_endpoint_generate_flux_post: Generate with Flux Models
- list_models_models_get: List Available Models

curl -X POST "http://0.0.0.0:5199/generate/flux" \ -H "Content-Type: application/json" \ -d '{"prompt": "A beautiful sunset", "model": "flux-schnell"}'
import requests response = requests.post( "http://0.0.0.0:5199/generate/flux", json={ "prompt": "A beautiful sunset", "model": "flux-schnell" } ) result = response.json()

Each model has specific default parameters optimized for best results:

These default parameters can be customized by adding adefault_paramssection to your IDE's MCP configuration file:

"default_params": { "steps": { "flux-schnell": 12, // Customize steps for better quality "sdxl": 30 // Increase steps for more detailed SDXL images }, "cfg_scale": { "sd15": 9.0 // Higher cfg_scale for stronger prompt adherence } }

You only need to specify the parameters you want to override - any unspecified values will use the built-in defaults.

Note: For model-specific command line examples and recommendations, seeModel-Specific Parameter Recommendationssection.

Here are examples of how to ask an AI assistant to generate images with DiffuGen:

Generate an image of a cat playing with yarn
Create a picture of a futuristic cityscape with flying cars
Generate an image of a medieval castle using the sdxl model
Create a flux image of a sunset over mountains
Generate an image of a cyberpunk street scene, model=flux-dev, width=768, height=512, steps=25, cfg_scale=1.0, seed=42
Create an illustration of a fantasy character with model=sd15, width=512, height=768, steps=30, cfg_scale=7.5, sampling_method=dpm++2m, negative_prompt=blurry, low quality, distorted

DiffuGen can be used from the command line with the following basic syntax:

./diffugen.sh "Your prompt here" [options]
./diffugen.sh "A futuristic cityscape with flying cars"

This command generates an image using default parameters (flux-schnell model, 512x512 resolution, etc.) and saves it to the configured output directory.

Below are the parameters that can be used with DiffuGen (applicable to both MCP interface and command line):

These parameters can be specified when asking an AI assistant to generate images or when using the command line interface. Parameters are passed in different formats depending on the interface:

- In MCP/AI Assistant:parameter=value(e.g.,model=sdxl, width=768, height=512)
- In Command Line:--parameter value(e.g.,--model sdxl --width 768 --height 512)

The default values are chosen to provide good results out-of-the-box with minimal waiting time. For higher quality images, consider increasing steps or switching to models like sdxl.

Model-Specific Parameter Recommendations

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.