list_images
Extract and display all images from a Microsoft Word document with metadata for easy reference and management.
Instructions
List all images in a document.
Args: filepath: Path to the document
Returns: Dictionary with list of images and metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes |
Implementation Reference
- src/docx_mcp/server.py:981-1016 (handler)The implementation of the `list_images` tool, which lists images in a docx document. It is registered via the `@app.tool()` decorator on line 980.
def list_images(filepath: str) -> dict[str, Any]: """ List all images in a document. Args: filepath: Path to the document Returns: Dictionary with list of images and metadata """ logger.info("Listing images", extra={"tool": "list_images", "filepath": filepath}) try: doc = safe_open_document(filepath) images = [] # Count images in document relationships for rel in doc.part.rels.values(): if "image" in rel.target_ref: images.append({ "filename": rel.target_part.filename, "content_type": rel.target_part.content_type, }) return { "status": "success", "filepath": filepath, "images": images, "count": len(images), } except DocxMcpError as e: logger.warning(e.message, extra={"tool": "list_images", "error_code": e.error_code}) return {"status": "error", "error": e.message, "error_code": e.error_code} except Exception as e: logger.error(f"Unexpected error listing images: {str(e)}") return {"status": "error", "error": str(e)}