Skip to main content
Glama
tusharpatil2912

Pollinations Multimodal MCP Server

generateImage

Create images from text descriptions using AI models, returning base64-encoded data with customizable dimensions and generation parameters.

Instructions

Generate an image and return the base64-encoded data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe text description of the image to generate
optionsNoAdditional options for image generation

Implementation Reference

  • The primary handler function for the 'generateImage' MCP tool. Validates input parameters, generates an image URL internally, fetches the image, converts it to base64-encoded data, and constructs an MCP response with image content and metadata.
    async function generateImage(params) {
        const { prompt, options = {} } = params;
    
        if (!prompt || typeof prompt !== "string") {
            throw new Error("Prompt is required and must be a string");
        }
    
        // First, generate the image URL (but don't use the MCP response format)
        const urlResult = await _generateImageUrlInternal(prompt, options);
    
        try {
            // Fetch the image from the URL
            const response = await fetch(urlResult.imageUrl);
    
            if (!response.ok) {
                throw new Error(`Failed to generate image: ${response.statusText}`);
            }
    
            // Get the image data as an ArrayBuffer
            const imageBuffer = await response.arrayBuffer();
    
            // Convert the ArrayBuffer to a base64 string
            const base64Data = Buffer.from(imageBuffer).toString("base64");
    
            // Determine the mime type from the response headers or default to image/jpeg
            const contentType =
                response.headers.get("content-type") || "image/jpeg";
    
            const metadata = {
                prompt: urlResult.prompt,
                width: urlResult.width,
                height: urlResult.height,
                model: urlResult.model,
                seed: urlResult.seed,
            };
    
            // Return the response in MCP format
            return createMCPResponse([
                createImageContent(base64Data, contentType),
                createTextContent(
                    `Generated image from prompt: "${prompt}"\n\nImage metadata: ${JSON.stringify(metadata, null, 2)}`,
                ),
            ]);
        } catch (error) {
            console.error("Error generating image:", error);
            throw error;
        }
    }
  • Zod input schema for the 'generateImage' tool defining required 'prompt' string and optional 'options' object with model, seed, width, and height parameters.
    {
        prompt: z
            .string()
            .describe("The text description of the image to generate"),
        options: z
            .object({
                model: z
                    .string()
                    .optional()
                    .describe("Model name to use for generation"),
                seed: z
                    .number()
                    .optional()
                    .describe("Seed for reproducible results"),
                width: z
                    .number()
                    .optional()
                    .describe("Width of the generated image"),
                height: z
                    .number()
                    .optional()
                    .describe("Height of the generated image"),
            })
            .optional()
            .describe("Additional options for image generation"),
    },
  • Tool registration array for 'generateImage' containing name, description, input schema, and handler reference. Exported as part of imageTools for use in the main server.
    [
        "generateImage",
        "Generate an image and return the base64-encoded data",
        {
            prompt: z
                .string()
                .describe("The text description of the image to generate"),
            options: z
                .object({
                    model: z
                        .string()
                        .optional()
                        .describe("Model name to use for generation"),
                    seed: z
                        .number()
                        .optional()
                        .describe("Seed for reproducible results"),
                    width: z
                        .number()
                        .optional()
                        .describe("Width of the generated image"),
                    height: z
                        .number()
                        .optional()
                        .describe("Height of the generated image"),
                })
                .optional()
                .describe("Additional options for image generation"),
        },
        generateImage,
    ],
  • Internal utility function that builds the Pollinations image API URL from prompt and options, used by both generateImage and generateImageUrl handlers.
    async function _generateImageUrlInternal(prompt, options = {}) {
        const { model, seed, width = 1024, height = 1024 } = options;
    
        // Construct the URL with query parameters
        const encodedPrompt = encodeURIComponent(prompt);
        const path = `prompt/${encodedPrompt}`;
        const queryParams = { model, seed, width, height };
    
        const url = buildUrl(IMAGE_API_BASE_URL, path, queryParams);
    
        // Return the URL with metadata
        return {
            imageUrl: url,
            prompt,
            width,
            height,
            model,
            seed,
        };
    }
  • src/index.js:87-87 (registration)
    Final MCP server registration loop that applies all tool definitions, including the 'generateImage' tool from imageTools, using McpServer.tool(name, description, schema, handler).
    toolDefinitions.forEach((tool) => server.tool(...tool));
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool generates an image and returns base64 data, but doesn't mention critical behaviors like whether this is a read-only operation, potential costs or rate limits, error conditions, or what happens if generation fails. For a tool that likely involves external API calls and resource consumption, this is a significant gap.

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 at just 8 words, front-loading the core functionality ('Generate an image') followed by the output specification. Every word earns its place with zero redundancy or unnecessary elaboration. The structure is optimal for quick comprehension.

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 (which typically involves external APIs, potential costs, and quality considerations), the description is insufficient. With no annotations, no output schema, and minimal behavioral context, it doesn't prepare an agent for real-world usage. The description should address authentication needs, rate limits, error handling, or at least reference sibling tools like 'listImageModels' for model selection.

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?

Schema description coverage is 100%, so the schema fully documents both parameters ('prompt' and 'options') and their nested properties. The description doesn't add any parameter semantics beyond what's in the schema - it doesn't explain prompt formatting best practices, default values for options, or valid ranges for dimensions. The baseline score of 3 reflects adequate but minimal value addition.

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 an image') and the output format ('return the base64-encoded data'), making the purpose immediately understandable. It distinguishes from sibling tools like 'generateImageUrl' by specifying base64 encoding rather than a URL. However, it doesn't explicitly differentiate from other generation tools like 'generateText' or 'respondAudio' beyond the resource type.

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. It doesn't mention when to choose 'generateImage' over 'generateImageUrl' (which likely returns a URL instead of base64 data), nor does it specify prerequisites like authentication or model availability. There's no context about appropriate use cases or limitations.

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/tusharpatil2912/pollinations-mcp'

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