Image Generation MCP Server
An MCP (Model Context Protocol)β server implementation for generating images using Replicateβs black-forest-labs/flux-schnell
model.
Ideally to be used with Cursorβs MCP feature, but can be used with any MCP client.
Features
- Generate images from text prompts
- Configurable image parameters (resolution, aspect ratio, quality)
- Save generated images to specified directory
- Full MCP protocol compliance
- Error handling and validation
Prerequisites
- Node.js 16+
- Replicate API token
- TypeScript SDK for MCP
Setup
-
Clone the repository
-
Install dependencies:
npm install
-
Add your Replicate API token directly in the code at
src/imageService.ts
by updating theapiToken
constant:// No environment variables are used since they can't be easily set in cursor const apiToken = "your-replicate-api-token-here";
Note: If using with Claude, you can create a
.env
file in the root directory and set your API token there:REPLICATE_API_TOKEN=your-replicate-api-token-here
Then build the project:
npm run build
Usage
To use with cursor:
- Go to Settings
- Select Features
- Scroll down to βMCP Serversβ
- Click βAdd new MCP Serverβ
- Set Type to βCommandβ
- Set Command to:
node ./path/to/dist/server.js
API Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
prompt | string | Yes | - | Text prompt for image generation |
output_dir | string | Yes | - | Server directory path to save generated images |
go_fast | boolean | No | false | Enable faster generation mode |
megapixels | string | No | β1β | Resolution quality (β1β, β2β, β4β) |
num_outputs | number | No | 1 | Number of images to generate (1-4) |
aspect_ratio | string | No | β1:1β | Aspect ratio (β1:1β, β4:3β, β16:9β) |
output_format | string | No | βwebpβ | Image format (βwebpβ, βpngβ, βjpegβ) |
output_quality | number | No | 80 | Compression quality (1-100) |
num_inference_steps | number | No | 4 | Number of denoising steps (4-20) |
Example Request
{
"prompt": "black forest gateau cake spelling out 'FLUX SCHNELL'",
"output_dir": "/var/output/images",
"filename": "black_forest_cake",
"output_format": "webp"
"go_fast": true,
"megapixels": "1",
"num_outputs": 2,
"aspect_ratio": "1:1"
}
Example Response
{
"image_paths": [
"/var/output/images/output_0.webp",
"/var/output/images/output_1.webp"
],
"metadata": {
"model": "black-forest-labs/flux-schnell",
"inference_time_ms": 2847
}
}
Error Handling
The server handles the following error types:
- Validation errors (invalid parameters)
- API errors (Replicate API issues)
- Server errors (filesystem, permissions)
- Unknown errors (unexpected issues)
Each error response includes:
- Error code
- Human-readable message
- Detailed error information
License
ISC
Last updated on