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
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Text 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
- src/index.ts:105-140 (handler)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 : '알 수 없는 오류'}` } ] } } }
- src/index.ts:102-104 (schema)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 : '알 수 없는 오류'}` } ] } } } )
- src/index.ts:6-8 (schema)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') })