Skip to main content
Glama
bendusy

Pollinations MCP Server

by bendusy

download_image

Download AI-generated images from Pollinations.ai to your local device by providing the image URL and specifying the save location.

Instructions

下载Pollinations.ai生成的图像到本地文件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes要下载的图像URL
output_pathNo保存图像的路径(包括文件名)image.jpg

Implementation Reference

  • The main handler function for the 'download_image' tool. Downloads image from provided URL using axios, ensures output directory exists, writes to file, verifies success, and returns JSON response with file info or error.
    private async handleDownloadImage(args: any) {
      try {
        if (!this.isValidDownloadImageArgs(args)) {
          throw this.handleValidationError('无效的图像下载参数');
        }
    
        // 获取参数
        let { url, output_path = 'image.jpg' } = args;
        
        // 使用相对路径保存图像到当前工作目录
        output_path = path.resolve(process.cwd(), output_path);
        console.error(`图像将保存到: ${output_path}`);
    
        try {
          // 确保输出目录存在
          const dirname = path.dirname(output_path);
          if (!fs.existsSync(dirname)) {
            console.error(`创建目录: ${dirname}`);
            fs.mkdirSync(dirname, { recursive: true });
          }
        } catch (fsError) {
          throw this.handleFileSystemError(fsError, '创建目录');
        }
    
        // 下载图像
        console.error(`开始下载图像: ${url}`);
        let response;
        try {
          response = await axios.get(url, { responseType: 'arraybuffer' });
        } catch (downloadError) {
          throw this.handleApiError(downloadError);
        }
        
        // 写入文件
        try {
          console.error(`写入文件: ${output_path}`);
          fs.writeFileSync(output_path, Buffer.from(response.data, 'binary'));
        } catch (writeError) {
          throw this.handleFileSystemError(writeError, '写入文件');
        }
        
        // 验证文件是否写入成功
        try {
          if (fs.existsSync(output_path)) {
            const fileSize = fs.statSync(output_path).size;
            console.error(`文件成功写入: ${output_path}, 大小: ${fileSize} 字节`);
            
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify({
                    success: true,
                    message: `图像已下载到 ${output_path}`,
                    size: fileSize,
                    path: output_path
                  }, null, 2),
                },
              ],
            };
          } else {
            throw new PollinationsError(
              `文件写入失败: ${output_path}`,
              PollinationsErrorType.FILE_SYSTEM_ERROR
            );
          }
        } catch (verifyError) {
          if (verifyError instanceof PollinationsError) {
            throw verifyError;
          } else {
            throw this.handleFileSystemError(verifyError, '验证文件');
          }
        }
      } 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 download_image tool, ensuring 'url' is string and 'output_path' is optional string.
    private isValidDownloadImageArgs(args: any): args is {
      url: string;
      output_path?: string;
    } {
      return (
        typeof args === 'object' &&
        args !== null &&
        typeof args.url === 'string' &&
        (args.output_path === undefined || typeof args.output_path === 'string')
      );
    }
  • src/index.ts:208-226 (registration)
    Tool registration in the ListTools response, including name, description, and input schema definition.
    {
      name: 'download_image',
      description: '下载Pollinations.ai生成的图像到本地文件',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: '要下载的图像URL',
          },
          output_path: {
            type: 'string',
            description: '保存图像的路径(包括文件名)',
            default: 'image.jpg',
          },
        },
        required: ['url'],
      },
    },
  • src/index.ts:272-273 (registration)
    Dispatcher switch case that routes 'download_image' tool calls to the handleDownloadImage method.
    case 'download_image':
      return this.handleDownloadImage(request.params.arguments);
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool downloads images to a local file, implying a write operation, but doesn't disclose behavioral traits like file system permissions, overwrite behavior, error handling, or network dependencies. This is a significant gap for a tool that modifies the local environment.

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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to understand at a glance.

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 a download operation with no annotations and no output schema, the description is incomplete. It lacks details on what happens after download (e.g., success/failure responses, file validation), behavioral risks, and integration with sibling tools, leaving gaps for an AI agent to use it correctly.

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 already documents both parameters ('url' and 'output_path') with clear descriptions. The description adds no additional meaning beyond what the schema provides, such as URL format constraints or path validation rules, resulting in the baseline score of 3.

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 ('下载' meaning 'download') and the resource ('Pollinations.ai生成的图像' meaning 'images generated by Pollinations.ai'), specifying both the source and destination. However, it doesn't explicitly differentiate from sibling tools like 'generate_image' or 'generate_text', which would require a 5.

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 like 'generate_image' (which likely creates images) or 'generate_text'. It mentions downloading generated images but doesn't specify prerequisites, such as needing a URL from a previous generation step.

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

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