Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

blend_images

Combine two images using blend modes like normal, multiply, screen, or overlay with adjustable opacity to create composite visuals.

Instructions

混合两张图片

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image1_sourceYes第一张图片源,可以是文件路径或base64编码的图片数据
image2_sourceYes第二张图片源,可以是文件路径或base64编码的图片数据
blend_modeNo混合模式:normal(正常)、multiply(正片叠底)、screen(滤色)、overlay(叠加)normal
opacityNo第二张图片的不透明度,范围 0.0-1.0
output_formatNo输出格式:PNG、JPEG、WEBP 等PNG

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler implementing image blending: loads two images, resizes them according to mode, applies opacity to second image, uses blend modes (normal, multiply, etc.), and outputs base64 result.
    async def blend_images(arguments: Dict[str, Any]) -> List[TextContent]:
        """
        混合两张图片
        
        Args:
            arguments: 包含两张图片源和混合参数的字典
            
        Returns:
            List[TextContent]: 处理结果
        """
        try:
            # 参数验证
            image1_source = arguments.get("image1_source")
            image2_source = arguments.get("image2_source")
            ensure_valid_image_source(image1_source)
            ensure_valid_image_source(image2_source)
            
            blend_mode = arguments.get("blend_mode", "normal")
            opacity = arguments.get("opacity", 0.5)
            resize_mode = arguments.get("resize_mode", "fit_first")
            output_format = arguments.get("output_format", DEFAULT_IMAGE_FORMAT)
            
            # 验证参数
            validate_numeric_range(opacity, 0.0, 1.0, "opacity")
            
            processor = ImageProcessor()
            
            # 加载图片
            image1 = processor.load_image(image1_source)
            image2 = processor.load_image(image2_source)
            
            # 转换为RGBA模式
            if image1.mode != "RGBA":
                image1 = image1.convert("RGBA")
            if image2.mode != "RGBA":
                image2 = image2.convert("RGBA")
            
            # 调整尺寸
            if resize_mode == "fit_first":
                image2 = image2.resize(image1.size, Image.Resampling.LANCZOS)
                final_size = image1.size
            elif resize_mode == "fit_second":
                image1 = image1.resize(image2.size, Image.Resampling.LANCZOS)
                final_size = image2.size
            elif resize_mode == "fit_largest":
                if image1.width * image1.height > image2.width * image2.height:
                    image2 = image2.resize(image1.size, Image.Resampling.LANCZOS)
                    final_size = image1.size
                else:
                    image1 = image1.resize(image2.size, Image.Resampling.LANCZOS)
                    final_size = image2.size
            else:  # fit_smallest
                if image1.width * image1.height < image2.width * image2.height:
                    image2 = image2.resize(image1.size, Image.Resampling.LANCZOS)
                    final_size = image1.size
                else:
                    image1 = image1.resize(image2.size, Image.Resampling.LANCZOS)
                    final_size = image2.size
            
            # 调整第二张图片的透明度
            alpha_channel = image2.split()[-1]
            alpha_channel = alpha_channel.point(lambda p: int(p * opacity))
            image2.putalpha(alpha_channel)
            
            # 应用混合模式
            if blend_mode == "normal":
                result = Image.alpha_composite(image1, image2)
            elif blend_mode == "multiply":
                # 简化的乘法混合
                result = Image.blend(image1, image2, opacity)
            elif blend_mode == "screen":
                # 简化的屏幕混合
                result = Image.blend(image1, image2, opacity)
            else:
                # 其他混合模式使用普通混合
                result = Image.alpha_composite(image1, image2)
            
            # 转换为base64
            output_info = processor.output_image(result, "batch_resize", output_format)
            
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": True,
                    "message": f"成功混合图片,使用{blend_mode}模式",
                    "data": {
                        **output_info,
                        "metadata": {
                            "size": f"{result.width}x{result.height}",
                            "blend_mode": blend_mode,
                            "opacity": opacity,
                            "resize_mode": resize_mode,
                            "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:726-749 (registration)
    Tool registration via @mcp.tool() decorator in main.py. Defines input parameters with descriptions and defaults matching the handler schema, constructs arguments dict, and calls the advanced handler via safe_run_async.
    @mcp.tool()
    def blend_images(
        image1_source: Annotated[str, Field(description="第一张图片源,可以是文件路径或base64编码的图片数据")],
        image2_source: Annotated[str, Field(description="第二张图片源,可以是文件路径或base64编码的图片数据")],
        blend_mode: Annotated[str, Field(description="混合模式:normal(正常)、multiply(正片叠底)、screen(滤色)、overlay(叠加)", default="normal")],
        opacity: Annotated[float, Field(description="第二张图片的不透明度,范围 0.0-1.0", ge=0.0, le=1.0, default=0.5)],
        output_format: Annotated[str, Field(description="输出格式:PNG、JPEG、WEBP 等", default="PNG")]
    ) -> str:
        """混合两张图片"""
        try:
            arguments = {
                "image1_source": image1_source,
                "image2_source": image2_source,
                "blend_mode": blend_mode,
                "opacity": opacity,
                "output_format": output_format
            }
            result = safe_run_async(advanced_blend_images(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 blend_images tool inputs within the Tool object in get_advanced_tools(), detailing properties, enums, defaults, and required fields.
    Tool(
        name="blend_images",
        description="混合两张图片",
        inputSchema={
            "type": "object",
            "properties": {
                "image1_source": {
                    "type": "string",
                    "description": "第一张图片源(文件路径或base64编码)"
                },
                "image2_source": {
                    "type": "string",
                    "description": "第二张图片源(文件路径或base64编码)"
                },
                "blend_mode": {
                    "type": "string",
                    "description": "混合模式",
                    "enum": ["normal", "multiply", "screen", "overlay", "soft_light", "hard_light"],
                    "default": "normal"
                },
                "opacity": {
                    "type": "number",
                    "description": "第二张图片的透明度(0.0-1.0)",
                    "minimum": 0.0,
                    "maximum": 1.0,
                    "default": 0.5
                },
                "resize_mode": {
                    "type": "string",
                    "description": "尺寸调整模式",
                    "enum": ["fit_first", "fit_second", "fit_largest", "fit_smallest"],
                    "default": "fit_first"
                },
                "output_format": {
                    "type": "string",
                    "description": "输出格式",
                    "enum": ["PNG", "JPEG", "WEBP"],
                    "default": "PNG"
                }
            },
            "required": ["image1_source", "image2_source"]
        }
    ),
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. '混合两张图片' implies a mutation operation that creates a new blended image, but it doesn't describe what happens to the input images (preserved or modified), whether there are size/format constraints, performance implications, or error conditions. For a tool with 5 parameters and no annotations, this is a significant gap in transparency.

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—just four characters in Chinese—and front-loaded with the core action. There's zero wasted verbiage, making it efficient for quick understanding. Every character earns its place by directly stating the tool's purpose.

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 complexity (5 parameters, mutation operation) and the presence of an output schema (which handles return values), the description is minimally adequate. However, with no annotations and many sibling tools, it lacks context about behavioral traits, usage scenarios, and differentiation. The output schema mitigates some completeness issues, but the description alone is insufficient for full understanding.

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 each parameter well-documented in the input schema (e.g., blend_mode options, opacity range, output formats). The description adds no additional parameter semantics beyond what's already in the schema. According to the rules, when schema coverage is high (>80%), the baseline score is 3 even with no param info in the description.

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 '混合两张图片' (blend two images) clearly states the verb (blend) and resource (images), making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from similar sibling tools like 'create_collage' or 'apply_overlay' (if such existed), which might also involve combining images. The description is specific about the action but lacks sibling differentiation.

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 manipulation (e.g., 'add_watermark', 'create_collage', 'apply_overlay'), there's no indication of when blending is preferred over other methods for combining images. It lacks any context about use cases, prerequisites, 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/duke0317/ps-mcp'

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