generate_image
Create custom images from text prompts using AI image generation. Describe what you want to see and generate corresponding visuals.
Instructions
텍스트 프롬프트를 사용하여 이미지를 생성하는 도구
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | 이미지 생성을 위한 프롬프트 |
Implementation Reference
- src/index.ts:256-289 (handler)Core handler function that generates an image from a text prompt using Hugging Face Inference API (FLUX.1-schnell model) and returns it as base64 string.const generateImage = async (prompt: string, hfToken: string): Promise<string> => { if (!hfToken) { throw new Error('HF_TOKEN이 설정되지 않았습니다. Hugging Face API 토큰을 설정해주세요.') } const client = new InferenceClient(hfToken) try { const image = await client.textToImage({ provider: "fal-ai", model: "black-forest-labs/FLUX.1-schnell", inputs: prompt, parameters: { num_inference_steps: 5 } }) // Convert to base64 let base64: string if (typeof image === 'string') { // If it's already a base64 string, use it directly base64 = image } else if (image && typeof image === 'object' && 'arrayBuffer' in image) { // If it's a Blob-like object const arrayBuffer = await (image as any).arrayBuffer() base64 = Buffer.from(arrayBuffer).toString('base64') } else { // If it's a Buffer or Uint8Array base64 = Buffer.from(image as any).toString('base64') } return base64 } catch (error) { throw new Error(`이미지 생성 중 오류가 발생했습니다: ${error instanceof Error ? error.message : '알 수 없는 오류'}`) } }
- src/index.ts:39-41 (schema)Zod schema defining the input for generate_image tool: a single 'prompt' string parameter.const ImageGenerationToolSchema = z.object({ prompt: z.string().describe('이미지 생성을 위한 프롬프트') })
- src/index.ts:394-407 (registration)Registration of generate_image tool in the MCP listTools handler, specifying name, description, and input schema.{ name: 'generate_image', description: '텍스트 프롬프트를 사용하여 이미지를 생성하는 도구', inputSchema: { type: 'object', properties: { prompt: { type: 'string', description: '이미지 생성을 위한 프롬프트' } }, required: ['prompt'] } }
- src/index.ts:579-608 (handler)MCP CallToolRequest handler branch for generate_image: validates input with schema, invokes generateImage function, returns base64 image content or error text.if (request.params.name === 'generate_image') { try { const { prompt } = ImageGenerationToolSchema.parse(request.params.arguments) const base64Image = await generateImage(prompt, hfToken) return { content: [ { type: 'image', data: base64Image, mimeType: 'image/png', annotations: { audience: ['user'], priority: 0.9 } } ] } } catch (error) { return { content: [ { type: 'text', text: `이미지 생성 오류: ${error instanceof Error ? error.message : '알 수 없는 오류'}` } ], isError: true } }