Stable Diffusion WebUI MCP server

Integrates with Stable Diffusion WebUI to provide text-to-image generation with extensive parameter control and metadata embedding
Back to servers
Setup instructions
Provider
Ichigo3766
Release date
Mar 25, 2025
Language
TypeScript
Package
Stats
14 stars

This MCP server provides text-to-image generation capabilities using Stable Diffusion WebUI API. It connects to your existing Stable Diffusion WebUI instance (such as ForgeUI or AUTOMATIC-1111) to enable image generation through the Model Context Protocol.

Prerequisites

Before installing the image-gen MCP server, ensure you have:

  • Node.js installed
  • Access to a Stable Diffusion WebUI instance with API enabled
  • The WebUI must be running with the --api flag enabled

Installation

Step 1: Clone the Repository

git clone https://github.com/Ichigo3766/image-gen-mcp.git
cd image-gen-mcp

Step 2: Install Dependencies

npm install

Step 3: Build the Server

npm run build

Step 4: Configure Server Settings

Add the server configuration to your environment. Create or modify your MCP configuration file:

{
  "mcpServers": {
    "image-gen": {
      "command": "node",
      "args": [
        "/path/to/image-gen-mcp/build/index.js"
      ],
      "env": {
        "SD_WEBUI_URL": "http://your-sd-webui-url:7860",
        "SD_AUTH_USER": "your-username",
        "SD_AUTH_PASS": "your-password",
        "SD_OUTPUT_DIR": "/path/to/output/directory",
        "SD_RESIZE_MODE": "0",
        "SD_UPSCALE_MULTIPLIER": "4",
        "SD_UPSCALE_WIDTH": "512",
        "SD_UPSCALE_HEIGHT": "512",
        "SD_UPSCALER_1": "R-ESRGAN 4x+",
        "SD_UPSCALER_2": "None"
      }
    }
  }
}

Configuration Options

Environment Variables

Replace the placeholders with your actual values:

  • SD_WEBUI_URL: URL of your Stable Diffusion WebUI instance
  • SD_AUTH_USER: Username for basic auth (optional)
  • SD_AUTH_PASS: Password for basic auth (optional)
  • SD_OUTPUT_DIR: Directory where generated images will be saved
  • SD_RESIZE_MODE: Default upscaling mode (0 for multiplier, 1 for dimensions)
  • SD_UPSCALE_MULTIPLIER: Default multiplier when resize_mode is 0
  • SD_UPSCALE_WIDTH: Default target width when resize_mode is 1
  • SD_UPSCALE_HEIGHT: Default target height when resize_mode is 1
  • SD_UPSCALER_1: Default primary upscaler model
  • SD_UPSCALER_2: Default secondary upscaler model

Available Tools

Generate Images

Use the generate_image tool to create images from text prompts:

Parameters:

  • prompt (required): Text description of the desired image
  • negative_prompt: Things to exclude from the image
  • steps: Number of sampling steps (default: 4, range: 1-150)
  • width: Image width (default: 1024, range: 512-2048)
  • height: Image height (default: 1024, range: 512-2048)
  • cfg_scale: CFG scale (default: 1, range: 1-30)
  • sampler_name: Sampling algorithm (default: "Euler")
  • scheduler_name: Scheduler algorithm (default: "Simple")
  • seed: Random seed (-1 for random)
  • batch_size: Number of images to generate (default: 1, max: 4)
  • restore_faces: Enable face restoration
  • tiling: Generate tileable images
  • output_path: Custom output path for the generated image

Manage SD Models

List Available Models: Use the get_sd_models tool to retrieve a list of available Stable Diffusion models.

Change Active Model: Use the set_sd_model tool to set the active Stable Diffusion model.

  • Parameter: model_name (required) - Name of the model to set as active

Upscaling Images

List Upscalers: Use the get_sd_upscalers tool to get a list of available upscaler models.

Upscale Images: Use the upscale_images tool to enhance image resolution.

Parameters:

  • images (required): Array of image file paths to upscale
  • resize_mode: 0 for multiplier mode, 1 for dimension mode
  • upscaling_resize: Upscale multiplier when resize_mode=0
  • upscaling_resize_w: Target width in pixels when resize_mode=1
  • upscaling_resize_h: Target height in pixels when resize_mode=1
  • upscaler_1: Primary upscaler model
  • upscaler_2: Secondary upscaler model
  • output_path: Custom output directory for upscaled images

Troubleshooting

If you encounter issues:

  1. Verify your Stable Diffusion WebUI is running with the --api flag
  2. Check that the WebUI URL is accessible from where you're running the MCP server
  3. If using authentication, ensure credentials are correct
  4. Verify the output directory exists and has write permissions
  5. When upscaling, ensure the input image files exist and are readable

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "image-gen" '{"command":"node","args":["/path/to/image-gen-mcp/build/index.js"],"env":{"SD_WEBUI_URL":"http://your-sd-webui-url:7860","SD_AUTH_USER":"your-username","SD_AUTH_PASS":"your-password","SD_OUTPUT_DIR":"/path/to/output/directory","SD_RESIZE_MODE":"0","SD_UPSCALE_MULTIPLIER":"4","SD_UPSCALE_WIDTH":"512","SD_UPSCALE_HEIGHT":"512","SD_UPSCALER_1":"R-ESRGAN 4x+","SD_UPSCALER_2":"None"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "image-gen": {
            "command": "node",
            "args": [
                "/path/to/image-gen-mcp/build/index.js"
            ],
            "env": {
                "SD_WEBUI_URL": "http://your-sd-webui-url:7860",
                "SD_AUTH_USER": "your-username",
                "SD_AUTH_PASS": "your-password",
                "SD_OUTPUT_DIR": "/path/to/output/directory",
                "SD_RESIZE_MODE": "0",
                "SD_UPSCALE_MULTIPLIER": "4",
                "SD_UPSCALE_WIDTH": "512",
                "SD_UPSCALE_HEIGHT": "512",
                "SD_UPSCALER_1": "R-ESRGAN 4x+",
                "SD_UPSCALER_2": "None"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "image-gen": {
            "command": "node",
            "args": [
                "/path/to/image-gen-mcp/build/index.js"
            ],
            "env": {
                "SD_WEBUI_URL": "http://your-sd-webui-url:7860",
                "SD_AUTH_USER": "your-username",
                "SD_AUTH_PASS": "your-password",
                "SD_OUTPUT_DIR": "/path/to/output/directory",
                "SD_RESIZE_MODE": "0",
                "SD_UPSCALE_MULTIPLIER": "4",
                "SD_UPSCALE_WIDTH": "512",
                "SD_UPSCALE_HEIGHT": "512",
                "SD_UPSCALER_1": "R-ESRGAN 4x+",
                "SD_UPSCALER_2": "None"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later