Skip to main content
Glama
GongRzhe

Office Word MCP Server

merge_table_cells_horizontal

Combine adjacent cells horizontally in a Word table row to create wider cells for headers, labels, or merged content.

Instructions

Merge cells horizontally in a single row.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
table_indexYes
row_indexYes
start_colYes
end_colYes

Implementation Reference

  • Main execution logic for the merge_table_cells_horizontal tool: validates inputs, loads Word document using python-docx, calls helper to perform merge, saves document and returns status.
    async def merge_table_cells_horizontal(filename: str, table_index: int, row_index: int, 
                                         start_col: int, end_col: int) -> str:
        """Merge cells horizontally in a single row.
        
        Args:
            filename: Path to the Word document
            table_index: Index of the table (0-based)
            row_index: Row index (0-based)
            start_col: Starting column index (0-based)
            end_col: Ending column index (0-based, inclusive)
        """
        filename = ensure_docx_extension(filename)
        
        # Ensure numeric parameters are the correct type
        try:
            table_index = int(table_index)
            row_index = int(row_index)
            start_col = int(start_col)
            end_col = int(end_col)
        except (ValueError, TypeError):
            return "Invalid parameter: all indices must be integers"
        
        if not os.path.exists(filename):
            return f"Document {filename} does not exist"
        
        # Check if file is writeable
        is_writeable, error_message = check_file_writeable(filename)
        if not is_writeable:
            return f"Cannot modify document: {error_message}. Consider creating a copy first."
        
        try:
            doc = Document(filename)
            
            # Validate table index
            if table_index < 0 or table_index >= len(doc.tables):
                return f"Invalid table index. Document has {len(doc.tables)} tables (0-{len(doc.tables)-1})."
            
            table = doc.tables[table_index]
            
            # Apply horizontal cell merge
            success = merge_cells_horizontal(table, row_index, start_col, end_col)
            
            if success:
                doc.save(filename)
                return f"Cells merged horizontally in table {table_index}, row {row_index}, columns {start_col}-{end_col}."
            else:
                return f"Failed to merge cells horizontally. Check that indices are valid."
        except Exception as e:
            return f"Failed to merge cells horizontally: {str(e)}"
  • MCP tool registration using @mcp.tool() decorator. Defines tool schema via type hints and delegates execution to format_tools.merge_table_cells_horizontal.
    @mcp.tool()
    def merge_table_cells_horizontal(filename: str, table_index: int, row_index: int, 
                                   start_col: int, end_col: int):
        """Merge cells horizontally in a single row."""
        return format_tools.merge_table_cells_horizontal(filename, table_index, row_index, start_col, end_col)
  • Supporting helper function that performs the actual horizontal cell merging by invoking the general merge_cells function on the specified row range.
    def merge_cells_horizontal(table, row_index, start_col, end_col):
        """
        Merge cells horizontally in a single row.
        
        Args:
            table: The table containing cells to merge
            row_index: Row index (0-based)
            start_col: Starting column index (0-based)
            end_col: Ending column index (0-based, inclusive)
            
        Returns:
            True if successful, False otherwise
        """
        return merge_cells(table, row_index, start_col, row_index, end_col)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action but doesn't reveal critical traits: whether this is a destructive mutation (likely yes, as merging alters table structure), what happens to content in merged cells (e.g., retention or loss), or error conditions (e.g., invalid indices). This is inadequate for a tool with clear mutation implications.

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 a single, efficient sentence with no wasted words. It's front-loaded with the core action and scope, making it easy to parse. Every word earns its place by conveying essential information without redundancy.

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?

Given the complexity (a mutation tool with 5 parameters, 0% schema coverage, no annotations, and no output schema), the description is incomplete. It fails to address behavioral risks, parameter usage, or output expectations. For a tool that modifies document structure, this lack of context could lead to incorrect or unsafe invocations by 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?

Schema description coverage is 0%, so the description must compensate by explaining parameters. It adds no semantic meaning beyond what the schema names imply (e.g., 'filename', 'row_index'). Key details like what 'table_index' refers to, zero-based indexing, or the inclusive/exclusive nature of 'start_col' and 'end_col' are missing, leaving parameters largely undocumented.

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?

The description clearly states the action ('merge cells horizontally') and the scope ('in a single row'), which is specific and unambiguous. It distinguishes from the sibling 'merge_table_cells' (which might be more general) and 'merge_table_cells_vertical' (which handles vertical merging). However, it doesn't explicitly mention the resource (e.g., a document or table), though this is implied by the context of sibling tools.

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 provides no guidance on when to use this tool versus alternatives like 'merge_table_cells' or 'merge_table_cells_vertical'. It lacks context about prerequisites (e.g., needing an existing table) or exclusions (e.g., not applicable across multiple rows). This leaves the agent to infer usage from the name alone.

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/GongRzhe/Office-Word-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server