Skip to main content
Glama
GongRzhe

Office Word MCP Server

merge_table_cells_vertical

Merge cells vertically in a single column of a Word document table to combine content or create headers.

Instructions

Merge cells vertically in a single column.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
table_indexYes
col_indexYes
start_rowYes
end_rowYes

Implementation Reference

  • Tool registration using FastMCP @mcp.tool() decorator. Delegates implementation to format_tools.merge_table_cells_vertical.
    @mcp.tool()
    def merge_table_cells_vertical(filename: str, table_index: int, col_index: int, 
                                 start_row: int, end_row: int):
        """Merge cells vertically in a single column."""
        return format_tools.merge_table_cells_vertical(filename, table_index, col_index, start_row, end_row)
  • Primary handler implementation: input validation, document loading/saving, delegates to core.tables.merge_cells_vertical for the merge operation.
    async def merge_table_cells_vertical(filename: str, table_index: int, col_index: int, 
                                       start_row: int, end_row: int) -> str:
        """Merge cells vertically in a single column.
        
        Args:
            filename: Path to the Word document
            table_index: Index of the table (0-based)
            col_index: Column index (0-based)
            start_row: Starting row index (0-based)
            end_row: Ending row index (0-based, inclusive)
        """
        filename = ensure_docx_extension(filename)
        
        # Ensure numeric parameters are the correct type
        try:
            table_index = int(table_index)
            col_index = int(col_index)
            start_row = int(start_row)
            end_row = int(end_row)
        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 vertical cell merge
            success = merge_cells_vertical(table, col_index, start_row, end_row)
            
            if success:
                doc.save(filename)
                return f"Cells merged vertically in table {table_index}, column {col_index}, rows {start_row}-{end_row}."
            else:
                return f"Failed to merge cells vertically. Check that indices are valid."
        except Exception as e:
            return f"Failed to merge cells vertically: {str(e)}"
  • Helper wrapper for vertical cell merging, invokes general merge_cells function.
    def merge_cells_vertical(table, col_index, start_row, end_row):
        """
        Merge cells vertically in a single column.
        
        Args:
            table: The table containing cells to merge
            col_index: Column index (0-based)
            start_row: Starting row index (0-based)
            end_row: Ending row index (0-based, inclusive)
            
        Returns:
            True if successful, False otherwise
        """
        return merge_cells(table, start_row, col_index, end_row, col_index)
  • Core cell merging logic: performs validation of merge range and executes python-docx cell.merge(end_cell).
    def merge_cells(table, start_row, start_col, end_row, end_col):
        """
        Merge cells in a rectangular area.
        
        Args:
            table: The table containing cells to merge
            start_row: Starting row index (0-based)
            start_col: Starting column index (0-based)
            end_row: Ending row index (0-based, inclusive)
            end_col: Ending column index (0-based, inclusive)
            
        Returns:
            True if successful, False otherwise
        """
        try:
            # Validate indices
            if (start_row < 0 or start_col < 0 or end_row < 0 or end_col < 0 or
                start_row >= len(table.rows) or end_row >= len(table.rows) or
                start_row > end_row or start_col > end_col):
                return False
            
            # Check if all rows have enough columns
            for row_idx in range(start_row, end_row + 1):
                if (start_col >= len(table.rows[row_idx].cells) or 
                    end_col >= len(table.rows[row_idx].cells)):
                    return False
            
            # Get the start and end cells
            start_cell = table.cell(start_row, start_col)
            end_cell = table.cell(end_row, end_col)
            
            # Merge the cells
            start_cell.merge(end_cell)
            
            return True
            
        except Exception as e:
            print(f"Error merging cells: {e}")
            return False
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 ('merge') but doesn't describe effects (e.g., data loss, formatting changes), permissions needed, error conditions, or output format. This is inadequate for a mutation tool with zero annotation coverage.

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, making it easy to parse. It's appropriately sized for the tool's complexity and front-loaded with the core action.

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?

For a mutation tool with 5 parameters, 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks details on behavior, parameter usage, error handling, and output, leaving significant gaps for an AI agent to understand and invoke the tool correctly.

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 for 5 undocumented parameters. It mentions 'vertically in a single column', which hints at 'col_index', 'start_row', and 'end_row', but doesn't explain 'filename' or 'table_index' or provide details on parameter usage, formats, or constraints.

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 'Merge cells vertically in a single column' clearly states the action (merge) and resource (table cells), with 'vertically in a single column' specifying the scope. It distinguishes from sibling 'merge_table_cells' (general) and 'merge_table_cells_horizontal' (horizontal merging), though it doesn't explicitly name these alternatives.

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_table_cells' or 'merge_table_cells_horizontal', nor are prerequisites or exclusions mentioned. The description implies vertical merging in a column but lacks explicit usage context.

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