Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

add_border

Add customizable borders to images with options for width, color, style, and corner radius to enhance visual presentation.

Instructions

为图片添加边框效果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据
border_widthNo边框宽度(像素)
border_colorNo边框颜色,十六进制格式如 #000000(黑色)#000000
border_styleNo边框样式:solid(实线)、dashed(虚线)、dotted(点线)solid
corner_radiusNo圆角半径(像素),0为直角
output_formatNo输出格式:PNG、JPEG、WEBP 等PNG

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core asynchronous handler function that implements the add_border tool logic. Loads image, validates parameters, creates bordered image with solid, rounded, or shadow styles using PIL, and returns base64 encoded result.
    async def add_border(arguments: Dict[str, Any]) -> List[TextContent]:
        """
        为图片添加边框效果
        
        Args:
            arguments: 包含图片源和边框参数的字典
            
        Returns:
            List[TextContent]: 处理结果
        """
        try:
            # 参数验证
            image_source = arguments.get("image_source")
            ensure_valid_image_source(image_source)
            
            border_width = arguments.get("border_width", 10)
            border_color = arguments.get("border_color", "#000000")
            border_style = arguments.get("border_style", "solid")
            corner_radius = arguments.get("corner_radius", 10)
            output_format = arguments.get("output_format", DEFAULT_IMAGE_FORMAT)
            
            # 验证参数
            validate_numeric_range(border_width, 1, 100, "border_width")
            validate_color_hex(border_color)
            validate_numeric_range(corner_radius, 0, 50, "corner_radius")
            
            # 加载图片
            processor = ImageProcessor()
            image = processor.load_image(image_source)
            
            # 创建带边框的新图片
            new_width = image.width + 2 * border_width
            new_height = image.height + 2 * border_width
            
            if border_style == "rounded":
                # 圆角边框
                bordered_image = Image.new("RGBA", (new_width, new_height), border_color)
                
                # 创建圆角遮罩
                mask = Image.new("L", (new_width, new_height), 0)
                draw = ImageDraw.Draw(mask)
                draw.rounded_rectangle(
                    [0, 0, new_width, new_height],
                    radius=corner_radius,
                    fill=255
                )
                
                # 应用遮罩
                bordered_image.putalpha(mask)
                
                # 粘贴原图片
                if image.mode != "RGBA":
                    image = image.convert("RGBA")
                bordered_image.paste(image, (border_width, border_width), image)
                
            elif border_style == "shadow":
                # 阴影边框
                bordered_image = Image.new("RGBA", (new_width + 10, new_height + 10), (0, 0, 0, 0))
                
                # 创建阴影
                shadow = Image.new("RGBA", (new_width, new_height), border_color + "80")
                shadow = shadow.filter(ImageFilter.GaussianBlur(radius=5))
                bordered_image.paste(shadow, (10, 10), shadow)
                
                # 粘贴原图片
                if image.mode != "RGBA":
                    image = image.convert("RGBA")
                bordered_image.paste(image, (border_width, border_width), image)
                
            else:
                # 实心边框
                bordered_image = Image.new("RGB", (new_width, new_height), border_color)
                bordered_image.paste(image, (border_width, border_width))
            
            # 转换为base64
            output_info = processor.output_image(bordered_image, "border", output_format)
            
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": True,
                    "message": f"成功添加{border_style}边框效果",
                    "data": {
                        **output_info,
                        "metadata": {
                            "original_size": f"{image.width}x{image.height}",
                            "new_size": f"{bordered_image.width}x{bordered_image.height}",
                            "border_width": border_width,
                            "border_color": border_color,
                            "border_style": border_style,
                            "format": output_format
                        }
                    }
                }, ensure_ascii=False)
            )]
            
        except ValidationError as e:
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": False,
                    "error": f"参数验证失败: {str(e)}"
                }, ensure_ascii=False)
            )]
        except Exception as e:
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": False,
                    "error": f"添加边框失败: {str(e)}"
                }, ensure_ascii=False)
            )]
  • main.py:490-516 (registration)
    Registers the 'add_border' tool with the FastMCP server using @mcp.tool() decorator. Defines input schema through Annotated parameters and wraps the async handler from effects.py with safe_run_async.
    @mcp.tool()
    def add_border(
        image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")],
        border_width: Annotated[int, Field(description="边框宽度(像素)", ge=1, default=10)],
        border_color: Annotated[str, Field(description="边框颜色,十六进制格式如 #000000(黑色)", default="#000000")],
        border_style: Annotated[str, Field(description="边框样式:solid(实线)、dashed(虚线)、dotted(点线)", default="solid")],
        corner_radius: Annotated[int, Field(description="圆角半径(像素),0为直角", ge=0, default=10)],
        output_format: Annotated[str, Field(description="输出格式:PNG、JPEG、WEBP 等", default="PNG")]
    ) -> str:
        """为图片添加边框效果"""
        try:
            arguments = {
                "image_source": image_source,
                "border_width": border_width,
                "border_color": border_color,
                "border_style": border_style,
                "corner_radius": corner_radius,
                "output_format": output_format
            }
            result = safe_run_async(effects_add_border(arguments))
            return result[0].text
        except Exception as e:
            return json.dumps({
                "success": False,
                "error": f"添加边框失败: {str(e)}"
            }, ensure_ascii=False, indent=2)
  • Detailed JSON schema definition for the add_border tool input parameters, defined within get_effect_tools() function, though not directly used in registration.
    Tool(
        name="add_border",
        description="为图片添加边框效果",
        inputSchema={
            "type": "object",
            "properties": {
                "image_source": {
                    "type": "string",
                    "description": "图片源(文件路径或base64编码)"
                },
                "border_width": {
                    "type": "integer",
                    "description": "边框宽度(像素)",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 10
                },
                "border_color": {
                    "type": "string",
                    "description": "边框颜色(十六进制格式,如#FF0000)",
                    "default": "#000000"
                },
                "border_style": {
                    "type": "string",
                    "description": "边框样式",
                    "enum": ["solid", "rounded", "shadow"],
                    "default": "solid"
                },
                "corner_radius": {
                    "type": "integer",
                    "description": "圆角半径(仅当border_style为rounded时有效)",
                    "minimum": 0,
                    "maximum": 50,
                    "default": 10
                },
                "output_format": {
                    "type": "string",
                    "description": "输出格式",
                    "enum": ["PNG", "JPEG", "WEBP"],
                    "default": "PNG"
                }
            },
            "required": ["image_source"]
        }
    ),
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While '添加边框效果' implies a transformation operation, it doesn't specify whether this is destructive to the original image, what permissions might be needed, performance characteristics, or error conditions. The description provides minimal behavioral context beyond the basic operation.

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 at just 7 Chinese characters ('为图片添加边框效果'), which directly states the tool's purpose without any wasted words. It's appropriately sized for a straightforward image processing operation and front-loads the core functionality.

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 moderate complexity (6 parameters, image transformation) and the presence of both comprehensive input schema (100% coverage) and output schema, the description is minimally adequate. However, for a mutation tool with no annotations, it should provide more context about behavioral implications and usage scenarios to be truly complete.

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 with detailed descriptions for all 6 parameters. The baseline score of 3 reflects adequate schema documentation, but the description doesn't provide additional context about parameter interactions, constraints, or usage patterns.

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 as adding border effects to images, which is a specific verb+resource combination. However, it doesn't explicitly differentiate this tool from its many image processing siblings like 'add_shadow' or 'add_watermark', which prevents a perfect score.

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. With numerous sibling tools for image effects (add_shadow, apply_vignette, etc.), there's no indication of when border addition is appropriate versus other visual enhancements, nor any prerequisites or exclusions mentioned.

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