Skip to main content
Glama

merge_hwp_cells_horizontal

Merge adjacent cells horizontally in a table row by setting colSpan on the first cell and removing the absorbed cells. Specify file, table, row, start column, and number of cells to merge.

Instructions

Merge horizontal cells in a row of a table by setting colSpan on the first cell and removing the absorbed cells. Args: file_path, table_index, row, col_start, col_count (>=2), output_path (optional).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
table_indexYes
rowYes
col_startYes
col_countYes
output_pathNo

Implementation Reference

  • The tool handler function `mergeHwpCellsHorizontal` in the tools layer. It performs preflight checks, computes output path, calls the core mutation function `mergeHwpxCellsHorizontal`, and returns a Korean-language result string.
    export async function mergeHwpCellsHorizontal(args: MergeCellsArgs): 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, "merged");
      try {
        const r = await mergeHwpxCellsHorizontal(
          args.file_path, out, args.table_index, args.row, args.col_start, args.col_count
        );
        return `셀 병합 완료 (merged ${r.merged} cells): 표 ${args.table_index}, 행 ${args.row}, 열 ${args.col_start}..${args.col_start + args.col_count - 1}\n저장 (saved): ${out}`;
      } catch (e) {
        return `셀 병합 오류 (merge error): ${(e as Error).message}`;
      }
    }
  • The `MergeCellsArgs` interface defining the input schema: file_path, table_index, row, col_start, col_count, and optional output_path.
    export interface MergeCellsArgs {
      file_path: string;
      table_index: number;
      row: number;
      col_start: number;
      col_count: number;
      output_path?: string;
    }
  • The MCP tool registration schema for 'merge_hwp_cells_horizontal', including description and inputSchema with property types and required fields.
    name: "merge_hwp_cells_horizontal",
    description:
      "Merge horizontal cells in a row of a table by setting colSpan on the first cell and removing the absorbed cells. Args: file_path, table_index, row, col_start, col_count (>=2), output_path (optional).",
    inputSchema: {
      type: "object",
      properties: {
        file_path: { type: "string" },
        table_index: { type: "number" },
        row: { type: "number" },
        col_start: { type: "number" },
        col_count: { type: "number" },
        output_path: { type: "string" },
      },
      required: ["file_path", "table_index", "row", "col_start", "col_count"],
    },
  • src/server.ts:536-536 (registration)
    Registration of the tool name 'merge_hwp_cells_horizontal' mapping to the handler function `mergeHwpCellsHorizontal` in the server's tool list.
    merge_hwp_cells_horizontal: mergeHwpCellsHorizontal,
  • Core implementation `mergeHwpxCellsHorizontal` that performs the actual HWPX XML mutation: loads the zip/section, finds the specified table/row/columns, sets colSpan on the first cell, removes absorbed cells, and writes the output.
    export async function mergeHwpxCellsHorizontal(
      inputPath: string,
      outputPath: string,
      tableIndex: number,
      rowIndex: number,
      colStart: number,
      colCount: number
    ): Promise<{ merged: number }> {
      if (colCount < 2) throw new Error("colCount must be >= 2");
      const { zip, sectionName, xml } = await loadSection(inputPath);
      const tblRegex = /<hp:tbl [^>]*>[\s\S]*?<\/hp:tbl>/g;
      const tables = [...xml.matchAll(tblRegex)];
      if (tableIndex < 0 || tableIndex >= tables.length) {
        throw new Error(`Table index out of range: ${tableIndex}`);
      }
      const tableXml = tables[tableIndex][0];
      const trRegex = /<hp:tr(?:\s[^>]*)?>[\s\S]*?<\/hp:tr>/g;
      const trs = [...tableXml.matchAll(trRegex)];
      if (rowIndex < 0 || rowIndex >= trs.length) {
        throw new Error(`Row index out of range: ${rowIndex}`);
      }
      const trXml = trs[rowIndex][0];
      const tcMatches = [...trXml.matchAll(/<hp:tc(?:\s[^>]*)?>[\s\S]*?<\/hp:tc>/g)];
      if (colStart < 0 || colStart + colCount > tcMatches.length) {
        throw new Error(`Column merge range out of bounds: ${colStart}..${colStart + colCount - 1}`);
      }
      const firstTc = tcMatches[colStart][0];
      // Add or update colSpan on the first <hp:tc>
      let mergedFirst: string;
      if (/colSpan="\d+"/.test(firstTc)) {
        mergedFirst = firstTc.replace(/colSpan="\d+"/, `colSpan="${colCount}"`);
      } else if (/^<hp:tc\s/.test(firstTc)) {
        mergedFirst = firstTc.replace(/^<hp:tc /, `<hp:tc colSpan="${colCount}" `);
      } else {
        mergedFirst = firstTc.replace(/^<hp:tc>/, `<hp:tc colSpan="${colCount}">`);
      }
      let newTrXml = trXml.replace(firstTc, mergedFirst);
      for (let i = 1; i < colCount; i++) {
        newTrXml = newTrXml.replace(tcMatches[colStart + i][0], "");
      }
      const newTableXml = tableXml.replace(trXml, newTrXml);
      const newXml = xml.replace(tableXml, newTableXml);
      await writeSection(zip, sectionName, newXml, outputPath);
      return { merged: colCount };
    }
Behavior4/5

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

The description explains the behavioral effect: setting colSpan on the first cell and removing absorbed cells. With no annotations provided, this sufficiently discloses the mutation and file modification.

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?

The description is a single sentence followed by an argument list, which is concise and front-loads the action. It avoids unnecessary words but could be slightly better structured.

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

Completeness4/5

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

For a cell-merging tool with no output schema, the description explains the mechanism and required/optional arguments. It is largely sufficient for an agent to use the tool correctly.

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?

Schema description coverage is 0%, so the description adds meaning by listing the parameters and noting that col_count must be >=2 and output_path is optional. However, it does not explain semantics of table_index, row, or col_start in detail.

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 merges horizontal cells in a row by setting colSpan and removing absorbed cells. The verb 'merge' and resource 'horizontal cells' is specific, and the name distinguishes it from the sibling 'merge_hwp_cells_vertical'.

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 like 'merge_hwp_cells_vertical' or prerequisites. The description only explains what the tool does without context for decision-making.

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