image gen mcp
A MCP server that integrates with Stable Diffusion WebUI to provide text-to-image generation and image upscaling capabilities through simple API calls.
A MCP server that integrates with Stable Diffusion WebUI to provide text-to-image generation and image upscaling capabilities through simple API calls.
A MCP server that provides text-to-image generation capabilities using Stable Diffusion WebUI API (ForgeUI/AUTOMATIC-1111).
--api
flag enabled when startingClone the repository:
git clone https://github.com/Ichigo3766/image-gen-mcp.git
cd image-gen-mcp
Install dependencies:
npm install
Build the server:
npm run build
Add the server configuration to your environment:
{
"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", // Optional: if authentication is enabled
"SD_AUTH_PASS": "your-password", // Optional: if authentication is enabled
"SD_OUTPUT_DIR": "/path/to/output/directory",
"SD_RESIZE_MODE": "0", // Optional: upscaling mode (0=multiplier, 1=dimensions)
"SD_UPSCALE_MULTIPLIER": "4", // Optional: default upscale multiplier
"SD_UPSCALE_WIDTH": "512", // Optional: default upscale width
"SD_UPSCALE_HEIGHT": "512", // Optional: default upscale height
"SD_UPSCALER_1": "R-ESRGAN 4x+", // Optional: default primary upscaler
"SD_UPSCALER_2": "None" // Optional: default secondary upscaler
}
}
}
}
Replace the environment variables with your values:
- SD_WEBUI_URL
: URL of your Stable Diffusion WebUI instance
- SD_AUTH_USER
: Username for basic auth (if enabled)
- SD_AUTH_PASS
: Password for basic auth (if enabled)
- 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 upscale 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
generate_image
- Generate images using Stable DiffusionParameters:
prompt
(required): Text description of the desired imagenegative_prompt
: Things to exclude from the imagesteps
: 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 restorationtiling
: Generate tileable imagesoutput_path
: Custom output path for the generated imageget_sd_models
- Get list of available Stable Diffusion models
Returns an array of model names
set_sd_model
- Set the active Stable Diffusion model
Parameters:
model_name
(required): Name of the model to set as activeget_sd_upscalers
- Get list of available upscaler models
Returns an array of upscaler names
upscale_images
- Upscale one or more images using Stable Diffusion
images
(required): Array of image file paths to upscaleresize_mode
: 0 for multiplier mode, 1 for dimension mode (default: from env)upscaling_resize
: Upscale multiplier when resize_mode=0 (default: from env)upscaling_resize_w
: Target width in pixels when resize_mode=1 (default: from env)upscaling_resize_h
: Target height in pixels when resize_mode=1 (default: from env)upscaler_1
: Primary upscaler model (default: from env)upscaler_2
: Secondary upscaler model (default: from env)output_path
: Custom output directory for upscaled imagesFor development with auto-rebuild:
npm run watch
Common issues and solutions:
1. Make sure your Stable Diffusion WebUI is running with the --api
flag
2. Check if 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
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
[
{
"description": "Generate an image using Stable Diffusion",
"inputSchema": {
"properties": {
"batch_size": {
"description": "Number of images to generate (default: 1)",
"maximum": 4,
"minimum": 1,
"type": "number"
},
"cfg_scale": {
"description": "CFG scale (default: 1)",
"maximum": 30,
"minimum": 1,
"type": "number"
},
"distilled_cfg_scale": {
"description": "Distilled CFG scale (default: 3.5)",
"maximum": 30,
"minimum": 1,
"type": "number"
},
"height": {
"description": "Image height (default: 1024)",
"maximum": 2048,
"minimum": 512,
"type": "number"
},
"negative_prompt": {
"description": "Things to exclude from the image",
"type": "string"
},
"output_path": {
"description": "Custom output path for the generated image",
"type": "string"
},
"prompt": {
"description": "The prompt describing the desired image",
"type": "string"
},
"restore_faces": {
"description": "Enable face restoration",
"type": "boolean"
},
"sampler_name": {
"default": "Euler",
"description": "Sampling algorithm (default: Euler)",
"type": "string"
},
"scheduler_name": {
"default": "Simple",
"description": "Scheduler algorithm (default: Simple)",
"type": "string"
},
"seed": {
"description": "Random seed (-1 for random)",
"minimum": -1,
"type": "number"
},
"steps": {
"description": "Number of sampling steps (default: 4)",
"maximum": 150,
"minimum": 1,
"type": "number"
},
"tiling": {
"description": "Generate tileable images",
"type": "boolean"
},
"width": {
"description": "Image width (default: 1024)",
"maximum": 2048,
"minimum": 512,
"type": "number"
}
},
"required": [
"prompt"
],
"type": "object"
},
"name": "generate_image"
},
{
"description": "Get list of available Stable Diffusion models",
"inputSchema": {
"properties": {},
"required": [],
"type": "object"
},
"name": "get_sd_models"
},
{
"description": "Set the active Stable Diffusion model",
"inputSchema": {
"properties": {
"model_name": {
"description": "Name of the model to set as active",
"type": "string"
}
},
"required": [
"model_name"
],
"type": "object"
},
"name": "set_sd_model"
},
{
"description": "Get list of available upscaler models",
"inputSchema": {
"properties": {},
"required": [],
"type": "object"
},
"name": "get_sd_upscalers"
},
{
"description": "Upscale one or more images using Stable Diffusion",
"inputSchema": {
"properties": {
"images": {
"description": "Array of image file paths to upscale",
"items": {
"type": "string"
},
"type": "array"
},
"output_path": {
"description": "Custom output directory for upscaled images",
"type": "string"
},
"resize_mode": {
"description": "0 for multiplier mode (default), 1 for dimension mode",
"enum": [
0,
1
],
"type": "number"
},
"upscaler_1": {
"description": "Primary upscaler model (default: R-ESRGAN 4x+)",
"type": "string"
},
"upscaler_2": {
"description": "Secondary upscaler model (default: None)",
"type": "string"
},
"upscaling_resize": {
"description": "Upscale multiplier (default: 4) - used when resize_mode is 0",
"type": "number"
},
"upscaling_resize_h": {
"description": "Target height in pixels (default: 512) - used when resize_mode is 1",
"type": "number"
},
"upscaling_resize_w": {
"description": "Target width in pixels (default: 512) - used when resize_mode is 1",
"type": "number"
}
},
"required": [
"images"
],
"type": "object"
},
"name": "upscale_images"
}
]