Skip to main content
Glama

set_hwp_field_value

Assign a new value to a named field in a Hancom HWPx file, replacing the content between the field's start and end tags.

Instructions

Set a Hancom field's value by name in an .hwpx (writes the new text between the matching <hp:fldBegin name=...> and <hp:fldEnd>). Use list_hwp_fields first to discover names. Args: file_path, name, value, output_path (optional).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
nameYes
valueYes
output_pathNo

Implementation Reference

  • Tool handler function for 'set_hwp_field_value'. Calls setHwpxFieldValue from core/hwpx-mutate.ts after preflight check.
    export async function setHwpFieldValue(args: SetFieldArgs): 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, "field-set");
      try {
        const r = await setHwpxFieldValue(args.file_path, out, args.name, args.value);
        if (r.replaced === 0) return `필드를 찾지 못했습니다 (field not found): ${args.name}`;
        return `필드 '${args.name}' = '${args.value}' (replaced ${r.replaced})\n저장 (saved): ${out}`;
      } catch (e) {
        return `필드 설정 오류 (set field error): ${(e as Error).message}`;
      }
    }
  • TypeScript interface SetFieldArgs defining the input schema: file_path, name, value, optional output_path.
    export interface SetFieldArgs {
      file_path: string;
      name: string;
      value: string;
      output_path?: string;
    }
  • MCP tool registration with input schema for set_hwp_field_value. Required: file_path, name, value.
    {
      name: "set_hwp_field_value",
      description:
        "Set a Hancom field's value by name in an .hwpx (writes the new text between the matching `<hp:fldBegin name=...>` and `<hp:fldEnd>`). Use list_hwp_fields first to discover names. Args: file_path, name, value, output_path (optional).",
      inputSchema: {
        type: "object",
        properties: {
          file_path: { type: "string" },
          name: { type: "string" },
          value: { type: "string" },
          output_path: { type: "string" },
        },
        required: ["file_path", "name", "value"],
      },
  • src/server.ts:540-543 (registration)
    Handler registration mapping 'set_hwp_field_value' → setHwpFieldValue (from edit.ts).
    set_hwp_field_value: setHwpFieldValue,
    delete_hwp_image: deleteHwpImage,
    render_hwp_html: renderHwpHtml,
    render_hwp_equation_svg: renderHwpEquationSvg,
  • Core implementation: loads .hwpx ZIP, finds <hp:fldBegin name='...'> / <hp:fldEnd> pairs, replaces <hp:t> text content with new value.
    export async function setHwpxFieldValue(
      inputPath: string,
      outputPath: string,
      fieldName: string,
      value: string
    ): Promise<{ replaced: number }> {
      const { zip, sectionName, xml } = await loadSection(inputPath);
      // OWPML field markers: <hp:fldBegin name="..." .../> ... text ... <hp:fldEnd .../>
      // Or as attribute on <hp:run>. Strategy: find each fldBegin/fldEnd pair where name matches,
      // then replace any <hp:t>...</hp:t> between them with new value (in the *first* such pair).
      // This is best-effort; full schema support comes in v0.3.
      const fldBeginRegex = new RegExp(
        `<hp:fldBegin[^/>]*name="${escapeRegex(fieldName)}"[^/>]*/?>`,
        "g"
      );
      const beginMatches = [...xml.matchAll(fldBeginRegex)];
      if (beginMatches.length === 0) {
        return { replaced: 0 };
      }
      // Take the first occurrence; find the next <hp:fldEnd .../> after it
      const begin = beginMatches[0];
      const startIdx = (begin.index ?? 0) + begin[0].length;
      const fldEndRegex = /<hp:fldEnd[^/>]*\/?>/g;
      fldEndRegex.lastIndex = startIdx;
      const endMatch = fldEndRegex.exec(xml);
      if (!endMatch) {
        return { replaced: 0 };
      }
      const before = xml.slice(0, startIdx);
      const between = xml.slice(startIdx, endMatch.index);
      const after = xml.slice(endMatch.index);
      const newBetween = between.replace(
        /<hp:t>[^<]*<\/hp:t>/g,
        `<hp:t>${xmlEscape(value)}</hp:t>`
      );
      const newXml = before + newBetween + after;
      await writeSection(zip, sectionName, newXml, outputPath);
      return { replaced: 1 };
    }
Behavior3/5

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

With no annotations, the description carries full burden. It reveals that the tool writes new text between specific XML tags, indicating a mutation. However, it omits important behaviors such as error handling (missing field), whether the file is overwritten if output_path is omitted, and any permission requirements. The transparency is adequate but lacks depth for a write operation.

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 plus an args list. The first sentence states the core action with technical context, and the second provides a critical usage hint. No fluff or redundancy, earning the highest score.

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 four parameters, no output schema, and no annotations, the description is minimally complete. It covers the main action and prerequisite but lacks details on error handling, side effects (in-place modification vs. new file), and behavior when output_path is absent. It is functional but leaves gaps for an agent.

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 lists the four parameters as 'Args: file_path, name, value, output_path (optional)', but adds no meaning beyond the parameter names and optionality. Schema coverage is 0%, so the description should compensate, yet it fails to explain what each parameter represents (e.g., file_path is path to .hwpx, name is field name, value is replacement text, output_path is optional output location).

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 specifies the action ('Set a Hancom field's value by name'), the resource (Hancom field in .hwpx files), and differentiates from siblings like list_hwp_fields (discovery) and get_hwp_field_value (reading). It is specific, non-tautological, and uses technical detail (XML tags) to clarify scope.

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

Usage Guidelines4/5

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

The description explicitly advises using list_hwp_fields first to discover field names, establishing a clear prerequisite. It does not, however, discuss when to avoid this tool (e.g., for bulk operations) or contrast with fill_hwp_template, but the sibling list implies differentiation. The guidance is clear but not exhaustive.

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