generate-image
Generate images from text prompts using the Hugging Face FLUX.1-schnell model. Specify prompt and inference steps to create visual content.
Instructions
텍스트 프롬프트를 입력하면 이미지를 생성합니다. Hugging Face FLUX.1-schnell 모델을 사용합니다.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | 이미지 생성 프롬프트 (영어 권장) | |
| num_inference_steps | No | 추론 스텝 수 (기본값: 4, 범위: 1~10) |
Implementation Reference
- src/index.ts:365-420 (handler)Implementation of the 'generate-image' tool, which uses Hugging Face InferenceClient to generate images based on a text prompt.
server.registerTool( 'generate-image', { description: '텍스트 프롬프트를 입력하면 이미지를 생성합니다. Hugging Face FLUX.1-schnell 모델을 사용합니다.', inputSchema: z.object({ prompt: z.string().describe('이미지 생성 프롬프트 (영어 권장)'), num_inference_steps: z .number() .int() .min(1) .max(10) .optional() .default(4) .describe('추론 스텝 수 (기본값: 4, 범위: 1~10)') }) }, async ({ prompt, num_inference_steps }) => { const token = process.env.HF_TOKEN if (!token || token === 'YOUR_HF_TOKEN_HERE') { const errorText = '오류: HF_TOKEN 환경변수가 설정되지 않았습니다. .cursor/mcp.json의 env.HF_TOKEN에 실제 토큰을 입력해 주세요.' return { content: [{ type: 'text' as const, text: errorText }], structuredContent: { content: [{ type: 'text' as const, text: errorText }] } } } try { const client = new InferenceClient(token) const imageBlob = await client.textToImage( { provider: 'together', model: 'black-forest-labs/FLUX.1-schnell', inputs: prompt, parameters: { num_inference_steps } }, { outputType: 'blob' } ) const base64 = Buffer.from(await imageBlob.arrayBuffer()).toString('base64') return { content: [ { type: 'image' as const, data: base64, mimeType: 'image/png' as const } ] } } catch (err) { const errorText = `오류: 이미지 생성 실패 — ${err instanceof Error ? err.message : String(err)}` return { content: [{ type: 'text' as const, text: errorText }], structuredContent: { content: [{ type: 'text' as const, text: errorText }] } } } } )