Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

convert_to_grayscale

Convert color images to grayscale by processing file paths or base64 encoded data. This tool transforms RGB images to monochrome for simplified visual analysis or stylistic effects.

Instructions

将图片转换为灰度图

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function that loads the image, converts it to grayscale using PIL's image.convert('L'), processes the output, and returns JSON result.
    async def convert_to_grayscale(image_source: str) -> list[TextContent]:
        """
        将图片转换为灰度图
        
        Args:
            image_source: 图片数据(base64编码)或文件路径
            
        Returns:
            灰度图片数据
        """
        try:
            # 验证参数
            if not image_source:
                raise ValidationError("图片数据不能为空")
            
            # 加载图片
            image = processor.load_image(image_source)
            
            # 转换为灰度图
            grayscale_image = image.convert('L')
            
            # 输出处理后的图片
            output_info = processor.output_image(grayscale_image, "grayscale")
            
            result = {
                "success": True,
                "message": "图片转换为灰度图成功",
                "data": {
                    **output_info,
                    "original_mode": image.mode,
                    "new_mode": grayscale_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:444-456 (registration)
    MCP tool registration decorator (@mcp.tool()) with input schema via Annotated Field, wrapper function that safely calls the imported color_adjust.convert_to_grayscale handler.
    @mcp.tool()
    def convert_to_grayscale(
        image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")]
    ) -> str:
        """将图片转换为灰度图"""
        try:
            result = safe_run_async(color_convert_to_grayscale(image_source))
            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 in get_color_adjust_tools() list (though not directly used in main.py registration).
    Tool(
        name="convert_to_grayscale",
        description="将图片转换为灰度图",
        inputSchema={
            "type": "object",
            "properties": {
                "image_source": {
                    "type": "string",
                    "description": "图片数据(base64编码)或文件路径"
                }
            },
            "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 for behavioral disclosure. It states the transformation outcome (grayscale) but doesn't mention whether this is a destructive operation, what permissions are needed, how large images are handled, or what the output looks like. For an image processing tool with zero annotation coverage, this leaves significant behavioral gaps.

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 with just one sentence in Chinese: '将图片转换为灰度图' (convert image to grayscale). It's front-loaded with the core purpose and contains zero wasted words. This is an excellent example of minimal but complete statement of function.

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 has an output schema (which handles return values), 100% parameter schema coverage, and relatively simple functionality, the description is minimally complete. However, with no annotations and many sibling tools, it should ideally provide more context about when to choose grayscale versus other color transformations. The description covers the basic purpose but lacks richer contextual guidance.

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 the single parameter 'image_source' well-documented in the schema as accepting file paths or base64 data. The description doesn't add any parameter semantics beyond what the schema already provides, so it meets the baseline of 3 for high schema coverage without adding extra value.

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: '将图片转换为灰度图' (convert image to grayscale). It specifies the action (convert) and the resource (image), but doesn't explicitly differentiate from sibling tools like 'apply_sepia' or 'apply_invert' which also modify image colors. The purpose is clear but lacks sibling distinction.

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 that modify image appearance (e.g., apply_sepia, adjust_saturation, apply_invert), there's no indication of when grayscale conversion is appropriate versus other color transformations. No context or exclusions are 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