Skip to main content
Glama
sanliunanjue

Image Processor MCP Server

by sanliunanjue

process_image_to_description

Generate text descriptions from images by analyzing visual content and specifying detail level or focus areas to extract meaningful information.

Instructions

处理图像并生成描述

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlYes图像URL
detail_levelNo描述详细程度:简洁(brief)、标准(standard)或详细(detailed)standard
focusNo描述重点,例如:物体、场景、人物、情感等

Implementation Reference

  • The main handler for the 'process_image_to_description' tool. It extracts image_url, detail_level, and focus parameters, downloads the image, constructs a descriptive prompt based on parameters, calls the processImageWithQwen helper to get the AI description, and returns the result as text content or error.
    case "process_image_to_description": {
      const imageUrl = String(request.params.arguments?.image_url);
      const detailLevel = String(request.params.arguments?.detail_level || "standard");
      const focus = String(request.params.arguments?.focus || "");
      
      if (!imageUrl) {
        throw new Error("图像URL是必需的");
      }
      
      try {
        // 下载图像
        const imagePath = await downloadImage(imageUrl);
        
        // 构建提示词
        let prompt = "请描述这张图片";
        if (detailLevel === "brief") {
          prompt += ",给出简洁的描述";
        } else if (detailLevel === "detailed") {
          prompt += ",提供详细的描述,包括细节、背景和上下文";
        }
        
        if (focus) {
          prompt += `,重点关注${focus}`;
        }
        
        // 处理图像
        const result = await processImageWithQwen(imagePath, prompt);
        
        return {
          content: [{
            type: "text",
            text: result
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `处理图像失败: ${error.message}`
          }],
          isError: true
        };
      }
    }
  • Input schema definition for the tool, specifying parameters: image_url (required), detail_level (enum with default), focus (optional). Defines validation for tool arguments.
    inputSchema: {
      type: "object",
      properties: {
        image_url: {
          type: "string",
          description: "图像URL"
        },
        detail_level: {
          type: "string",
          description: "描述详细程度:简洁(brief)、标准(standard)或详细(detailed)",
          enum: ["brief", "standard", "detailed"],
          default: "standard"
        },
        focus: {
          type: "string",
          description: "描述重点,例如:物体、场景、人物、情感等",
          default: ""
        }
      },
      required: ["image_url"]
    }
  • src/index.ts:178-202 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining name, description, and input schema for discovery by MCP clients.
    {
      name: "process_image_to_description",
      description: "处理图像并生成描述",
      inputSchema: {
        type: "object",
        properties: {
          image_url: {
            type: "string",
            description: "图像URL"
          },
          detail_level: {
            type: "string",
            description: "描述详细程度:简洁(brief)、标准(standard)或详细(detailed)",
            enum: ["brief", "standard", "detailed"],
            default: "standard"
          },
          focus: {
            type: "string",
            description: "描述重点,例如:物体、场景、人物、情感等",
            default: ""
          }
        },
        required: ["image_url"]
      }
    }
  • Core helper function that calls the Qwen VL API: reads image to base64, sends prompt + image to API, extracts text response, cleans up temp file. Used by both image processing tools.
    async function processImageWithQwen(imagePath: string, prompt: string): Promise<string> {
      try {
        // 读取图像文件
        const imageBuffer = fs.readFileSync(imagePath);
        const base64Image = imageBuffer.toString('base64');
        
        // 准备请求数据
        const requestData = {
          model: "qwen-vl-plus",
          input: {
            messages: [
              {
                role: "user",
                content: [
                  {
                    type: "text",
                    text: prompt
                  },
                  {
                    type: "image",
                    image: base64Image
                  }
                ]
              }
            ]
          },
          parameters: {}
        };
        
        // 发送请求到API
        const response = await axios.post(API_ENDPOINT, requestData, {
          headers: {
            'Authorization': `Bearer ${API_KEY}`,
            'Content-Type': 'application/json'
          }
        });
        
        // 处理响应
        if (response.data && response.data.output && response.data.output.text) {
          return response.data.output.text;
        } else {
          throw new Error("API响应格式不正确");
        }
      } catch (error: any) {
        console.error("调用qwen2.5-vl模型API失败:", error);
        if (error.response) {
          console.error("API响应:", error.response.data);
        }
        throw new Error(`处理图像失败: ${error.message}`);
      } finally {
        // 清理临时文件
        try {
          fs.unlinkSync(imagePath);
        } catch (e) {
          console.error("清理临时文件失败:", e);
        }
      }
    }
  • Helper to download image from URL to temp file using stream, generates unique filename, returns path. Used in tool handlers.
    async function downloadImage(imageUrl: string): Promise<string> {
      try {
        // 为图像生成唯一文件名
        const filename = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}.jpg`;
        const filePath = path.join(TEMP_DIR, filename);
        
        // 下载图像
        const response = await axios({
          method: 'GET',
          url: imageUrl,
          responseType: 'stream'
        });
        
        await streamPipeline(response.data, fs.createWriteStream(filePath));
        return filePath;
      } catch (error: any) {
        console.error("下载图像失败:", error);
        throw new Error(`下载图像失败: ${error.message}`);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool processes images and generates descriptions, but doesn't reveal important behavioral aspects like whether this is a read-only operation, what permissions might be required, potential rate limits, error conditions, or what format the description output takes. For a tool with no annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 extremely concise - a single Chinese sentence that directly states the tool's function. There's no wasted language or unnecessary elaboration. It's front-loaded with the core purpose and doesn't include any extraneous information.

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?

For a tool with 3 parameters, no annotations, and no output schema, the description is insufficiently complete. While concise, it doesn't address the behavioral aspects needed when annotations are absent, doesn't explain the relationship between parameters, and provides no information about the output format or structure. The description should do more to compensate for the lack of structured metadata.

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?

The description adds no parameter information beyond what's already in the schema, which has 100% coverage. All three parameters (image_url, detail_level, focus) are fully documented in the schema with descriptions, enums, defaults, and requirements. The description doesn't provide additional context about parameter usage, relationships, or examples, so it meets the baseline for high schema coverage.

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 tool's purpose: '处理图像并生成描述' (process image and generate description). It specifies both the action (process) and resource (image) with a clear output (description). However, it doesn't explicitly differentiate from its sibling tool 'process_image_to_code', which processes images but generates code instead of descriptions.

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. There's no mention of the sibling tool 'process_image_to_code' or any other context for choosing between image processing tools. The description simply states what the tool does without indicating appropriate use cases or exclusions.

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/sanliunanjue/image-processor-mcp'

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