replicate-flux-mcp
Version:
MCP for Replicate Flux Model
41 lines (40 loc) • 1.15 kB
JavaScript
import { replicate } from "../services/replicate.js";
import { handleError } from "../utils/error.js";
import { urlToSvg } from "../utils/image.js";
import { CONFIG } from "../config/index.js";
export const registerGenerateSvgTool = async (input) => {
try {
const output = (await replicate.run(CONFIG.svgModelId, {
input,
}));
const svgUrl = output.url();
if (!svgUrl) {
throw new Error("Failed to generate SVG URL");
}
let svg;
try {
svg = await urlToSvg(svgUrl);
}
catch {
svg = undefined;
}
const content = [
{ type: "text", text: `Generated SVG URL: ${svgUrl}` },
];
if (svg)
content.push({ type: "text", text: svg });
return {
content,
structuredContent: {
url: svgUrl,
prompt: input.prompt,
size: input.size,
style: input.style,
...(svg ? { svg } : {}),
},
};
}
catch (error) {
return handleError(error);
}
};