generate-image
Create custom images by providing a text prompt, powered by Replicate and integrated into the MCP-Claude server for streamlined AI workflows.
Instructions
Generate an image using Replicate
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Prompt for the image generation |
Implementation Reference
- src/index.ts:223-260 (handler)The handler function that implements the core logic of the 'generate-image' tool. It generates an image using an external Replicate helper, fetches the image, encodes it to base64 (commented), and returns the URL as text.async ({ prompt }) => { const imageUrl = await generateImageWithReplicate(prompt); if (!imageUrl) { return { content: [ { type: "text", text: "Failed to generate image", }, ], }; } // Fetch the image and convert to base64 const response = await fetch(imageUrl); const arrayBuffer = await response.arrayBuffer(); const base64Data = Buffer.from(arrayBuffer).toString("base64"); // return { // content: [ // { // type: "image", // data: base64Data, // mimeType: "image/jpeg", // }, // ], // }; return { content: [ { type: "text", text: `Generated image URL: ${imageUrl}`, }, ], }; } );
- src/index.ts:221-222 (schema)Input schema for the 'generate-image' tool, defining the 'prompt' parameter using Zod.prompt: z.string().describe("Prompt for the image generation"), },
- src/index.ts:217-260 (registration)Registers the 'generate-image' tool on the MCP server with name, description, schema, and handler function.server.tool( "generate-image", "Generate an image using Replicate", { prompt: z.string().describe("Prompt for the image generation"), }, async ({ prompt }) => { const imageUrl = await generateImageWithReplicate(prompt); if (!imageUrl) { return { content: [ { type: "text", text: "Failed to generate image", }, ], }; } // Fetch the image and convert to base64 const response = await fetch(imageUrl); const arrayBuffer = await response.arrayBuffer(); const base64Data = Buffer.from(arrayBuffer).toString("base64"); // return { // content: [ // { // type: "image", // data: base64Data, // mimeType: "image/jpeg", // }, // ], // }; return { content: [ { type: "text", text: `Generated image URL: ${imageUrl}`, }, ], }; } );