Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

adjust_opacity

Change image transparency by adjusting opacity levels from fully transparent to fully opaque to modify image appearance for overlays, watermarks, or visual effects.

Instructions

调整图片不透明度

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据
opacityYes不透明度,范围 0.0-1.0,0.0为完全透明,1.0为完全不透明

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler function that loads the image, adjusts the alpha channel opacity using PIL, processes output with ImageProcessor, and returns JSON result.
    async def adjust_opacity(image_source: str, opacity: float) -> list[TextContent]:
        """
        调整图片不透明度
        
        Args:
            image_source: 图片数据(base64编码)或文件路径
            opacity: 不透明度值(0.0-1.0)
            
        Returns:
            调整后的图片数据
        """
        try:
            # 验证参数
            if not image_source:
                raise ValidationError("图片数据不能为空")
            
            if not validate_numeric_range(opacity, 0.0, 1.0):
                raise ValidationError(f"不透明度值必须在0.0-1.0范围内: {opacity}")
            
            # 加载图片
            image = processor.load_image(image_source)
            original_mode = image.mode
            
            # 确保图片有alpha通道
            if image.mode != 'RGBA':
                image = image.convert('RGBA')
            
            # 获取图片数据
            data = image.getdata()
            
            # 调整alpha通道
            new_data = []
            for item in data:
                # item是(R, G, B, A)元组
                r, g, b, a = item
                # 计算新的alpha值
                new_alpha = int(a * opacity)
                new_data.append((r, g, b, new_alpha))
            
            # 创建新图片
            opacity_image = Image.new('RGBA', image.size)
            opacity_image.putdata(new_data)
            
            # 输出处理后的图片
            output_info = processor.output_image(opacity_image, "opacity")
            
            result = {
                "success": True,
                "message": f"不透明度调整成功: {opacity}",
                "data": {
                    **output_info,
                    "opacity_value": opacity,
                    "original_mode": original_mode,
                    "new_mode": opacity_image.mode,
                    "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:473-487 (registration)
    MCP tool registration using @mcp.tool() decorator. Defines input schema via Annotated Fields, wraps and calls the core handler from color_adjust.py.
    @mcp.tool()
    def adjust_opacity(
        image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")],
        opacity: Annotated[float, Field(description="不透明度,范围 0.0-1.0,0.0为完全透明,1.0为完全不透明", ge=0.0, le=1.0)]
    ) -> str:
        """调整图片不透明度"""
        try:
            result = safe_run_async(color_adjust_opacity(image_source, opacity))
            return result[0].text
        except Exception as e:
            return json.dumps({
                "success": False,
                "error": f"调整不透明度失败: {str(e)}"
            }, ensure_ascii=False, indent=2)
  • Tool schema definition used in get_color_adjust_tools(), matching the input parameters for adjust_opacity.
    Tool(
        name="adjust_opacity",
        description="调整图片不透明度",
        inputSchema={
            "type": "object",
            "properties": {
                "image_source": {
                    "type": "string",
                    "description": "图片数据(base64编码)或文件路径"
                },
                "opacity": {
                    "type": "number",
                    "description": "不透明度值(0.0-1.0,0.0为完全透明,1.0为完全不透明)",
                    "minimum": 0.0,
                    "maximum": 1.0
                }
            },
            "required": ["image_source", "opacity"]
        }
    )
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 for behavioral disclosure. While '调整' (adjust) implies mutation, the description doesn't specify whether this modifies the original image or creates a new one, what format the output takes, whether there are performance implications, or any error conditions. For a mutation tool with zero annotation coverage, this is insufficient.

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 phrase in Chinese that directly states the tool's function without any wasted words. It's appropriately sized for a straightforward image adjustment operation.

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 that there's an output schema (though not shown here), the description doesn't need to explain return values. However, for an image mutation tool with no annotations and many similar siblings, the description should provide more context about behavioral characteristics and usage differentiation 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?

Schema description coverage is 100%, with both parameters well-documented in the schema itself (image_source accepts file paths or base64 data, opacity is a 0.0-1.0 number). The description adds no additional parameter information beyond what's already in the schema, so it meets the baseline for high schema coverage.

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 '调整图片不透明度' (adjust image opacity) clearly states the verb ('adjust') and resource ('image opacity'), making the purpose immediately understandable. However, it doesn't differentiate this tool from its many image-processing siblings (like adjust_brightness or adjust_contrast) beyond the specific property being adjusted.

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 adjustments (brightness, contrast, saturation, etc.), there's no indication of when opacity adjustment is appropriate versus other visual modifications or how it might interact with them.

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