process_images
Process images in a directory with operations like enhancing, OCR, resizing, and deduplication, returning results in JSON format for streamlined image management.
Instructions
Process images in a directory with various operations.
Args:
image_dir: Directory containing images to process
operations: List of operations (enhance, ocr, resize, deduplicate)
ocr_language: Language for OCR processing (default: eng)
Returns:
JSON string with processing results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_dir | Yes | ||
| ocr_language | No | eng | |
| operations | No |
Implementation Reference
- server.py:258-300 (handler)The core handler and registration for the 'process_images' MCP tool. Decorated with @mcp.tool(), it processes images in a directory with specified operations (enhance, OCR, etc.) using an image processor, returning JSON results. The function signature provides input schema via type hints and defaults.@mcp.tool() async def process_images( image_dir: str, operations: List[str] = ["enhance"], ocr_language: str = "eng" ) -> str: """ Process images in a directory with various operations. Args: image_dir: Directory containing images to process operations: List of operations (enhance, ocr, resize, deduplicate) ocr_language: Language for OCR processing (default: eng) Returns: JSON string with processing results. """ try: ip = get_image_processor() results = ip.process_batch(image_dir, operations) # Add OCR language info to results if OCR was performed if "ocr" in operations: for ocr_result in results.get("ocr_results", []): ocr_result["language"] = ocr_language result = { "status": "success", "image_directory": image_dir, "operations": operations, "results": results } return json.dumps(result, indent=2) except Exception as e: logger.error(f"Failed to process images: {e}") return json.dumps({ "status": "error", "error": str(e), "image_directory": image_dir, "operations": operations })