Skip to main content
Glama

extract_hwp_images

Extract and save all embedded images from an HWP file to a specified output directory (defaults to _images/).

Instructions

Save every embedded image to disk. Args: file_path, output_dir (optional; defaults to _images/).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
output_dirNo

Implementation Reference

  • Main handler function that extracts all embedded images from an HWP/HWPX file and saves them to disk. Opens the document, walks images via walkImages(), creates the output directory, writes each image as a file, and returns a summary.
    export async function extractHwpImages(args: ExtractImagesArgs): 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 to extract)";
        const baseName = basename(args.file_path, extname(args.file_path));
        const outDir = args.output_dir
          ? resolve(args.output_dir)
          : resolve(dirname(args.file_path), `${baseName}_images`);
        mkdirSync(outDir, { recursive: true });
        const saved: string[] = [];
        imgs.forEach((img, i) => {
          const bytes = getImageBytes(doc, img);
          const fname = `image_${String(i + 1).padStart(3, "0")}.${img.ext}`;
          const fpath = join(outDir, fname);
          writeFileSync(fpath, bytes);
          saved.push(fname);
        });
        return [
          `이미지 ${saved.length}개를 추출했습니다 (extracted ${saved.length} images):`,
          `저장 위치 (output): ${outDir}`,
          "",
          ...saved.map((s) => `  - ${s}`),
        ].join("\n");
      } finally {
        closeDocument(doc);
      }
    }
  • TypeScript interface ExtractImagesArgs defining the input schema for extractHwpImages: file_path (required) and output_dir (optional).
    export interface ExtractImagesArgs {
      file_path: string;
      output_dir?: string;
    }
  • src/server.ts:80-90 (registration)
    Tool registration: defines the name 'extract_hwp_images', its description, and inputSchema (object with file_path required, output_dir optional).
    name: "extract_hwp_images",
    description:
      "Save every embedded image to disk. Args: file_path, output_dir (optional; defaults to <file>_images/).",
    inputSchema: {
      type: "object",
      properties: {
        file_path: { type: "string" },
        output_dir: { type: "string" },
      },
      required: ["file_path"],
    },
  • src/server.ts:514-514 (registration)
    Registration of extractHwpImages handler function in the HANDLERS record mapping tool names to handler functions.
    extract_hwp_images: extractHwpImages,
  • Helper walkImages() that iterates over all sections/paragraphs/controls in an HWP document, collecting image metadata (mime, byte length, ext) into ImageRef array.
    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;
    }
  • Helper getImageBytes() that retrieves raw image byte data from the document given an ImageRef.
    export function getImageBytes(doc: HwpDocument, ref: ImageRef): Uint8Array {
      return doc.getControlImageData(ref.section, ref.paragraph, ref.controlIdx);
    }
  • ImageRef interface defining the structure for referencing an embedded image: section, paragraph, controlIdx, mime, byteLength, ext.
    export interface ImageRef {
      section: number;
      paragraph: number;
      controlIdx: number;
      mime: string;
      byteLength: number;
      ext: string;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must fully convey behavior, but it omits crucial details: what happens if file_path is missing, whether it overwrites existing files, image format handling, or any side effects. The default output_dir hint is helpful but insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise: two sentences with no redundancy. It front-loads the core purpose and immediately lists parameters. Every word is necessary.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite low complexity (2 simple params, no nested objects, no output schema, no annotations), the description is missing return value specifications, error conditions, and behavioral constraints. A user cannot fully anticipate the tool's effect.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds the default value for output_dir and notes its optionality, but provides no guidance for file_path beyond its name. Since schema description coverage is 0%, the description does not compensate adequately for missing parameter details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'save', resource 'every embedded image', and destination 'to disk'. It is distinct from sibling tools like list_hwp_images (listing only) or delete_hwp_image (deletion), making its purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. For example, it does not explain when to use extract_hwp_images instead of list_hwp_images or how it differs from other image-related operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/treesoop/hwp-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server