Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

load_image

Load image files or base64-encoded images into the Image Processing MCP Server for subsequent editing, transformation, or analysis operations.

Instructions

加载图片文件或base64编码的图片

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYes图片文件路径或base64编码的图片数据。支持本地文件路径(如 'image.jpg')或base64编码字符串

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main execution logic for the load_image tool: validates source, loads image using processor, retrieves info, outputs image reference, and returns JSON response.
    async def load_image(source: str) -> list[TextContent]:
        """
        加载图片
        
        Args:
            source: 图片源(文件路径或base64编码)
            
        Returns:
            包含图片信息和文件引用的响应
        """
        try:
            # 验证图片源
            ensure_valid_image_source(source)
            
            # 加载图片
            image = processor.load_image(source)
            
            # 获取图片信息
            info = processor.get_image_info(image)
            
            # 输出图片(文件引用模式)
            output_info = processor.output_image(image, "loaded")
            
            result = {
                "success": True,
                "message": "图片加载成功",
                "data": {
                    **output_info,
                    "info": info
                }
            }
            
            return [TextContent(type="text", text=json.dumps(result, ensure_ascii=False))]
            
        except ValidationError as e:
            error_result = {
                "success": False,
                "error": f"参数验证失败: {str(e)}"
            }
            return [TextContent(type="text", text=json.dumps(error_result, ensure_ascii=False))]
            
        except Exception as e:
            error_result = {
                "success": False,
                "error": f"图片加载失败: {str(e)}"
            }
            return [TextContent(type="text", text=json.dumps(error_result, ensure_ascii=False))]
  • main.py:107-120 (registration)
    MCP server tool registration using @mcp.tool() decorator. Defines input schema via Annotated Field and delegates execution to basic_load_image handler.
    @mcp.tool()
    def load_image(
        source: Annotated[str, Field(description="图片文件路径或base64编码的图片数据。支持本地文件路径(如 'image.jpg')或base64编码字符串")]
    ) -> str:
        """加载图片文件或base64编码的图片"""
        try:
            result = safe_run_async(basic_load_image(source))
            return result[0].text
        except Exception as e:
            return json.dumps({
                "success": False,
                "error": f"加载图片失败: {str(e)}"
            }, ensure_ascii=False, indent=2)
  • Input schema definition for the load_image tool using Pydantic Annotated and Field for source parameter validation and description.
    source: Annotated[str, Field(description="图片文件路径或base64编码的图片数据。支持本地文件路径(如 'image.jpg')或base64编码字符串")]
  • Core utility function in ImageProcessor class that loads image from file path or base64 string into PIL Image object, with size validation.
    def load_image(self, source: Union[str, bytes]) -> Image.Image:
        """
        加载图片,支持文件路径、base64编码
        
        Args:
            source: 图片源,可以是文件路径或base64编码字符串
            
        Returns:
            PIL Image对象
            
        Raises:
            ValueError: 当图片源无效时
            IOError: 当图片无法加载时
        """
        try:
            if isinstance(source, str):
                if source.startswith('data:image'):
                    # base64编码的图片
                    header, data = source.split(',', 1)
                    image_data = base64.b64decode(data)
                    image = Image.open(io.BytesIO(image_data))
                else:
                    # 文件路径
                    if not os.path.exists(source):
                        raise ValueError(f"图片文件不存在: {source}")
                    image = Image.open(source)
            elif isinstance(source, bytes):
                image = Image.open(io.BytesIO(source))
            else:
                raise ValueError("不支持的图片源类型")
            
            # 检查图片尺寸
            if image.size[0] > self.max_image_size[0] or image.size[1] > self.max_image_size[1]:
                raise ValueError(f"图片尺寸过大,最大支持: {self.max_image_size}")
            
            return image
            
        except Exception as e:
            raise IOError(f"图片加载失败: {str(e)}")
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 what the tool does (loads images) but doesn't describe behavioral traits such as error handling (e.g., invalid paths/formats), performance implications, memory usage, or output format. For a tool that likely serves as an entry point for image processing, this is a significant gap.

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 in Chinese that directly states the tool's function without any fluff or redundant information. It's appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one parameter) and the presence of an output schema (which likely describes the loaded image data), the description is minimally adequate. However, it lacks context on integration with sibling tools (e.g., that this loads images for subsequent processing) and behavioral details, leaving gaps in completeness for a foundational tool in this server.

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 schema description coverage is 100%, with the parameter 'source' well-documented in the schema itself (describing it as a file path or base64 string). The description adds no additional semantic meaning beyond what's in the schema, so it meets the baseline of 3 for high schema coverage without compensating value.

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 'load') and the resource ('图片文件或base64编码的图片' meaning 'image file or base64-encoded image'), making the purpose immediately understandable. It distinguishes from siblings by focusing on loading/input rather than processing or output operations, though it doesn't explicitly name alternatives.

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. It doesn't mention prerequisites (e.g., that this should be used before applying other image processing tools), exclusions, or contextual cues for selection among siblings like 'get_image_info' or 'save_image'.

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/duke0317/ps-mcp'

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