Skip to main content
Glama

append_hwp_paragraph

Append a new paragraph to the end of an HWPX document, cloning the last paragraph's structure and inserting specified text.

Instructions

Append a new paragraph to the end of an .hwpx document body. Clones the last paragraph's structure (paraPr/charPr/style refs) and replaces text. Args: file_path, text, output_path (optional).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
textYes
output_pathNo

Implementation Reference

  • MCP tool handler that validates file path (must be .hwpx), determines output path, calls appendHwpxParagraph core function, and returns a Korean/English status message.
    export async function appendHwpParagraph(args: AppendParaArgs): Promise<string> {
      const err = preflight(args.file_path);
      if (err) return err;
      const out = args.output_path && args.output_path.length > 0
        ? args.output_path
        : defaultOutput(args.file_path, "appended");
      try {
        const r = await appendHwpxParagraph(args.file_path, out, args.text);
        return `문단 추가 (paragraph appended): ${r.inserted}건\n저장 (saved): ${out}`;
      } catch (e) {
        return `문단 추가 오류 (append error): ${(e as Error).message}`;
      }
    }
  • TypeScript interface defining the input arguments for appendHwpParagraph: file_path (required), text (required), output_path (optional).
    export interface AppendParaArgs {
      file_path: string;
      text: string;
      output_path?: string;
    }
  • src/server.ts:217-230 (registration)
    Tool registration in the TOOLS array with name 'append_hwp_paragraph', description, and inputSchema (JSON Schema with file_path and text required).
    {
      name: "append_hwp_paragraph",
      description:
        "Append a new paragraph to the end of an .hwpx document body. Clones the last paragraph's structure (paraPr/charPr/style refs) and replaces text. Args: file_path, text, output_path (optional).",
      inputSchema: {
        type: "object",
        properties: {
          file_path: { type: "string" },
          text: { type: "string" },
          output_path: { type: "string" },
        },
        required: ["file_path", "text"],
      },
    },
  • src/server.ts:526-527 (registration)
    Maps the tool name 'append_hwp_paragraph' to the appendHwpParagraph handler function in the HANDLERS record.
    append_hwp_paragraph: appendHwpParagraph,
    delete_hwp_paragraph: deleteHwpParagraph,
  • Core mutation logic: loads the .hwpx ZIP, finds the last paragraph via regex, clones its attributes (with a fresh id), creates a new paragraph with the given text, inserts it before the closing </hs:sec>, and writes the modified ZIP.
    export async function appendHwpxParagraph(
      inputPath: string,
      outputPath: string,
      text: string
    ): Promise<{ inserted: number }> {
      const { zip, sectionName, xml } = await loadSection(inputPath);
      const matches = [...xml.matchAll(PARA_REGEX)];
      if (matches.length === 0) throw new Error("No <hp:p> paragraph found in section to clone");
      const last = matches[matches.length - 1][0];
      // Extract <hp:p> attributes (paraPrIDRef, styleIDRef, etc.) — keep them,
      // but build a minimal body to avoid cloning embedded secPr/linesegarray/etc.
      const openTagMatch = last.match(/^<hp:p ([^>]*)>/);
      if (!openTagMatch) throw new Error("Could not parse <hp:p> opening tag");
      const attrs = openTagMatch[1].replace(/\s*id="\d+"\s*/, ` id="${freshId()}" `);
      // Find a charPrIDRef from any <hp:run ...> inside the cloned para; default 0.
      const charPrMatch = last.match(/<hp:run [^>]*charPrIDRef="(\d+)"/);
      const charPrId = charPrMatch ? charPrMatch[1] : "0";
      const newPara =
        `<hp:p ${attrs}>` +
        `<hp:run charPrIDRef="${charPrId}"><hp:t>${xmlEscape(text)}</hp:t></hp:run>` +
        `</hp:p>`;
      const newXml = xml.replace(/<\/hs:sec>\s*$/, newPara + "</hs:sec>");
      await writeSection(zip, sectionName, newXml, outputPath);
      return { inserted: 1 };
    }
Behavior3/5

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

Discloses that it clones the last paragraph's structure and replaces text, but does not state if it modifies the original file or saves to output_path, nor any side effects. No annotations to supplement.

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

Conciseness4/5

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

Two sentences, front-loaded with purpose. The 'Args' line is a bit redundant but acceptable. No wasted words.

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?

Missing return value description, error handling, and prerequisites. For a tool that modifies documents, knowing whether it returns success or a path is important. Sibling tools provide more context, but this description alone is incomplete.

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

Parameters3/5

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

Lists parameters and indicates output_path is optional, which adds beyond the schema. However, does not describe the format of text or constraints on file_path. Schema has no descriptions, so this helps but is minimal.

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

Purpose4/5

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

Clearly states it appends a paragraph to an .hwpx document and describes cloning behavior. Distinguishes from sibling tools like append_hwp_table_row by focusing on paragraph. However, could be more explicit that it modifies an existing document.

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 on when to use this tool versus siblings like insert_hwp_image or set_hwp_paragraph_text. Does not specify prerequisites (e.g., document must exist).

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