Skip to main content
Glama
bendusy

Pollinations MCP Server

by bendusy

generate_text

Generate AI text content using Pollinations.ai models. Provide a prompt to create text responses, customize with model selection, system instructions, and output formatting options.

Instructions

使用Pollinations.ai生成文本

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes文本提示词
modelNo要使用的模型(如openai、mistral等)openai
seedNo随机种子值(用于生成一致的结果)
systemNo系统提示词(设置AI行为)
jsonNo是否返回JSON格式的响应
privateNo设置为true可使响应私有

Implementation Reference

  • The primary handler function for the 'generate_text' tool. Validates input arguments, calls the PollinationsTextAPI to generate text, formats the response, and handles errors appropriately.
    private async handleGenerateText(args: any) {
      try {
        if (!this.isValidGenerateTextArgs(args)) {
          throw this.handleValidationError('无效的文本生成参数');
        }
    
        const { prompt, model = 'openai', seed, system, json = false, private: isPrivate = false } = args;
    
        const result = await this.textAPI.generateTextGet(prompt, {
          model,
          seed,
          json,
          system,
          private: isPrivate
        });
    
        return {
          content: [
            {
              type: 'text',
              text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        // 处理所有错误
        let pollinationsError: PollinationsError;
        
        if (error instanceof PollinationsError) {
          pollinationsError = error;
        } else {
          pollinationsError = this.handleApiError(error);
        }
        
        return {
          content: [
            {
              type: 'text',
              text: pollinationsError.toUserFriendlyMessage(),
            },
          ],
          isError: true,
        };
      }
    }
  • Type guard function that validates the input arguments for the generate_text tool, ensuring correct types for prompt, model, seed, system, json, and private parameters.
    private isValidGenerateTextArgs(args: any): args is {
      prompt: string;
      model?: string;
      seed?: number;
      system?: string;
      json?: boolean;
      private?: boolean;
    } {
      return (
        typeof args === 'object' &&
        args !== null &&
        typeof args.prompt === 'string' &&
        (args.model === undefined || typeof args.model === 'string') &&
        (args.seed === undefined || typeof args.seed === 'number') &&
        (args.system === undefined || typeof args.system === 'string') &&
        (args.json === undefined || typeof args.json === 'boolean') &&
        (args.private === undefined || typeof args.private === 'boolean')
      );
    }
  • src/index.ts:227-263 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the name, description, and input schema for the 'generate_text' tool.
    {
      name: 'generate_text',
      description: '使用Pollinations.ai生成文本',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: {
            type: 'string',
            description: '文本提示词',
          },
          model: {
            type: 'string',
            description: '要使用的模型(如openai、mistral等)',
            default: 'openai',
          },
          seed: {
            type: 'number',
            description: '随机种子值(用于生成一致的结果)',
          },
          system: {
            type: 'string',
            description: '系统提示词(设置AI行为)',
          },
          json: {
            type: 'boolean',
            description: '是否返回JSON格式的响应',
            default: false,
          },
          private: {
            type: 'boolean',
            description: '设置为true可使响应私有',
            default: false,
          },
        },
        required: ['prompt'],
      },
    },
  • Helper method in PollinationsTextAPI class that constructs the API URL and makes the HTTP GET request to Pollinations.ai text generation endpoint.
    async generateTextGet(prompt: string, options: {
      model?: string;
      seed?: number;
      json?: boolean;
      system?: string;
      private?: boolean;
    } = {}) {
      const { model = 'openai', seed, json = false, system, private: isPrivate = false } = options;
      
      let url = `${this.baseTextUrl}/${encodeURIComponent(prompt)}?model=${model}`;
      
      if (seed !== undefined) {
        url += `&seed=${seed}`;
      }
      
      if (json) {
        url += `&json=true`;
      }
      
      if (system) {
        url += `&system=${encodeURIComponent(system)}`;
      }
      
      if (isPrivate) {
        url += `&private=true`;
      }
      
      try {
        const response = await axios.get(url);
        return response.data;
      } catch (error) {
        throw new Error(`文本生成失败: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/index.ts:274-275 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes 'generate_text' calls to the handleGenerateText method.
    case 'generate_text':
      return this.handleGenerateText(request.params.arguments);
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/bendusy/pollinations-mcp'

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