
Stable Diffusion MCP Server
An MCP server to connect Claude Desktop with local Stable Diffusion WebUI
What is Stable Diffusion MCP Server?
Stable Diffusion MCP Server is a Model Context Protocol server that connects Claude Desktop with your local Stable Diffusion WebUI, enabling AI-assisted image generation directly from conversations.
How to use Stable Diffusion MCP Server?
To use the server, clone the repository, install dependencies, and configure both the Stable Diffusion WebUI and Claude Desktop. After setup, you can generate images by typing prompts in Claude Desktop.
Key features of Stable Diffusion MCP Server?
- Text-to-Image Generation: Create images from text prompts.
- Image-to-Image Editing: Modify existing images using text guidance.
- Model Management: List and switch between installed models.
- Sampler Control: Access all WebUI samplers.
- High Performance: Utilizes local GPU resources for image generation.
- Privacy-Focused: All processing occurs on your machine.
Use cases of Stable Diffusion MCP Server?
- Generating images from descriptive text.
- Editing images based on user-defined prompts.
- Managing and switching between different Stable Diffusion models.
FAQ from Stable Diffusion MCP Server?
- Can I use this server with any version of Stable Diffusion?
Yes, as long as the Stable Diffusion WebUI is properly configured and running with the API enabled.
- Is there a performance impact when using this server?
The server is optimized to use local GPU resources, ensuring high performance during image generation.
- What if I encounter issues?
Common troubleshooting steps include verifying the configuration paths and ensuring the Stable Diffusion WebUI is running.
Stable Diffusion MCP Server
An MCP (Model Context Protocol) server that connects Claude Desktop to your local Stable Diffusion WebUI installation, enabling AI-assisted image generation directly from your conversations.
📋 Overview
This project allows you to utilize your local Stable Diffusion installation through Claude Desktop, giving you the ability to:
- Generate images from text descriptions
- Edit existing images with text prompts
- List and switch between different Stable Diffusion models
- Access advanced image generation parameters
All while staying within the Claude Desktop interface, without switching between applications.
🌟 Features
- Text-to-Image Generation: Create images from text prompts
- Image-to-Image Editing: Modify existing images using text guidance
- Model Management: List and switch between your installed models
- Sampler Control: Access all WebUI samplers
- Connection Status: Verify connectivity with your local Stable Diffusion
- High Performance: Uses your local GPU resources for image generation
- Privacy-Focused: All processing happens on your machine
- SDXL Optimized: Default settings tuned for SDXL's 1024x1024 resolution
📦 Prerequisites
- Node.js v16.0.0 or higher
- Stable Diffusion WebUI with API enabled
- Claude Desktop
- Basic familiarity with command line interfaces
🚀 Installation
1. Clone this repository
git clone https://github.com/boxi-rgb/stable-diffusion-mcp.git
cd stable-diffusion-mcp
2. Install dependencies
npm install
3. Build the project
npm run build
4. Configure Stable Diffusion WebUI
Make sure your Stable Diffusion WebUI is running with the API enabled.
For Windows:
Edit your webui-user.bat
file and add --api
to the COMMANDLINE_ARGS:
@echo off
set COMMANDLINE_ARGS=--api
call webui.bat
For Linux/macOS:
Edit your webui-user.sh
file and add --api
to the COMMANDLINE_ARGS:
export COMMANDLINE_ARGS="--api"
./webui.sh
5. Configure Claude Desktop
- Open Claude Desktop
- Go to Settings
- Windows: Click on the gear icon in the bottom left
- macOS: Click on 'Claude' in the menu bar, then 'Settings...'
- Navigate to the 'Developer' tab
- Click 'Edit Config'
- Add the following to the
claude_desktop_config.json
file (create it if it doesn't exist):
{
"mcpServers": {
"stable-diffusion": {
"command": "node",
"args": [
"/FULL/PATH/TO/stable-diffusion-mcp/dist/index.js"
]
}
}
}
Important: Replace /FULL/PATH/TO/
with the actual full path to your project directory. For Windows users, use double backslashes (\\
) or forward slashes (/
) in your path.
- Save the file and restart Claude Desktop
🎮 Usage
Step 1: Verify installation
After starting Claude Desktop, you should see a tools icon (🔧) in the bottom right corner of the chat interface. Click on it to see if "stable-diffusion" appears in the list of available tools.
Step 2: Check connection
Type the following message to Claude:
Can you check if Stable Diffusion is connected properly?
Claude should use the check-status
tool to verify the connection with your local Stable Diffusion WebUI.
Step 3: Generate your first image
Type something like:
Please create an image of a futuristic city with flying cars.
Claude will use the generate-image
tool to send your request to Stable Diffusion and display the resulting image.
Advanced Usage
The MCP server provides several tools that Claude can use:
1. Image Generation
Generate an image of a cat wearing a space suit on Mars.
You can add more detailed parameters:
Generate an image of a mountain landscape with the following parameters:
- Width: 1024
- Height: 1024
- Steps: 30
- CFG Scale: 8
- Negative prompt: blurry, low quality
2. Model Switching
First, check available models:
What Stable Diffusion models are available on my system?
Then switch models:
Please switch to the AnythingV5 model.
3. Editing Existing Images
Save an image to your system, then:
Edit the image at C:/path/to/image.png to add flowers in the background.
4. List Sampling Methods
What samplers are available in my Stable Diffusion setup?
📁 Project Structure
stable-diffusion-mcp/
├── dist/ # Compiled JavaScript files
├── src/
│ ├── index.ts # Main entry point
│ ├── config.ts # Configuration settings
│ ├── server.ts # MCP server setup
│ ├── api/
│ │ ├── sd-api.ts # Stable Diffusion WebUI API client
│ │ └── types.ts # TypeScript type definitions
│ └── tools/
│ ├── image.ts # Image generation tools
│ ├── models.ts # Model management tools
│ └── utils.ts # Utility tools
├── output/ # Generated images directory
├── package.json
├── tsconfig.json
└── README.md
🔧 Configuration
You can customize the behavior of the MCP server by modifying src/config.ts
:
SD_API_URL
: The URL of your Stable Diffusion WebUI API (default:http://127.0.0.1:7861
)OUTPUT_DIR
: Directory where generated images will be saved (default:./output
)DEFAULT_PARAMS
: Default image generation parameters optimized for SDXL (1024x1024 resolution)
After modifying, rebuild the project with npm run build
.
🔍 Troubleshooting
Common Issues
MCP server not found in Claude Desktop
- Verify the path in
claude_desktop_config.json
is correct - Ensure you've included the full absolute path to the
dist/index.js
file - Check if the Node.js path is correct
Cannot connect to Stable Diffusion WebUI
- Make sure Stable Diffusion WebUI is running
- Verify that it was started with the
--api
flag - Check if the default port (7861) is being used or if you need to specify a custom port in
config.ts
Images not being generated
- Check the output directory exists and has write permissions
- Look for error messages in the Claude Desktop console
- Try running the
check-status
tool to verify connectivity
Debugging
If you're experiencing issues, you can enable more verbose logging by:
-
Running the MCP server directly from the command line to see error messages:
node dist/index.js
-
You can also use the MCP Inspector for debugging:
npx @modelcontextprotocol/inspector node /path/to/stable-diffusion-mcp/dist/index.js
🛠️ Development
Building from source
- Make changes to the TypeScript files in the
src/
directory - Run
npm run build
to compile the TypeScript code - Restart the MCP server in Claude Desktop (by restarting Claude Desktop)
Adding new features
To add new functionality:
- Add new API methods in
src/api/sd-api.ts
if needed - Create new tools in the appropriate file in
src/tools/
- Register your new tools in
src/server.ts
- Rebuild and test
📝 License
MIT License - See LICENSE for details.
⚠️ Disclaimer
This project is not officially affiliated with Anthropic (creators of Claude) or Stable Diffusion. Use at your own risk.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add some amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
🙏 Acknowledgments
- Anthropic for creating Claude and the Model Context Protocol
- AUTOMATIC1111 for the amazing Stable Diffusion WebUI
- Model Context Protocol for the TypeScript SDK
Made with ❤️ by boxi-rgb