Skip to main content
Glama

TypeScript MCP Server Boilerplate

by mazah81-gif

image_generation

Create AI-generated images from text descriptions to visualize concepts, ideas, or scenes using natural language prompts.

Instructions

Generate an image from a text prompt using AI

Input Schema

NameRequiredDescriptionDefault
promptYesText description of the image to generate

Input Schema (JSON Schema)

{ "properties": { "prompt": { "description": "Text description of the image to generate", "type": "string" } }, "required": [ "prompt" ], "type": "object" }

Implementation Reference

  • The handler function that performs AI image generation from text prompt using Hugging Face InferenceClient with FLUX.1-schnell model, handles errors, converts image to base64.
    async ({ prompt }: { prompt: string }) => { try { const client = new InferenceClient(config.HF_TOKEN) const imageBlob = await client.textToImage({ provider: 'fal-ai', model: 'black-forest-labs/FLUX.1-schnell', inputs: prompt, parameters: { num_inference_steps: 5 } }) as unknown as Blob // Convert Blob to base64 const arrayBuffer = await imageBlob.arrayBuffer() const buffer = Buffer.from(arrayBuffer) const base64Data = buffer.toString('base64') return { content: [ { type: 'image', data: base64Data, mimeType: 'image/png' } ] } } catch (error) { return { content: [ { type: 'text', text: `이미지 생성 오류: ${error instanceof Error ? error.message : '알 수 없는 오류'}` } ] } } }
  • Zod input schema for the image_generation tool, requiring a 'prompt' string.
    { prompt: z.string().describe('Text description of the image to generate') },
  • src/index.ts:99-141 (registration)
    McpServer.tool registration for 'image_generation' tool including name, description, schema, and handler.
    server.tool( 'image_generation', 'Generate an image from a text prompt using AI', { prompt: z.string().describe('Text description of the image to generate') }, async ({ prompt }: { prompt: string }) => { try { const client = new InferenceClient(config.HF_TOKEN) const imageBlob = await client.textToImage({ provider: 'fal-ai', model: 'black-forest-labs/FLUX.1-schnell', inputs: prompt, parameters: { num_inference_steps: 5 } }) as unknown as Blob // Convert Blob to base64 const arrayBuffer = await imageBlob.arrayBuffer() const buffer = Buffer.from(arrayBuffer) const base64Data = buffer.toString('base64') return { content: [ { type: 'image', data: base64Data, mimeType: 'image/png' } ] } } catch (error) { return { content: [ { type: 'text', text: `이미지 생성 오류: ${error instanceof Error ? error.message : '알 수 없는 오류'}` } ] } } } )
  • Configuration schema requiring HF_TOKEN for image generation authentication.
    export const configSchema = z.object({ HF_TOKEN: z.string().describe('Hugging Face API token for image generation') })

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/mazah81-gif/my-mcp-server-2025'

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