Skip to main content
Glama

generate-image

Create images from text prompts using AI generation through the MCP-Claude server's integration with Replicate.

Instructions

Generate an image using Replicate

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesPrompt for the image generation

Implementation Reference

  • src/index.ts:217-260 (registration)
    Registration of the 'generate-image' MCP tool, including description, input schema, and inline 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}`,
            },
          ],
        };
      }
    );
  • Inline handler function that executes the tool logic: generates image using helper, fetches it, and returns URL in text content.
    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}`,
          },
        ],
      };
    }
  • Zod input schema defining the 'prompt' parameter for the tool.
    {
      prompt: z.string().describe("Prompt for the image generation"),
    },
  • Helper function that performs the actual image generation by calling the Replicate API with the given prompt and default parameters.
    export async function generateImageWithReplicate(
      prompt: string,
      options: Partial<ReplicatePredictionInput> = {}
    ): Promise<string> {
      const apiToken = process.env.REPLICATE_API_TOKEN;
      if (!apiToken) {
        throw new Error("REPLICATE_API_TOKEN environment variable is not set");
      }
    
      // Default parameters
      const defaultInput: ReplicatePredictionInput = {
        width: 768,
        height: 768,
        prompt: prompt,
        refine: "expert_ensemble_refiner",
        scheduler: "K_EULER",
        lora_scale: 0.6,
        num_outputs: 1,
        guidance_scale: 7.5,
        apply_watermark: false,
        high_noise_frac: 0.8,
        negative_prompt: "",
        prompt_strength: 0.8,
        num_inference_steps: 25,
        ...options,
      };
    
      const payload: ReplicatePredictionPayload = {
        version: "7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
        input: defaultInput,
      };
    
      try {
        const response = await fetch("https://api.replicate.com/v1/predictions", {
          method: "POST",
          headers: {
            Authorization: `Bearer ${apiToken}`,
            "Content-Type": "application/json",
            Prefer: "wait", // Synchronous mode
          },
          body: JSON.stringify(payload),
        });
    
        if (!response.ok) {
          const errorData = await response.json();
          throw new Error(errorData.error || "Failed to create prediction");
        }
    
        const data: ReplicatePredictionResponse = await response.json();
    
        if (data.error) {
          throw new Error(data.error);
        }
    
        if (
          !data.output ||
          !Array.isArray(data.output) ||
          data.output.length === 0
        ) {
          throw new Error("No output generated or invalid output format");
        }
    
        const imageUrl = data.output[0];
        return imageUrl;
      } catch (error) {
        console.error("Error generating image with Replicate:", error);
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It only states the tool generates an image using Replicate, without disclosing behavioral traits like cost implications, rate limits, quality settings, or what happens on failure. This leaves significant gaps for a tool that likely involves external API calls and resource usage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It is front-loaded, directly stating the tool's purpose without unnecessary details. Every word earns its place, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of image generation (external API, potential costs, quality variations) and lack of annotations or output schema, the description is incomplete. It doesn't cover return values, error handling, or operational context, leaving the agent with insufficient information to use the tool effectively beyond basic invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'prompt' parameter well-documented in the schema. The description adds no additional meaning beyond the schema, such as examples or constraints on prompt formatting. With high schema coverage, the baseline is 3, as the description doesn't compensate but doesn't detract either.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('generate') and resource ('image'), specifying it uses Replicate as the service. It distinguishes from sibling tools like 'add' or 'get-forecast' by focusing on image generation, though it doesn't explicitly differentiate from 'display_generated_image' which might be related. The purpose is specific but lacks sibling differentiation details.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description does not mention any context, prerequisites, or exclusions, such as when to choose this over other image generation methods or how it relates to 'display_generated_image'. It offers no usage instructions beyond the basic action.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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