Skip to main content
Glama

generateText

Generate customizable text responses from prompts using the Pollinations Text API. Specify models, set system behaviors, and receive outputs in JSON format for integration needs.

Instructions

Generate text from a prompt using the Pollinations Text API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelNoModel to use for text generation (default: "openai")
optionsNoAdditional options for text generation
promptYesThe text prompt to generate a response for

Implementation Reference

  • The main handler function that implements the generateText tool by calling the Pollinations Text API, processing parameters, constructing the request URL, fetching the response, and formatting it as MCP response.
    async function generateText(params) { const { prompt, model = "openai", options = {} } = params; if (!prompt || typeof prompt !== "string") { throw new Error("Prompt is required and must be a string"); } const { seed, systemPrompt, json, isPrivate } = options; // Prepare query parameters const queryParams = { model, seed, ...(systemPrompt && { system: encodeURIComponent(systemPrompt) }), ...(json && { json: "true" }), ...(isPrivate && { private: "true" }), }; // Construct the URL const encodedPrompt = encodeURIComponent(prompt); const url = buildUrl(TEXT_API_BASE_URL, encodedPrompt, queryParams); try { // Fetch the text from the URL const response = await fetch(url); if (!response.ok) { throw new Error(`Failed to generate text: ${response.statusText}`); } // Get the text response const textResponse = await response.text(); // Return the response in MCP format return createMCPResponse([createTextContent(textResponse)]); } catch (error) { console.error("Error generating text:", error); throw error; } }
  • Zod schema defining the input parameters for the generateText tool, including prompt, optional model, and options object with seed, systemPrompt, json, and isPrivate.
    { prompt: z .string() .describe("The text prompt to generate a response for"), model: z .string() .optional() .describe( 'Model to use for text generation (default: "openai")', ), options: z .object({ seed: z .number() .optional() .describe("Seed for reproducible results"), systemPrompt: z .string() .optional() .describe( "Optional system prompt to set the behavior of the AI", ), json: z .boolean() .optional() .describe( "Set to true to receive response in JSON format", ), isPrivate: z .boolean() .optional() .describe( "Set to true to prevent the response from appearing in the public feed", ), }) .optional() .describe("Additional options for text generation"), },
  • Tool definition array registering the generateText tool with name, description, schema, and handler reference as part of the textTools export.
    [ "generateText", "Generate text from a prompt using the Pollinations Text API", { prompt: z .string() .describe("The text prompt to generate a response for"), model: z .string() .optional() .describe( 'Model to use for text generation (default: "openai")', ), options: z .object({ seed: z .number() .optional() .describe("Seed for reproducible results"), systemPrompt: z .string() .optional() .describe( "Optional system prompt to set the behavior of the AI", ), json: z .boolean() .optional() .describe( "Set to true to receive response in JSON format", ), isPrivate: z .boolean() .optional() .describe( "Set to true to prevent the response from appearing in the public feed", ), }) .optional() .describe("Additional options for text generation"), }, generateText, ],
  • src/index.js:87-87 (registration)
    Registers all tools from toolDefinitions (including generateText via textTools) to the MCP server using server.tool().
    toolDefinitions.forEach((tool) => server.tool(...tool));

Other Tools

Related 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