Skip to main content
Glama

generate_image

Create custom images from text prompts using AI. Specify dimensions and quantity to generate base64-encoded images for your projects.

Instructions

Generates and returns an image based on the provided promptUse this tool when you need to generate an image based on a promptThe image will be returned as a base64 encoded string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe prompt to generate an image for
widthNoThe width of the image to generate
heightNoThe height of the image to generate
numberOfImagesNoThe number of images to generate

Implementation Reference

  • Core handler function for the generate_image tool. Selects provider from env var and delegates to provider-specific generateImage function.
    export const handler = async (prompt: string, params: Record<string, any>) => {
      const provider = process.env.PROVIDER || "replicate"
      const { generateImage } = await useImageProvider(provider)
      const generatedImages = await generateImage(prompt, {
        ...params,
        n: params.numberOfImages || undefined,
      })
      if (!generatedImages || generatedImages.length === 0) {
        throw new Error(`No image returned from ${provider}`)
      }
      return generatedImages
    }
  • Zod schema defining input parameters for the generate_image tool.
    export const InputSchema = {
      prompt: z.string().describe("The prompt to generate an image for"),
      width: z.coerce.number().describe("The width of the image to generate").optional(),
      height: z.coerce.number().describe("The height of the image to generate").optional(),
      numberOfImages: z.coerce.number().describe("The number of images to generate").optional(),
    }
  • src/server.ts:13-33 (registration)
    Registers the generate_image tool on the MCP server for SSE transport.
    server.tool(
      "generate_image",
      "Generates and returns an image based on the provided prompt" +
      "Use this tool when you need to generate an image based on a prompt" +
      "The image will be returned as a base64 encoded string",
      InputSchema,
      async (args) => {
        try {
          const content = await handler(args.prompt, args)
          return {
            content,
            isError: false,
          }
        } catch (error) {
          return {
            content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
            isError: true,
          }
        }
      }
    )
  • src/index.ts:10-30 (registration)
    Registers the generate_image tool on the MCP server for stdio transport.
    server.tool(
      "generate_image",
      "Generates and returns an image based on the provided prompt" +
      "Use this tool when you need to generate an image based on a prompt" +
      "The image will be returned as a base64 encoded string",
      InputSchema,
      async (args) => {
        try {
          const content = await handler(args.prompt, args)
          return {
            content,
            isError: false,
          }
        } catch (error) {
          return {
            content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
            isError: true,
          }
        }
      }
    )
  • Helper function that routes to the appropriate provider's image generation based on the provider string.
    export const useImageProvider = (provider: string) => {
    
      switch (provider) {
        case "together":
          return useTogether()
        case "replicate":
          return useReplicate()
        default:
          throw new Error(`Provider ${provider} not supported`)
      }
    }
Behavior3/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 discloses that the image is 'returned as a base64 encoded string,' which adds useful behavioral context beyond the input schema. However, it lacks details on potential limitations (e.g., rate limits, quality constraints, or error conditions), leaving gaps for a mutation tool.

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

Conciseness4/5

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

The description is front-loaded with the purpose and usage guidelines in two sentences, with no wasted words. However, the lack of punctuation between sentences ('promptUse this tool') slightly reduces readability, preventing a perfect score of 5.

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

Completeness3/5

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

Given the tool's complexity (image generation with 4 parameters) and no annotations or output schema, the description is moderately complete. It covers the basic operation and output format but lacks details on behavioral traits (e.g., performance, errors) and does not explain return values beyond the base64 string, leaving room for improvement.

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 schema description coverage is 100%, meaning all parameters are documented in the schema itself. The description does not add any parameter-specific details beyond what the schema provides (e.g., format or constraints for 'prompt' or 'width'). Thus, it meets the baseline of 3 but does not enhance parameter understanding.

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 tool's purpose: 'Generates and returns an image based on the provided prompt.' It specifies both the action (generate and return) and the resource (image). However, with no sibling tools provided, it cannot demonstrate differentiation from alternatives, which prevents a score of 5.

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

Usage Guidelines4/5

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

The description includes explicit guidance: 'Use this tool when you need to generate an image based on a prompt.' This clearly indicates the primary use case. However, it lacks exclusions or alternatives (e.g., when not to use it or other tools for similar tasks), which prevents a score of 5.

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/GMKR/mcp-imagegen'

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