Skip to main content
Glama

set_hwp_paragraph_text

Replace the text of a specified paragraph in an .hwpx document while preserving its formatting. Collapses existing runs into a single run with the new text.

Instructions

Replace the entire text of the Nth paragraph (0-based) in an .hwpx body with new text. The paragraph attributes (paraPr/style refs) are preserved; runs are collapsed into a single hp:run with the new text. Args: file_path, index, text, output_path (optional).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
indexYes
textYes
output_pathNo

Implementation Reference

  • The tool handler function 'setHwpParagraphText' that executes the logic for 'set_hwp_paragraph_text'. It validates input, delegates to the core mutator, and returns a result string.
    export async function setHwpParagraphText(args: SetParaTextArgs): 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, "para-set");
      try {
        const r = await setHwpxParagraphText(args.file_path, out, args.index, args.text);
        if (r.replaced === 0) return `인덱스 범위 초과 (index out of range): ${args.index} (전체 ${r.total})`;
        return `문단 ${args.index} 텍스트 설정 (paragraph text set)\n저장 (saved): ${out}`;
      } catch (e) {
        return `문단 텍스트 설정 오류 (set paragraph text error): ${(e as Error).message}`;
      }
    }
  • The TypeScript interface 'SetParaTextArgs' defining the input schema for the tool: file_path, index, text, and optional output_path.
    export interface SetParaTextArgs {
      file_path: string;
      index: number;
      text: string;
      output_path?: string;
    }
  • The core implementation 'setHwpxParagraphText' that performs the actual XML mutation: loads the HWPX zip, finds the Nth <hp:p> paragraph, collapses its runs into a single <hp:run> with the new text, preserves character formatting via charPrIDRef, and writes back.
    export async function setHwpxParagraphText(
      inputPath: string,
      outputPath: string,
      index: number,
      text: string
    ): Promise<{ replaced: number; total: number }> {
      const { zip, sectionName, xml } = await loadSection(inputPath);
      const matches = [...xml.matchAll(PARA_REGEX)];
      if (index < 0 || index >= matches.length) {
        return { replaced: 0, total: matches.length };
      }
      const para = matches[index][0];
      // Replace every <hp:t>...</hp:t> with one carrying the new text;
      // collapse to a single <hp:run><hp:t>NEW</hp:t></hp:run> body inside the
      // paragraph wrapper to avoid duplicating runs.
      const open = para.match(/^<hp:p [^>]*>/)?.[0] ?? "<hp:p>";
      const close = "</hp:p>";
      const charPrMatch = para.match(/<hp:run [^>]*charPrIDRef="(\d+)"/);
      const charPrId = charPrMatch ? charPrMatch[1] : "0";
      const newPara =
        open +
        `<hp:run charPrIDRef="${charPrId}"><hp:t>${xmlEscape(text)}</hp:t></hp:run>` +
        close;
      const newXml = xml.replace(para, newPara);
      await writeSection(zip, sectionName, newXml, outputPath);
      return { replaced: 1, total: matches.length };
    }
  • src/server.ts:275-289 (registration)
    Tool registration entry in the TOOLS array: defines name 'set_hwp_paragraph_text', description, and input schema (file_path, index, text, output_path).
    {
      name: "set_hwp_paragraph_text",
      description:
        "Replace the entire text of the Nth paragraph (0-based) in an .hwpx body with new text. The paragraph attributes (paraPr/style refs) are preserved; runs are collapsed into a single <hp:run> with the new text. Args: file_path, index, text, output_path (optional).",
      inputSchema: {
        type: "object",
        properties: {
          file_path: { type: "string" },
          index: { type: "number" },
          text: { type: "string" },
          output_path: { type: "string" },
        },
        required: ["file_path", "index", "text"],
      },
    },
  • src/server.ts:538-538 (registration)
    Handler mapping in the HANDLERS record linking the tool name 'set_hwp_paragraph_text' to the imported 'setHwpParagraphText' function.
    set_hwp_paragraph_text: setHwpParagraphText,
Behavior3/5

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

With no annotations, the description must disclose behavior. It mentions that paragraph attributes are preserved and runs are collapsed into a single <hp:run>, which is good. However, it does not clarify whether the tool modifies the file in-place or creates a new file (output_path optional implies possibly in-place), nor does it mention error handling or permissions. Transparency is adequate but not thorough.

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 very concise: two sentences and a parameter list. It front-loads the main purpose and behavioral notes, with no redundant or irrelevant information. Every sentence adds value.

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?

Given the absence of annotations and output schema, the description is moderately complete. It covers the main operation and key behavioral details (preserving attributes, collapsing runs). However, it lacks information on return values, error scenarios, and usage context relative to siblings, so it is not fully complete for an agent to use without guesswork.

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?

Schema description coverage is 0%, so the description must explain parameters. It lists the four parameters (file_path, index, text, output_path) and notes that output_path is optional, but provides no additional semantic detail such as value ranges, format constraints, or behavior for edge cases (e.g., out-of-range index, empty text). This adds minimal value beyond the schema.

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 action: 'Replace the entire text of the Nth paragraph (0-based) in an .hwpx body with new text.' It specifies the verb (replace), resource (paragraph text), file type (.hwpx), and indexing (0-based). This distinguishes it from siblings like set_hwp_cell_text or replace_hwp_text.

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?

The description does not provide guidance on when to use this tool versus alternatives. No explicit 'when to use' or 'when not to use' statements are present. It only lists arguments, missing context like 'Use for replacing paragraph text while preserving formatting; for bulk text replacement use replace_hwp_text.'

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