Enables high-quality image generation using FLUX.1 Kontext [Max] model through Replicate's API, with support for text-to-image generation, image editing, multiple aspect ratios, and prediction management including tracking, monitoring, and canceling running predictions.
Replicate FLUX.1 Kontext [Max] MCP Server
A Model Context Protocol (MCP) server that provides access to FLUX.1 Kontext [Max] - the frontier image generation model through the Replicate API. This server enables high-quality image generation with advanced text rendering capabilities and superior contextual understanding.
š Repository: https://github.com/PierrunoYT/replicate-flux-kontext-max-mcp-server
š Ready to use! Pre-built executable included - no compilation required.
ā Enhanced Reliability: Server handles missing API tokens gracefully without crashes and includes robust error handling.
Features
Frontier Image Generation: Uses FLUX.1 Kontext [Max] - the latest frontier model via Replicate API
Advanced Text Rendering: Superior text integration and rendering capabilities
Contextual Understanding: Enhanced understanding of complex prompts and context
Image Editing Support: Both text-to-image and image editing capabilities
Automatic Image Download: Generated images are automatically saved to local
imagesdirectoryMultiple Aspect Ratios: Support for 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 4:5, 5:4, 21:9, 9:21, 2:1, 1:2
Reproducible Results: Optional seed parameter for consistent outputs
Prediction Management: Track, monitor, and cancel running predictions
Flexible Output Formats: Support for JPEG and PNG formats
Safety Controls: Configurable safety tolerance levels (0-6)
Detailed Responses: Returns both local file paths and original URLs with metadata
Robust Error Handling: Graceful handling of missing API tokens without server crashes
Universal Portability: Works anywhere with npx - no local installation required
Enhanced Reliability: Graceful shutdown handlers and comprehensive error reporting
Prerequisites
Node.js 18 or higher
Replicate API token
Installation
1. Get your Replicate API Token
Visit Replicate
Sign up for an account
Navigate to your account settings
Generate an API token (starts with
r8_)
2. Clone or Download
3. Install Dependencies (Optional)
The server is pre-built, but if you want to modify it:
Configuration
š Recommended: Universal npx Configuration (Works Everywhere)
Best option for portability - works on any machine with Node.js:
Benefits:
ā Universal Access: Works on any machine with Node.js
ā No Local Installation: npx downloads and runs automatically
ā Always Latest Version: Pulls from GitHub repository
ā Cross-Platform: Windows, macOS, Linux compatible
ā Settings Sync: Works everywhere you use your MCP client
Alternative: Local Installation
If you prefer to install locally, use the path helper:
This will output the complete MCP configuration with the correct absolute path.
For Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
For Kilo Code MCP Settings
Add to your MCP settings file at:
C:\Users\[username]\AppData\Roaming\Kilo-Code\MCP\settings\mcp_settings.json
Available Tools
flux_kontext_max_generate
Generate images using FLUX.1 Kontext [Max] with real-time processing via Replicate.
Parameters:
prompt(required): Text description of the image to generate, or instruction on how to edit the given imageinput_image(optional): Image to use as reference. Must be jpeg, png, gif, or webp. Can be a URL or base64 data URIseed(optional): Random seed for reproducible generationaspect_ratio(optional): "match_input_image", "1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "4:5", "5:4", "21:9", "9:21", "2:1", "1:2" (default: "match_input_image")output_format(optional): "jpg" or "png" (default: "jpg")safety_tolerance(optional): Safety level 0-6 (default: 2)
Response includes:
Image URLs for immediate access
Generation metadata (seed, prediction details)
File information (content type, dimensions)
Local file paths for downloaded images
flux_kontext_max_generate_async
Generate images using FLUX.1 Kontext [Max] with async prediction tracking for monitoring progress.
Parameters: Same as flux_kontext_max_generate
Use this tool when:
You want to monitor generation progress
Working with complex prompts that might take longer
Need detailed prediction tracking and logging
Features:
Prediction-based processing with status polling
5-minute timeout with progress updates
Detailed logging of generation progress
Prediction ID returned for tracking
flux_kontext_max_cancel_prediction
Cancel a running prediction by its ID.
Parameters:
prediction_id(required): The ID of the prediction to cancel
Use this tool when:
You need to stop a long-running generation
Want to free up resources
Made a mistake in the prompt and want to start over
flux_kontext_max_get_prediction
Get the status and details of a prediction by its ID.
Parameters:
prediction_id(required): The ID of the prediction to check
Response includes:
Current prediction status
Creation and completion timestamps
Input parameters used
Output results (if completed)
Error details (if failed)
Generation logs
š„ How Image Download Works
The Replicate FLUX.1 Kontext [Max] MCP server automatically downloads generated images to your local machine. Here's the complete process:
1. Image Generation Flow
API Call: Server calls Replicate's FLUX.1 Kontext [Max] API
Response: Replicate returns URLs for generated images
Auto-Download: Server immediately downloads images to local storage
Response: Returns both local paths and original URLs
2. Download Implementation
Download Function (downloadImage):
Filename Generation (generateImageFilename):
3. File Storage Details
Directory Structure:
Filename Format:
Prefix:
flux_kontext_max_Prompt: First 50 chars, sanitized (alphanumeric + underscores)
Seed: Random seed used for generation (if provided)
Index: Image number (for multiple images)
Timestamp: ISO timestamp for uniqueness
Extension:
.jpgor.pngbased on output_format
4. Response Format
The server returns both local and remote information:
Example Usage
Basic Image Generation
With Specific Parameters
Advanced Usage with Text Rendering
Text-Heavy Prompts (Kontext [Max] Specialty)
Image Editing Examples
Basic Image Editing
Complex Image Editing
Text Addition to Images
Prediction Management
Track Generation Progress
Cancel Long-Running Generation
Technical Details
Architecture
Language: TypeScript with ES2022 target
Runtime: Node.js 18+ with ES modules
Protocol: Model Context Protocol (MCP) SDK v1.0.0
API Client: Replicate JavaScript client v0.34.1
Validation: Zod schema validation
API Model Used
Model:
black-forest-labs/flux-kontext-maxon ReplicateMethod: Both direct
run()and prediction-basedpredictions.create()
Error Handling
Graceful API token handling: Server continues running even without REPLICATE_API_TOKEN set
No crash failures: Removed
process.exit()calls that caused connection dropsNull safety checks: All tools validate API client availability before execution
Graceful shutdown: Proper SIGINT and SIGTERM signal handling
API error catching: Comprehensive error reporting with detailed context
Timeout handling: Robust async request management with progress updates
User-friendly messages: Clear error descriptions instead of technical crashes
Development
Project Structure
Scripts
npm run build- Compile TypeScript to JavaScriptnpm run dev- Watch mode for developmentnpm run start- Start the server directlynpm run test- Test server startup and basic functionalitynpm run get-path- Get configuration path for your system
Making Changes
Edit files in the
src/directoryRun
npm run buildto compileRestart your MCP client to use the updated server
Testing
This runs a basic connectivity test that verifies:
Server starts correctly
MCP protocol initialization
Tool discovery functionality
API Costs
This server uses the Replicate platform, which charges per image generation. Check Replicate pricing for current rates.
Typical costs (as of 2024):
FLUX.1 Kontext [Max]: ~$0.05-0.15 per image
Costs vary by resolution and complexity
Troubleshooting
Server not appearing in MCP client
Recommended: Use the npx configuration for universal compatibility
If using local installation, verify the path to
build/index.jsis correct and absoluteEnsure Node.js 18+ is installed:
node --versionTest server startup:
npm run testRestart your MCP client (Claude Desktop, Kilo Code, etc.)
Note: Server will start successfully even without REPLICATE_API_TOKEN - check tool responses for API token errors
Image generation failing
Verify your Replicate API token is valid and has sufficient credits
Check that your prompt follows Replicate's content policy
Try simplifying the prompt or adjusting parameters
Use the async tool for complex requests
Check the server logs for detailed error messages
Ensure the FLUX.1 Kontext [Max] model is available in your region
Build issues
If you need to rebuild the server:
Configuration issues
Use the helper script to get the correct path:
Support
For issues with:
This MCP server: Create an issue in this repository
Replicate API: Check Replicate documentation
MCP Protocol: See MCP documentation
License
MIT License - see LICENSE file for details.
Contributing
Fork the repository
Create a feature branch
Make your changes
Test with
npm run testSubmit a pull request
Changelog
v1.2.0 (Latest)
š API Migration: Migrated from FAL AI to Replicate API
š New Tools: Added
flux_kontext_max_cancel_predictionandflux_kontext_max_get_predictionš Prediction Management: Full prediction lifecycle management with tracking
š§ Enhanced Async: Improved async generation with detailed progress monitoring
š”ļø Better Error Handling: Enhanced error reporting and graceful degradation
š Updated Documentation: Comprehensive documentation for Replicate integration
ā” Performance: Optimized image download and processing pipeline
v1.1.0 (Previous)
⨠NEW: Image Editing: Added FLUX.1 Kontext [Max] image editing capabilities
š§ New Tools:
flux_kontext_max_editandflux_kontext_max_edit_asyncfor image editingš¼ļø Image Input Support: Accept image URLs and base64 data URIs for editing
šØ Advanced Editing: Complex image modifications with contextual understanding
š Text Addition: Add text overlays and modifications to existing images
š Dual Editing Methods: Both real-time and async queue-based image editing
š„ Auto-download: Edited images automatically saved with descriptive filenames
v1.0.0 (Initial)
šØ Image Generation: Basic FLUX.1 Kontext [Max] text-to-image generation
š„ Auto-download: Automatic local image saving
š§ MCP Integration: Full Model Context Protocol support
āļø Configuration: Easy setup with environment variables