Skip to main content
Glama

apply_find_edges

Detect and highlight edges in images using a specialized edge detection filter. Input an image source as a file path or base64 data for precise edge identification.

Instructions

应用边缘检测滤镜

Input Schema

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

Implementation Reference

  • Core asynchronous handler function that validates input, loads the image using ImageProcessor, applies PIL's ImageFilter.FIND_EDGES to detect edges, generates output image data, and returns a JSON-formatted result wrapped in TextContent.
    async def apply_find_edges(image_data: str) -> list[TextContent]: """ 应用边缘检测滤镜 Args: image_data: 图片数据(base64编码) Returns: 应用滤镜后的图片数据 """ try: # 验证参数 if not image_data: raise ValidationError("图片数据不能为空") # 加载图片 image = processor.load_image(image_data) # 应用边缘检测滤镜 edges_image = image.filter(ImageFilter.FIND_EDGES) # 输出处理后的图片 output_info = processor.output_image(edges_image, "find_edges") result = { "success": True, "message": "边缘检测滤镜应用成功", "data": { **output_info, "filter_type": "find_edges", "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:312-324 (registration)
    MCP tool registration using FastMCP's @mcp.tool() decorator. This synchronous wrapper function calls the async handler from filters.py via safe_run_async, handles exceptions, and returns stringified JSON response. The input schema is derived from the Annotated parameter.
    @mcp.tool() def apply_find_edges( image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")] ) -> str: """应用边缘检测滤镜""" try: result = safe_run_async(filters_apply_find_edges(image_source)) return result[0].text except Exception as e: return json.dumps({ "success": False, "error": f"应用边缘检测失败: {str(e)}" }, ensure_ascii=False, indent=2)
  • Explicit Tool schema definition within get_filter_tools() function, specifying the tool name, description, and input schema requiring a single 'image_data' string parameter.
    Tool( name="apply_find_edges", description="应用边缘检测滤镜", inputSchema={ "type": "object", "properties": { "image_data": { "type": "string", "description": "图片数据(base64编码)" } }, "required": ["image_data"] } ),

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