apply_edge_enhance
Enhance image edges to improve clarity and detail using the edge enhancement filter on the Image Processing MCP Server. Input images via file path or base64 encoding.
Instructions
应用边缘增强滤镜
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_source | Yes | 图片源,可以是文件路径或base64编码的图片数据 |
Implementation Reference
- tools/filters.py:339-387 (handler)Core handler function implementing the edge enhance filter using PIL ImageFilter.EDGE_ENHANCE. Loads image, applies filter, generates base64 output, and returns JSON result.async def apply_edge_enhance(image_data: str) -> list[TextContent]: """ 应用边缘增强滤镜 Args: image_data: 图片数据(base64编码) Returns: 应用滤镜后的图片数据 """ try: # 验证参数 if not image_data: raise ValidationError("图片数据不能为空") # 加载图片 image = processor.load_image(image_data) # 应用边缘增强滤镜 enhanced_image = image.filter(ImageFilter.EDGE_ENHANCE) # 输出处理后的图片 output_info = processor.output_image(enhanced_image, "edge_enhance") result = { "success": True, "message": "边缘增强滤镜应用成功", "data": { **output_info, "filter_type": "edge_enhance", "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:284-297 (registration)MCP server registration of the tool using @mcp.tool() decorator. Provides a synchronous wrapper that safely calls the async handler from filters.py.@mcp.tool() def apply_edge_enhance( image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")] ) -> str: """应用边缘增强滤镜""" try: result = safe_run_async(filters_apply_edge_enhance(image_source)) return result[0].text except Exception as e: return json.dumps({ "success": False, "error": f"应用边缘增强失败: {str(e)}" }, ensure_ascii=False, indent=2)
- tools/filters.py:79-92 (schema)Tool schema definition specifying input as object with required 'image_data' string field (base64 image). Part of get_filter_tools().Tool( name="apply_edge_enhance", description="应用边缘增强滤镜", inputSchema={ "type": "object", "properties": { "image_data": { "type": "string", "description": "图片数据(base64编码)" } }, "required": ["image_data"] } ),