generate_image
Create custom images from text prompts using the Flux Schnell model. Specify aspect ratio, resolution, format, and quality for tailored results. Ideal for quick, scalable image generation.
Instructions
Generate an image from a text prompt using Flux Schnell model
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aspect_ratio | No | Aspect ratio for the generated image | 1:1 |
| disable_safety_checker | No | Disable safety checker for generated images. | |
| go_fast | No | Run faster predictions with model optimized for speed (currently fp8 quantized); disable to run in original bf16 | |
| megapixels | No | Approximate number of megapixels for generated image | 1 |
| num_inference_steps | No | Number of denoising steps. 4 is recommended, and lower number of steps produce lower quality outputs, faster. | |
| num_outputs | No | Number of outputs to generate | |
| output_format | No | Format of the output images | webp |
| output_quality | No | Quality when saving the output images, from 0 to 100. 100 is best quality, 0 is lowest quality. Not relevant for .png outputs | |
| prompt | Yes | Prompt for generated image | |
| seed | No | Random seed. Set for reproducible generation | |
| support_image_mcp_response_type | No | Disable if the image type is not supported in the response, if it's Cursor app for example |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"aspect_ratio": {
"default": "1:1",
"description": "Aspect ratio for the generated image",
"enum": [
"1:1",
"16:9",
"21:9",
"3:2",
"2:3",
"4:5",
"5:4",
"3:4",
"4:3",
"9:16",
"9:21"
],
"type": "string"
},
"disable_safety_checker": {
"default": false,
"description": "Disable safety checker for generated images.",
"type": "boolean"
},
"go_fast": {
"default": true,
"description": "Run faster predictions with model optimized for speed (currently fp8 quantized); disable to run in original bf16",
"type": "boolean"
},
"megapixels": {
"default": "1",
"description": "Approximate number of megapixels for generated image",
"enum": [
"1",
"0.25"
],
"type": "string"
},
"num_inference_steps": {
"default": 4,
"description": "Number of denoising steps. 4 is recommended, and lower number of steps produce lower quality outputs, faster.",
"maximum": 4,
"minimum": 1,
"type": "integer"
},
"num_outputs": {
"default": 1,
"description": "Number of outputs to generate",
"maximum": 4,
"minimum": 1,
"type": "integer"
},
"output_format": {
"default": "webp",
"description": "Format of the output images",
"enum": [
"webp",
"jpg",
"png"
],
"type": "string"
},
"output_quality": {
"default": 80,
"description": "Quality when saving the output images, from 0 to 100. 100 is best quality, 0 is lowest quality. Not relevant for .png outputs",
"maximum": 100,
"minimum": 0,
"type": "integer"
},
"prompt": {
"description": "Prompt for generated image",
"minLength": 1,
"type": "string"
},
"seed": {
"description": "Random seed. Set for reproducible generation",
"type": "integer"
},
"support_image_mcp_response_type": {
"default": true,
"description": "Disable if the image type is not supported in the response, if it's Cursor app for example",
"type": "boolean"
}
},
"required": [
"prompt"
],
"type": "object"
}
Implementation Reference
- src/tools/generateImage.ts:9-55 (handler)The main handler function for the 'generate_image' tool. It calls the Replicate API with the Flux model to generate an image from the input prompt and other parameters, then constructs the MCP tool response content, optionally embedding the image as base64 if supported.export const registerGenerateImageTool = async ( input: ImageGenerationParams ): Promise<CallToolResult> => { const { support_image_mcp_response_type, ...predictionInput } = input; try { const [output] = (await replicate.run(CONFIG.imageModelId, { input: predictionInput, })) as [FileOutput]; const imageUrl = output.url() as unknown as string; if (support_image_mcp_response_type) { const imageBase64 = await outputToBase64(output); return { content: [ { type: "text", text: `This is a generated image link: ${imageUrl}`, }, { type: "image", data: imageBase64, mimeType: "image/png", }, { type: "text", text: `The image above is generated by the Flux model and prompt: ${input.prompt}`, }, ], }; } return { content: [ { type: "text", text: `This is a generated image link: ${imageUrl}`, }, { type: "text", text: `The image above is generated by the Flux model and prompt: ${input.prompt}`, }, ], }; } catch (error) { handleError(error); } };
- src/types/index.ts:75-83 (schema)Zod schema defining the input parameters for the 'generate_image' tool, extending createPredictionSchema with an option to support image responses in MCP.export const imageGenerationSchema = { ...createPredictionSchema, support_image_mcp_response_type: z .boolean() .default(true) .describe( "Disable if the image type is not supported in the response, if it's Cursor app for example" ), };
- src/tools/index.ts:21-26 (registration)Registers the 'generate_image' tool on the MCP server, specifying the tool name, description, input schema, and handler function.server.tool( "generate_image", "Generate an image from a text prompt using Flux Schnell model", imageGenerationSchema, registerGenerateImageTool );