Skip to main content
Glama
luoshui-coder

Image Generator MCP Server

generate_image

Create custom images from text prompts using AI, specifying content and filename for generated visuals.

Instructions

Generate an image from a prompt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesA prompt detailing what image to generate.
imageNameYesThe filename for the image excluding any extensions.

Implementation Reference

  • Handler for CallToolRequestSchema specifically for the 'generate_image' tool. Validates the tool name and arguments, generates the image using ImageGenerator, saves the file using FileSaver, and returns the file URI as tool result.
    this.server.setRequestHandler(
      CallToolRequestSchema,
      async (request) => {
        if (request.params.name !== "generate_image") {
          throw new McpError(
            ErrorCode.MethodNotFound,
            `Unknown tool: ${request.params.name}`
          );
        }
    
        if (!isValidImageGenerationArgs(request.params.arguments)) {
          throw new McpError(
            ErrorCode.InvalidParams,
            "Invalid image generation arguments"
          )
        };
        
        const { prompt, imageName } = request.params.arguments;
        const base64 = await new ImageGenerator().generateImage(prompt);
        const fileName = `${imageName.replace(/\..*$/, '')}.png`;
        const filepath = await imageSaver.saveBase64(fileName, base64!);
    
        return {
          toolResult: {
            uri: `file://${filepath}`,
            type: 'image',
            mimeType: 'image/png'
          }
        }
      }
    )
  • Type definition for image generation parameters and validation function used in the handler to check input arguments.
    export interface ImageGenerationRequestParams {
        prompt: string;
        imageName: string;
    }
    
    export function isValidImageGenerationArgs(args: any): args is ImageGenerationRequestParams {
        return typeof args === "object" &&
            args !== null &&
            "prompt" in args &&
            typeof args.prompt === 'string' &&
            "imageName" in args &&
            typeof args.imageName === 'string';  
    }
  • src/index.ts:53-71 (registration)
    Registers the 'generate_image' tool in the ListToolsRequestHandler with description and input schema.
      tools: [{
        name: "generate_image",
        description: "Generate an image from a prompt.",
        inputSchema: {
          type: "object",
          properties: {
            prompt: {
              type: "string",
              description: "A prompt detailing what image to generate."
            },
            imageName: {
              type: "string",
              description: "The filename for the image excluding any extensions."
            }
          },
          required: ["prompt", "imageName"]
        }
      }]
    })
  • Core image generation logic using OpenAI's DALL-E 3 model to generate base64 image from prompt.
    async generateImage(prompt: string, size: ImageGenerateParams['size'] = "1024x1024") {
        const response = await this.openai.images.generate({
            model: IMAGE_MODEL,
            prompt,
            size,
            response_format: 'b64_json'
        });
        return response.data[0].b64_json;
    }
Behavior1/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 of behavioral disclosure. However, it only states the basic action ('Generate an image') without mentioning any behavioral traits such as permissions required, rate limits, output format, error conditions, or whether the operation is idempotent. This is inadequate for a tool that likely involves external resources or processing.

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 extremely concise—a single sentence that directly states the tool's purpose without any unnecessary words. It is front-loaded and wastes no space, making it easy for an agent to parse quickly. This efficiency is commendable for such a straightforward tool.

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 lack of annotations and output schema, the description is incomplete. It does not explain what the tool returns (e.g., image data, URL, error messages), nor does it cover behavioral aspects like authentication or limitations. For a tool with no structured metadata, the description should provide more context to guide the agent effectively.

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%, with clear descriptions for both parameters ('prompt' and 'imageName'). The description does not add any additional meaning beyond what the schema provides, such as examples or constraints. Given the high schema coverage, the baseline score of 3 is appropriate, as the schema adequately documents the parameters.

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: 'Generate an image from a prompt.' It specifies the verb ('Generate') and resource ('image'), making it easy to understand what the tool does. However, since there are no sibling tools mentioned, it cannot demonstrate differentiation from alternatives, which prevents a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or contextual constraints. It simply states what the tool does without any usage instructions, leaving the agent to infer appropriate scenarios based on the tool name and parameters alone.

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/luoshui-coder/image-generator-mcp-server'

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