Skip to main content
Glama

merge_cells

Combine a range of cells in an Excel spreadsheet to create a single merged cell. Input file path, sheet name, and start and end cells to perform the operation.

Instructions

Merge a range of cells.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
end_cellYes
filepathYes
sheet_nameYes
start_cellYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler and registration for 'merge_cells'. The @mcp.tool() decorator registers this function as an MCP tool. It handles input validation via type hints, calls the helper function, and returns success/error messages.
    @mcp.tool()
    def merge_cells(filepath: str, sheet_name: str, start_cell: str, end_cell: str) -> str:
        """Merge a range of cells."""
        try:
            full_path = get_excel_path(filepath)
            result = merge_range(full_path, sheet_name, start_cell, end_cell)
            return result["message"]
        except (ValidationError, SheetError) as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error merging cells: {e}")
            raise
  • Supporting utility function that performs the actual cell merging using openpyxl. Parses the cell range, calls worksheet.merge_cells(), saves the workbook, and returns a success message.
    def merge_range(filepath: str, sheet_name: str, start_cell: str, end_cell: str) -> Dict[str, Any]:
        """Merge a range of cells."""
        try:
            wb = load_workbook(filepath)
            if sheet_name not in wb.sheetnames:
                raise SheetError(f"Sheet '{sheet_name}' not found")
                
            start_row, start_col, end_row, end_col = parse_cell_range(start_cell, end_cell)
    
            if end_row is None or end_col is None:
                raise SheetError("Both start and end cells must be specified for merging")
    
            range_string = format_range_string(start_row, start_col, end_row, end_col)
            worksheet = wb[sheet_name]
            worksheet.merge_cells(range_string)
            wb.save(filepath)
            return {"message": f"Range '{range_string}' merged in sheet '{sheet_name}'"}
        except SheetError as e:
            logger.error(str(e))
            raise
        except Exception as e:
            logger.error(f"Failed to merge range: {e}")
            raise SheetError(str(e))
Behavior1/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the action ('merge') without any details on side effects (e.g., data loss in merged cells, impact on formulas), permissions required, error conditions, or rate limits. This leaves critical behavioral traits unspecified for a mutation tool.

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 that directly states the tool's purpose without unnecessary words. It's front-loaded and wastes no space, making it easy to parse quickly.

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 tool's complexity (a mutation operation with 4 parameters), lack of annotations, and 0% schema description coverage, the description is incomplete. It doesn't explain behavioral risks, parameter usage, or output (though an output schema exists, reducing some burden). For a tool that modifies data, this level of detail is inadequate.

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%, meaning none of the 4 parameters (filepath, sheet_name, start_cell, end_cell) have descriptions in the schema. The tool description adds no information about parameter meanings, formats (e.g., A1 notation for cells), or constraints, failing to compensate for the schema gap.

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') and resource ('a range of cells'), which is specific and unambiguous. However, it doesn't distinguish this tool from its sibling 'unmerge_cells' or other cell manipulation tools like 'format_range', leaving room for improvement in sibling differentiation.

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. There's no mention of prerequisites (e.g., needing an existing workbook), exclusions (e.g., not applicable to protected sheets), or comparisons with siblings like 'unmerge_cells' or 'format_range', making it minimally helpful 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

Related 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/haris-musa/excel-mcp-server'

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