UNPKG

replicate-flux-mcp

Version:
39 lines (38 loc) 1.31 kB
import { replicate } from "../services/replicate.js"; import { handleError } from "../utils/error.js"; import { mimeFor, outputToBase64 } from "../utils/image.js"; import { CONFIG } from "../config/index.js"; export const registerGenerateImageTool = async (input) => { try { const [output] = (await replicate.run(CONFIG.imageModelId, { input, })); const imageUrl = output.url(); const imageBase64 = await outputToBase64(output); const structuredContent = { url: imageUrl, prompt: input.prompt, format: input.output_format, aspect_ratio: input.aspect_ratio, ...(input.seed !== undefined ? { seed: input.seed } : {}), }; return { content: [ { type: "text", text: `Generated image URL: ${imageUrl}` }, { type: "image", data: imageBase64, mimeType: mimeFor(input.output_format), }, { type: "text", text: `Generated by Flux Schnell with prompt: ${input.prompt}`, }, ], structuredContent, }; } catch (error) { return handleError(error); } };