Skip to main content
Glama

create_hwpx_document

Creates a new .hwpx document from a JSON list of text items and tables (rendered as flat rows).

Instructions

Create a new .hwpx file from a JSON content list of {type:'text',text} items. Tables (type:'table',headers,rows) are rendered as flat text rows in v0.2. Args: output_path (must end with .hwpx), content (JSON string of items).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
output_pathYes
contentYes

Implementation Reference

  • Input schema (CreateHwpxArgs interface) for create_hwpx_document tool: requires output_path (string) and content (string - JSON array of content items).
    export interface CreateHwpxArgs {
      output_path: string;
      content: string;
    }
  • ContentItem type definition: items can be of type 'text' (with text string) or 'table' (with headers string[] and rows string[][]).
    type ContentItem =
      | { type: "text"; text: string }
      | { type: "table"; headers: string[]; rows: string[][] };
  • Main handler function createHwpxDocument. Validates output_path ends with .hwpx, parses content JSON into ContentItem[], creates an empty HWPX document via @rhwp/core's HwpDocument, inserts text and table items (tables rendered as pipe-separated text for v0.2), exports to HWPX bytes, and writes to output_path.
    export async function createHwpxDocument(args: CreateHwpxArgs): Promise<string> {
      if (!args.output_path.toLowerCase().endsWith(".hwpx")) {
        return `출력 경로는 .hwpx 확장자여야 합니다 (output must end with .hwpx): ${args.output_path}`;
      }
      let items: ContentItem[];
      try {
        items = JSON.parse(args.content);
        if (!Array.isArray(items)) throw new Error("content must be a JSON array");
      } catch (e) {
        return `content JSON 파싱 오류 (JSON parse error): ${(e as Error).message}`;
      }
    
      // Strategy:
      //   1) Build a doc via @rhwp/core in memory (text-only round-trips fine in
      //      .hwpx; tables/images do not, so we render tables as plain text rows
      //      with separator pipes — sufficient for v0.2 scope, fully working in
      //      v0.3 once we generate OWPML directly).
      //   2) exportHwpx and write.
      await initRhwp();
      const doc = HwpDocument.createEmpty();
      doc.createBlankDocument();
      try {
        let first = true;
        for (const item of items) {
          const sec = doc.getSectionCount() - 1;
          const para = doc.getParagraphCount(sec) - 1;
          const tail = doc.getParagraphLength(sec, para);
          if (item.type === "text") {
            const prefix = first && tail === 0 ? "" : "\n";
            doc.insertText(sec, para, tail, prefix + item.text);
            first = false;
          } else if (item.type === "table") {
            // Render tables as flat lines until v0.3 adds OWPML table generation.
            const lines: string[] = [];
            lines.push(item.headers.join(" | "));
            lines.push(item.headers.map(() => "---").join(" | "));
            for (const row of item.rows) lines.push(row.join(" | "));
            const block = (first && tail === 0 ? "" : "\n") + lines.join("\n");
            doc.insertText(sec, para, tail, block);
            first = false;
          }
        }
        const bytes = doc.exportHwpx();
        writeFileSync(args.output_path, bytes);
      } catch (e) {
        return `문서 생성 오류 (create error): ${(e as Error).message}`;
      } finally {
        doc.free();
      }
    
      return `HWPX 문서 생성 완료 (created): ${args.output_path}`;
    }
  • src/server.ts:494-506 (registration)
    Tool registration in TOOLS array: defines name 'create_hwpx_document', description, and inputSchema (type: object with required output_path and content string properties).
    {
      name: "create_hwpx_document",
      description:
        "Create a new .hwpx file from a JSON content list of {type:'text',text} items. Tables (type:'table',headers,rows) are rendered as flat text rows in v0.2. Args: output_path (must end with .hwpx), content (JSON string of items).",
      inputSchema: {
        type: "object",
        properties: {
          output_path: { type: "string" },
          content: { type: "string" },
        },
        required: ["output_path", "content"],
      },
    },
  • src/server.ts:517-517 (registration)
    Handler mapping: 'create_hwpx_document' is mapped to the createHwpxDocument function imported from ./tools/write.js.
    create_hwpx_document: createHwpxDocument,
Behavior3/5

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

With no annotations, the description carries full burden. It discloses the required file extension (.hwpx) and the JSON content format, including a limitation about table rendering. However, it omits behaviors like overwrite policy, error handling, and whether the tool is idempotent.

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 concise (two sentences plus a parenthetical explanation) and front-loaded with the core purpose. Every sentence adds essential information without redundancy.

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

Completeness3/5

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

The description covers the two parameters and a limitation, but lacks information on return values, success indicators, error behavior, or what happens if the output path already exists. Given no output schema, more details would improve completeness.

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

Parameters4/5

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

The description adds crucial meaning beyond the schema: output_path must end with .hwpx, and content is a JSON string of items with a specified format (text and table types). This compensates for the schema having zero description coverage.

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 tool creates a new .hwpx file from a JSON content list, specifying the file type and content format. This differentiates it from sibling tools that modify existing HWP files.

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 explicit guidance on when to use this tool versus alternatives like insert_hwp_image or append_hwp_paragraph. The description does not provide context for choosing this tool over others for creating files.

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