Skip to main content
Glama

Image Generation MCP Server

by mikeyny

generate-image

Create custom images from text prompts with configurable settings like aspect ratio, resolution, and output format. Save results to a specified directory.

Instructions

Generate an image based on a prompt

Input Schema

NameRequiredDescriptionDefault
aspect_ratioNo
filenameNoBase filename to save the image(s) with
go_fastNo
megapixelsNo
num_inference_stepsNo
num_outputsNo
output_dirYesFull absolute path to output directory. For Windows, use double backslashes like 'C:\\Users\\name\\path'. For Unix/Mac use '/path/to/dir'. Always use the proper path otherwise you will get an error.
output_formatNo
output_qualityNo
promptYes

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "aspect_ratio": { "enum": [ "1:1", "4:3", "16:9" ], "type": "string" }, "filename": { "description": "Base filename to save the image(s) with", "type": "string" }, "go_fast": { "type": "boolean" }, "megapixels": { "enum": [ "1", "2", "4" ], "type": "string" }, "num_inference_steps": { "maximum": 20, "minimum": 4, "type": "number" }, "num_outputs": { "maximum": 4, "minimum": 1, "type": "number" }, "output_dir": { "description": "Full absolute path to output directory. For Windows, use double backslashes like 'C:\\\\Users\\\\name\\\\path'. For Unix/Mac use '/path/to/dir'. Always use the proper path otherwise you will get an error.", "type": "string" }, "output_format": { "enum": [ "webp", "png", "jpeg" ], "type": "string" }, "output_quality": { "maximum": 100, "minimum": 1, "type": "number" }, "prompt": { "type": "string" } }, "required": [ "prompt", "output_dir" ], "type": "object" }

Implementation Reference

  • Handler function for the 'generate-image' tool. It calls imageService.generateImages(params) and returns the JSON stringified result or error message.
    async (params) => { try { const result = await imageService.generateImages(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } }
  • Zod input schema definition for the 'generate-image' tool parameters.
    { prompt: z.string(), output_dir: z.string().describe("Full absolute path to output directory. For Windows, use double backslashes like 'C:\\\\Users\\\\name\\\\path'. For Unix/Mac use '/path/to/dir'. Always use the proper path otherwise you will get an error."), filename: z.string().optional().describe("Base filename to save the image(s) with"), go_fast: z.boolean().optional(), megapixels: z.enum(["1", "2", "4"]).optional(), num_outputs: z.number().min(1).max(4).optional(), aspect_ratio: z.enum(["1:1", "4:3", "16:9"]).optional(), output_format: z.enum(["webp", "png", "jpeg"]).optional(), output_quality: z.number().min(1).max(100).optional(), num_inference_steps: z.number().min(4).max(20).optional() },
  • src/server.ts:19-52 (registration)
    Registration of the 'generate-image' tool on the MCP server using server.tool() with name, description, schema, and handler.
    server.tool( "generate-image", "Generate an image based on a prompt", { prompt: z.string(), output_dir: z.string().describe("Full absolute path to output directory. For Windows, use double backslashes like 'C:\\\\Users\\\\name\\\\path'. For Unix/Mac use '/path/to/dir'. Always use the proper path otherwise you will get an error."), filename: z.string().optional().describe("Base filename to save the image(s) with"), go_fast: z.boolean().optional(), megapixels: z.enum(["1", "2", "4"]).optional(), num_outputs: z.number().min(1).max(4).optional(), aspect_ratio: z.enum(["1:1", "4:3", "16:9"]).optional(), output_format: z.enum(["webp", "png", "jpeg"]).optional(), output_quality: z.number().min(1).max(100).optional(), num_inference_steps: z.number().min(4).max(20).optional() }, async (params) => { try { const result = await imageService.generateImages(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } } );
  • TypeScript interface defining ImageGenerationParams, matching the input schema for generate-image tool.
    export interface ImageGenerationParams { prompt: string; output_dir: string; filename?: string; go_fast?: boolean; megapixels?: "1" | "2" | "4"; num_outputs?: number; aspect_ratio?: "1:1" | "4:3" | "16:9"; output_format?: "webp" | "png" | "jpeg"; output_quality?: number; num_inference_steps?: number; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mikeyny/ai-image-gen-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server