generateImageUrl
Create image URLs by converting text prompts into visuals using specified dimensions and models for consistent results.
Instructions
Generate an image URL from a text prompt
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| options | No | Additional options for image generation | |
| prompt | Yes | The text description of the image to generate |
Implementation Reference
- src/services/imageService.js:58-70 (handler)Main handler function for the generateImageUrl MCP tool. Validates input parameters and delegates to internal helper before returning formatted MCP response.async function generateImageUrl(params) { const { prompt, options = {} } = params; if (!prompt || typeof prompt !== "string") { throw new Error("Prompt is required and must be a string"); } // Generate the image URL and metadata const result = await _generateImageUrlInternal(prompt, options); // Return the response in MCP format return createMCPResponse([createTextContent(result, true)]); }
- src/services/imageService.js:25-44 (helper)Core internal helper that builds the Pollinations image API URL with prompt and options, returns URL and metadata.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/services/imageService.js:165-190 (schema)Zod schema defining input parameters for the generateImageUrl tool: required prompt string and optional options object.{ 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"), },
- src/services/imageService.js:162-192 (registration)Registration array for the generateImageUrl tool within imageTools export, including name, description, schema, and handler reference. Imported and spread into main toolDefinitions for server.tool() registration.[ "generateImageUrl", "Generate an image URL from a text prompt", { 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"), }, generateImageUrl, ],