Skip to main content
Glama

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
NameRequiredDescriptionDefault
promptYesPrompt for the image generation

Implementation Reference

  • 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}`, }, ], }; } );
  • 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}`, }, ], }; } );

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/virajsamarasinghe/MCP-Claude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server