Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

create_silhouette

Convert images into silhouette effects by processing image sources with customizable color, background, threshold, and output format settings.

Instructions

创建图片的剪影效果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据
silhouette_colorNo剪影颜色,十六进制格式如 #000000(黑色)#000000
background_colorNo背景颜色,十六进制格式或 'transparent'(透明)transparent
thresholdNo阈值,范围 0-255,用于确定剪影边界
output_formatNo输出格式:PNG、JPEG、WEBP 等PNG

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation of the create_silhouette tool. Processes the input image by thresholding alpha channel pixels and filling with silhouette color, handles background, and outputs base64 image.
    async def create_silhouette(arguments: Dict[str, Any]) -> List[TextContent]:
        """
        创建图片的剪影效果
        
        Args:
            arguments: 包含图片源和剪影参数的字典
            
        Returns:
            List[TextContent]: 处理结果
        """
        try:
            # 参数验证
            image_source = arguments.get("image_source")
            ensure_valid_image_source(image_source)
            
            silhouette_color = arguments.get("silhouette_color", "#000000")
            background_color = arguments.get("background_color", "transparent")
            threshold = arguments.get("threshold", 128)
            output_format = arguments.get("output_format", DEFAULT_IMAGE_FORMAT)
            
            # 验证参数
            validate_color_hex(silhouette_color)
            if background_color != "transparent":
                validate_color_hex(background_color)
            validate_numeric_range(threshold, 0, 255, "threshold")
            
            # 加载图片
            processor = ImageProcessor()
            image = processor.load_image(image_source)
            
            # 转换为RGBA模式
            if image.mode != "RGBA":
                image = image.convert("RGBA")
            
            # 创建剪影
            silhouette = Image.new("RGBA", image.size, (0, 0, 0, 0))
            
            # 获取像素数据
            pixels = image.load()
            silhouette_pixels = silhouette.load()
            
            # 解析剪影颜色
            silhouette_rgb = tuple(int(silhouette_color[i:i+2], 16) for i in (1, 3, 5))
            
            for y in range(image.height):
                for x in range(image.width):
                    r, g, b, a = pixels[x, y]
                    
                    # 如果像素不透明度大于阈值,则设为剪影颜色
                    if a > threshold:
                        silhouette_pixels[x, y] = silhouette_rgb + (255,)
                    else:
                        silhouette_pixels[x, y] = (0, 0, 0, 0)
            
            # 处理背景
            if background_color != "transparent":
                background_rgb = tuple(int(background_color[i:i+2], 16) for i in (1, 3, 5))
                final_image = Image.new("RGB", image.size, background_rgb)
                final_image.paste(silhouette, (0, 0), silhouette)
            else:
                final_image = silhouette
            
            # 转换为base64
            output_info = processor.output_image(final_image, "silhouette", output_format)
            
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": True,
                    "message": "成功创建剪影效果",
                    "data": {
                        **output_info,
                        "metadata": {
                            "size": f"{image.width}x{image.height}",
                            "silhouette_color": silhouette_color,
                            "background_color": background_color,
                            "threshold": threshold,
                            "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:517-541 (registration)
    MCP tool registration for create_silhouette using FastMCP's @mcp.tool() decorator. Defines the input schema with pydantic validations and delegates execution to the handler in tools/effects.py.
    @mcp.tool()
    def create_silhouette(
        image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")],
        silhouette_color: Annotated[str, Field(description="剪影颜色,十六进制格式如 #000000(黑色)", default="#000000")],
        background_color: Annotated[str, Field(description="背景颜色,十六进制格式或 'transparent'(透明)", default="transparent")],
        threshold: Annotated[int, Field(description="阈值,范围 0-255,用于确定剪影边界", ge=0, le=255, default=128)],
        output_format: Annotated[str, Field(description="输出格式:PNG、JPEG、WEBP 等", default="PNG")]
    ) -> str:
        """创建图片的剪影效果"""
        try:
            arguments = {
                "image_source": image_source,
                "silhouette_color": silhouette_color,
                "background_color": background_color,
                "threshold": threshold,
                "output_format": output_format
            }
            result = safe_run_async(effects_create_silhouette(arguments))
            return result[0].text
        except Exception as e:
            return json.dumps({
                "success": False,
                "error": f"创建剪影失败: {str(e)}"
            }, ensure_ascii=False, indent=2)
  • JSON schema definition for create_silhouette tool inputs, defined in get_effect_tools() function (though registration uses pydantic fields in main.py).
    Tool(
        name="create_silhouette",
        description="创建图片的剪影效果",
        inputSchema={
            "type": "object",
            "properties": {
                "image_source": {
                    "type": "string",
                    "description": "图片源(文件路径或base64编码)"
                },
                "silhouette_color": {
                    "type": "string",
                    "description": "剪影颜色(十六进制格式)",
                    "default": "#000000"
                },
                "background_color": {
                    "type": "string",
                    "description": "背景颜色(十六进制格式,transparent表示透明)",
                    "default": "transparent"
                },
                "threshold": {
                    "type": "integer",
                    "description": "透明度阈值(0-255)",
                    "minimum": 0,
                    "maximum": 255,
                    "default": 128
                },
                "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?

No annotations are provided, so the description carries full burden. It states what the tool does ('create silhouette effect') but doesn't disclose behavioral traits such as whether it modifies the original image, requires specific file permissions, has performance implications, or what the output contains (though output schema exists). For a mutation tool with zero annotation coverage, this is inadequate.

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 purpose without any wasted words. It's 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.

Completeness4/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 processing with 5 parameters), the description is minimal but complete enough in context. The schema covers parameters fully, and an output schema exists, so the description doesn't need to explain return values. However, for a tool with no annotations, it could benefit from more behavioral context to reach a perfect score.

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 all parameters thoroughly. The description adds no additional meaning beyond the schema, such as explaining how parameters interact or providing usage examples. Baseline 3 is appropriate when the schema does the heavy lifting.

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 '创建图片的剪影效果' (Create silhouette effect for images) clearly states the verb ('create') and resource ('silhouette effect for images'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'apply_contour' or 'apply_edge_enhance' which might also produce edge-based effects, so it doesn't reach the highest 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 many sibling tools for image processing (e.g., 'apply_contour', 'convert_to_grayscale'), there's no indication of when a silhouette effect is preferred over other transformations or what specific use cases it serves.

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