generateImageUrl
Create images from text descriptions using AI, with options to customize model, dimensions, and seed for reproducible results.
Instructions
Generate an image URL from a text prompt
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The text description of the image to generate | |
| options | No | Additional options for image generation |
Implementation Reference
- src/services/imageService.js:58-70 (handler)Main handler function for the 'generateImageUrl' tool. Validates the prompt parameter, calls the internal helper to generate the image URL and metadata, and returns an MCP-formatted 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)Internal helper function that constructs the Pollinations Image API URL using the prompt and options, encodes parameters, and returns the URL with 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 the input parameters for the generateImageUrl tool: required 'prompt' string and optional 'options' object with model, seed, width, height.{ 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 entry in imageTools array: [name, description, schema, handler]. This array is spread into toolDefinitions and registered via server.tool(...tool) in src/index.js.[ "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, ],
- src/index.js:87-88 (registration)Generic registration loop that calls server.tool(name, description, inputSchema, handler) for all tools, including generateImageUrl from imageTools.toolDefinitions.forEach((tool) => server.tool(...tool));