Skip to main content
Glama
sammyl720

Image Generator MCP Server

by sammyl720

generate_image

Create custom images from text descriptions using AI, saving them to your specified directory with a chosen filename.

Instructions

Generate an image from a prompt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesA prompt detailing what image to generate.
imageNameYesThe filename for the image excluding any extensions.

Implementation Reference

  • Core handler function that generates the image using OpenAI DALL-E 3 API and returns base64 encoded image.
    async generateImage(prompt: string, size: ImageGenerateParams['size'] = "1024x1024") { const response = await this.openai.images.generate({ model: IMAGE_MODEL, prompt, size, response_format: 'b64_json' }); return response.data[0].b64_json; }
  • MCP CallToolRequestSchema handler specifically for 'generate_image': validates args, calls ImageGenerator, saves image file, returns resource URI.
    if (request.params.name !== "generate_image") { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!isValidImageGenerationArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, "Invalid image generation arguments" ) }; const { prompt, imageName } = request.params.arguments; const base64 = await new ImageGenerator().generateImage(prompt); const fileName = `${imageName.replace(/\..*$/, '')}.png`; const filepath = await imageSaver.saveBase64(fileName, base64!); return { toolResult: { uri: `file://${filepath}`, type: 'image', mimeType: 'image/png' } }
  • src/index.ts:53-71 (registration)
    Tool registration in ListToolsRequestSchema handler, including name, description, and input schema.
    tools: [{ name: "generate_image", description: "Generate an image from a prompt.", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "A prompt detailing what image to generate." }, imageName: { type: "string", description: "The filename for the image excluding any extensions." } }, required: ["prompt", "imageName"] } }] })
  • Validation function for generate_image input arguments matching the schema.
    export function isValidImageGenerationArgs(args: any): args is ImageGenerationRequestParams { return typeof args === "object" && args !== null && "prompt" in args && typeof args.prompt === 'string' && "imageName" in args && typeof args.imageName === 'string'; }
  • TypeScript interface defining the input parameters for generate_image tool.
    export interface ImageGenerationRequestParams { prompt: string; imageName: string; }

Other 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/sammyl720/image-generator-mcp-server'

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