list_hwp_images
List embedded image metadata (mime type, byte length, locator) from HWP/HWPX files.
Instructions
List embedded images (mime, byte length, locator) in an HWP/HWPX file. Args: file_path.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes |
Implementation Reference
- src/tools/images.ts:18-37 (handler)The main handler function that lists embedded images in an HWP/HWPX file. Opens the document, walks through all images using walkImages(), and returns a formatted string listing each image's section/paragraph/control index, MIME type, byte length, and file extension.
export async function listHwpImages(args: ListImagesArgs): Promise<string> { let doc; try { doc = await openDocument(args.file_path); } catch (e) { return (e as Error).message; } try { const imgs = walkImages(doc); if (imgs.length === 0) return "(이미지가 없습니다 / no images)"; return imgs .map( (img, i) => `${i + 1}. [section ${img.section}, para ${img.paragraph}, ctrl ${img.controlIdx}] ${img.mime} (${img.byteLength} bytes, .${img.ext})` ) .join("\n"); } finally { closeDocument(doc); } } - src/tools/images.ts:10-12 (schema)Input schema for listHwpImages: requires a file_path string.
export interface ListImagesArgs { file_path: string; } - src/server.ts:69-78 (registration)Tool definition/registration in the SERVER_TOOLS array with name 'list_hwp_images', description, and inputSchema.
{ name: "list_hwp_images", description: "List embedded images (mime, byte length, locator) in an HWP/HWPX file. Args: file_path.", inputSchema: { type: "object", properties: { file_path: { type: "string" } }, required: ["file_path"], }, }, - src/server.ts:513-513 (registration)Handler mapping in the HANDLERS record, mapping 'list_hwp_images' to the listHwpImages function.
list_hwp_images: listHwpImages, - src/core/document.ts:393-426 (helper)Helper function walkImages() that iterates over all sections, paragraphs, and controls in an HWP document, extracting image metadata and returning an array of ImageRef objects.
export function walkImages(doc: HwpDocument): ImageRef[] { const out: ImageRef[] = []; const sectionCount = doc.getSectionCount(); for (let s = 0; s < sectionCount; s++) { const paraCount = doc.getParagraphCount(s); for (let p = 0; p < paraCount; p++) { const n = controlCount(doc, s, p); for (let ci = 0; ci < n; ci++) { let mime: string; try { mime = doc.getControlImageMime(s, p, ci); } catch { continue; } if (!mime) continue; let bytes: Uint8Array; try { bytes = doc.getControlImageData(s, p, ci); } catch { continue; } out.push({ section: s, paragraph: p, controlIdx: ci, mime, byteLength: bytes.byteLength, ext: extFromMime(mime), }); } } } return out; }