Flux Image MCP Server
March 17, 2025 ยท View on GitHub
A Model Context Protocol (MCP) server for generating and modifying images using Replicate's Flux models.
Features
- ๐ผ๏ธ Generate Images: Create images from text prompts using Flux models
- ๐ Modify Images: Transform existing images with text prompts
- ๐ญ Inpaint Images: Remove or replace specific elements in images using Flux Fill Pro
- ๐ Get Image URLs: Obtain shareable URLs for local images
- ๐ List Images: Browse images stored in various directories
Prerequisites
Installation
# Clone the repository
git clone https://github.com/yourusername/flux-image-mcp.git
cd flux-image-mcp
# Install dependencies
npm install
# Build the project
npm run build
Configuration
Create a .env file in the root directory with the following variables:
REPLICATE_API_TOKEN=your_replicate_api_token
IMGBB_API_KEY=your_imgbb_api_key
You can also configure the following optional variables:
IMAGE_INPUT_DIR=/path/to/input/images
MODIFIED_IMAGES_DIR=/path/to/modified/images
GENERATED_IMAGES_DIR=/path/to/generated/images
If not specified, the server will use the following default paths:
- Input images:
./imagesor~/Downloads/flux-images-input - Modified images:
./modified_imagesor~/Downloads/flux-images-modified - Generated images:
./images-from-promptor~/Downloads/flux-images-generated
Usage with Claude Desktop
-
Open your Claude Desktop App configuration at:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
Add the Flux Image MCP server to your configuration:
{
"mcpServers": {
"flux-image": {
"command": "node",
"args": [
"/absolute/path/to/flux-image-mcp/dist/index.js"
]
}
}
}
- Restart Claude Desktop
Usage with Cursor.ai
- Open Cursor Settings
- Navigate to Features > MCP
- Click "+ Add New MCP Server"
- Use the following settings:
- Type:
stdio - Name:
flux-image - Command:
node /absolute/path/to/flux-image-mcp/dist/index.js
- Type:
- Click "Add"
Available Tools
1. Generate Image
Create an image from a text prompt.
Parameters:
prompt(required): Text description of the desired imageimage_filename(optional): Custom filename for the generated imagenegative_prompt(optional): Text describing what not to includewidth(optional): Width of the generated image (default: 1024)height(optional): Height of the generated image (default: 1024)
2. Modify Image
Modify an existing image using a text prompt.
Parameters:
image_path(required): Path to the image file to modifymodification_prompt(required): Text describing how to modify the imageoutput_filename(optional): Custom filename for the modified imagemodel(optional): Model to use ("flux-schnell" or "flux-pro", default: "flux-schnell")
3. Get Image URL
Obtain a shareable URL for a local image.
Parameters:
image_path(required): Path to the image fileupload_method(required): Method to use for uploading ('imgbb' or 'replicate')
4. List Images
List all images in a specific directory.
Parameters:
directory(required): Directory to list images from ('input', 'modified', or 'generated')
5. Inpaint Image
Remove or replace specific elements in an image using Flux Fill Pro.
Parameters:
image_path(required): Path to the image file to inpaintprompt(required): Text describing what should fill the masked areamask_path(optional): Path to an existing mask image (white areas will be inpainted)mask_area(optional): Object defining area to inpaint {x, y, width, height}target_colors(optional): Array of RGB color values to target for inpainting, e.g. [[0,255,0]]color_tolerance(optional): Tolerance for color matching (0-255, default: 30)negative_prompt(optional): Text describing what should NOT appear in the inpainted areaoutput_filename(optional): Custom filename for the inpainted imageguidance_scale(optional): Guidance scale for the model (default: 9.0)strength(optional): Strength of the inpainting effect (0.0-1.0, default: 1.0)
6. Simple Inpaint
Simplified interface for modifying images using natural language descriptions.
Parameters:
image_path(required): Path to the image file to modifyrequest(required): Natural language description of what to change in the imageoutput_filename(optional): Custom filename for the modified image
Inpainting Techniques
The inpainting functionality offers three different ways to specify what parts of an image to modify:
1. Mask-Based Inpainting
Use an existing mask image where white areas (255,255,255) indicate regions to be inpainted.
{
"image_path": "pizza.jpg",
"mask_path": "mask.png",
"prompt": "Plain cheese pizza with no toppings"
}
2. Area-Based Inpainting
Specify a rectangular region to be inpainted using coordinates.
{
"image_path": "company_banner.jpg",
"mask_area": {
"x": 150,
"y": 100,
"width": 200,
"height": 80
},
"prompt": "A prominent, bold company logo"
}
3. Color-Based Inpainting
Target specific colors in the image for inpainting (great for removing elements like green basil leaves).
{
"image_path": "pizza_with_basil.jpg",
"target_colors": [
[0, 128, 0],
[34, 139, 34],
[50, 205, 50]
],
"color_tolerance": 60,
"prompt": "Plain cheese pizza with no herbs or garnish",
"negative_prompt": "basil, leaves, herbs, green, garnish"
}
Example Queries
Here are some example queries to try in Claude Desktop or Cursor.ai:
- "Generate an image of a futuristic cityscape with flying cars and neon lights"
- "Take the image from my desktop called 'portrait.jpg' and modify it to make it look like an oil painting"
- "List all the images I've generated so far"
- "Get a shareable URL for the image called 'sunset.jpg' in my input folder"
- "Remove all the green basil leaves from the pizza image 'margherita.jpg'"
- "Make the logo in 'company_banner.jpg' more visible and prominent by inpainting the logo area"
- "Remove the person wearing a red shirt from the group photo 'team.jpg'"
- "Use simple_inpaint to remove the clouds from 'landscape.jpg' and make it a clear sunny day"
- "Use simple_inpaint to fix the blurry text in 'document.jpg' and make it sharp and readable"
Best Practices for Inpainting
For best results with the inpainting tool:
- Be specific in prompts: Describe exactly what should replace the masked area
- Use negative prompts: Explicitly state what should NOT appear in the inpainted area
- Adjust color tolerance: For color-based targeting, increase tolerance to capture more shades
- Multiple steps for complex tasks: For challenging modifications, break it down into multiple inpainting operations
- Choose the right targeting method:
- For colored elements (like basil): Use color-based targeting
- For specific regions (like logos): Use area-based targeting
- For complex shapes: Create a custom mask image
Example Scripts
The project includes example scripts demonstrating different use cases:
Removing Basil Leaves
npm run remove-basil
This example demonstrates how to use color-based targeting to remove green basil leaves from a pizza image.
Enhancing Logo and Flattening Crust
npm run enhance-logo
This example shows a multi-step process: first enhancing a logo using area-based targeting, then flattening the crust edges around a pizza.
Development
# Run in development mode with hot reloading
npm run dev
# Build for production
npm run build
# Start the server
npm start
# Run the basil removal example
npm run remove-basil
# Run the logo enhancement example
npm run enhance-logo
# Run the simplified inpainting example
npm run simple-inpaint
Troubleshooting
Image Not Found
If you get "Image not found" errors, check:
- The image path is correct and accessible
- The image exists in one of the search directories (input, modified, generated)
- File permissions allow the server to access the image
API Errors
If you encounter API errors:
- Verify your Replicate API token and ImgBB API key are correct
- Check your internet connection
- Ensure you haven't exceeded API rate limits
Inpainting Problems
If inpainting results don't match expectations:
- Make your prompt more specific and detailed
- Add a strong negative prompt to exclude unwanted elements
- Adjust the color tolerance or targeting method
- Try breaking the task into multiple smaller inpainting operations
License
MIT