Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

flip_image

Flip images horizontally or vertically to correct orientation, create mirror effects, or adjust visual layouts for various applications.

Instructions

翻转图片

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据
directionYes翻转方向:horizontal(水平翻转)或 vertical(垂直翻转)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler function that performs the actual image flipping using PIL.Image.transpose based on direction (horizontal or vertical). Loads image, applies flip, outputs result via ImageProcessor, returns JSON response.
    async def flip_image(image_data: str, direction: str) -> list[TextContent]:
        """
        翻转图片
        
        Args:
            image_data: 图片数据(base64编码)
            direction: 翻转方向(horizontal, vertical)
            
        Returns:
            翻转后的图片数据
        """
        try:
            # 验证参数
            if not image_data:
                raise ValidationError("图片数据不能为空")
            
            if direction not in ['horizontal', 'vertical']:
                raise ValidationError(f"无效的翻转方向: {direction}")
            
            # 加载图片
            image = processor.load_image(image_data)
            
            # 翻转图片
            if direction == 'horizontal':
                flipped_image = image.transpose(Image.FLIP_LEFT_RIGHT)
                direction_desc = "水平翻转"
            else:  # vertical
                flipped_image = image.transpose(Image.FLIP_TOP_BOTTOM)
                direction_desc = "垂直翻转"
            
            # 输出翻转后的图片
            output_info = processor.output_image(flipped_image, f"flip_{direction}")
            
            result = {
                "success": True,
                "message": f"图片{direction_desc}成功",
                "data": {
                    **output_info,
                    "direction": direction,
                    "size": image.size
                }
            }
            
            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:223-236 (registration)
    MCP tool registration using @mcp.tool() decorator. This wrapper function handles the tool call, delegates to the core transform_flip_image handler, and formats the response as string.
    @mcp.tool()
    def flip_image(
        image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")],
        direction: Annotated[str, Field(description="翻转方向:horizontal(水平翻转)或 vertical(垂直翻转)")]
    ) -> str:
        """翻转图片"""
        try:
            result = safe_run_async(transform_flip_image(image_source, direction))
            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 flip_image tool, specifying parameters image_data (base64 string) and direction (enum: horizontal, vertical). Part of get_transform_tools().
    Tool(
        name="flip_image",
        description="翻转图片",
        inputSchema={
            "type": "object",
            "properties": {
                "image_data": {
                    "type": "string",
                    "description": "图片数据(base64编码)"
                },
                "direction": {
                    "type": "string",
                    "description": "翻转方向(horizontal, vertical)",
                    "enum": ["horizontal", "vertical"]
                }
            },
            "required": ["image_data", "direction"]
        }
    )
Behavior1/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 but fails to add any context. It doesn't describe what the tool does beyond the basic action (e.g., whether it modifies the original image, creates a new file, handles errors, or has performance implications). For a mutation tool with zero annotation coverage, 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.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is overly concise to the point of under-specification—it's a single phrase with no structure or elaboration. While brief, it fails to convey essential information, making it inefficient rather than appropriately concise. Every sentence should earn its place, but here the lack of content is a drawback.

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 tool's complexity (image transformation with two parameters) and the presence of an output schema (which reduces the need to explain return values), the description is incomplete. It lacks behavioral context, usage guidelines, and differentiation from siblings, making it inadequate for effective tool selection and invocation despite the structured data.

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 clear documentation for both parameters ('image_source' and 'direction'), including allowed values for direction. The description adds no parameter semantics beyond what the schema provides, so it meets the baseline of 3 where the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '翻转图片' (flip image) is a tautology that merely restates the tool name in Chinese without adding any meaningful clarification. While it indicates the tool performs image flipping, it doesn't specify what resource it operates on (e.g., an image file or data) or differentiate it from similar sibling tools like 'rotate_image' or other transformation tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/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 sibling tools like 'rotate_image' for different transformations or clarify specific scenarios for flipping (e.g., mirroring effects). There's no indication of prerequisites, exclusions, or contextual usage.

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