Skip to main content
Glama

delete_range

Remove a specified range of cells in an Excel sheet and adjust neighboring cells by shifting them up or down to maintain data integrity and structure.

Instructions

Delete a range of cells and shift remaining cells.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
end_cellYes
filepathYes
sheet_nameYes
shift_directionNoup
start_cellYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'delete_range' that validates input, resolves file path, calls the sheet operation, and returns the result message or error.
    @mcp.tool()
    def delete_range(
        filepath: str,
        sheet_name: str,
        start_cell: str,
        end_cell: str,
        shift_direction: str = "up"
    ) -> str:
        """Delete a range of cells and shift remaining cells."""
        try:
            full_path = get_excel_path(filepath)
            from excel_mcp.sheet import delete_range_operation
            result = delete_range_operation(
                full_path,
                sheet_name,
                start_cell,
                end_cell,
                shift_direction
            )
            return result["message"]
        except (ValidationError, SheetError) as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error deleting range: {e}")
            raise
  • Core implementation of delete_range operation: loads workbook, validates sheet and range, clears cell contents/formatting using helper, shifts rows/columns, saves workbook.
    def delete_range_operation(
        filepath: str,
        sheet_name: str,
        start_cell: str,
        end_cell: Optional[str] = None,
        shift_direction: str = "up"
    ) -> Dict[str, Any]:
        """Delete a range of cells and shift remaining cells."""
        try:
            wb = load_workbook(filepath)
            if sheet_name not in wb.sheetnames:
                raise SheetError(f"Sheet '{sheet_name}' not found")
                
            worksheet = wb[sheet_name]
            
            # Validate range
            try:
                start_row, start_col, end_row, end_col = parse_cell_range(start_cell, end_cell)
                if end_row and end_row > worksheet.max_row:
                    raise SheetError(f"End row {end_row} out of bounds (1-{worksheet.max_row})")
                if end_col and end_col > worksheet.max_column:
                    raise SheetError(f"End column {end_col} out of bounds (1-{worksheet.max_column})")
            except ValueError as e:
                raise SheetError(f"Invalid range: {str(e)}")
                
            # Validate shift direction
            if shift_direction not in ["up", "left"]:
                raise ValidationError(f"Invalid shift direction: {shift_direction}. Must be 'up' or 'left'")
                
            range_string = format_range_string(
                start_row, start_col,
                end_row or start_row,
                end_col or start_col
            )
            
            # Delete range contents
            delete_range(worksheet, start_cell, end_cell)
            
            # Shift cells if needed
            if shift_direction == "up":
                worksheet.delete_rows(start_row, (end_row or start_row) - start_row + 1)
            elif shift_direction == "left":
                worksheet.delete_cols(start_col, (end_col or start_col) - start_col + 1)
                
            wb.save(filepath)
            
            return {"message": f"Range {range_string} deleted successfully"}
        except (ValidationError, SheetError) as e:
            logger.error(str(e))
            raise
        except Exception as e:
            logger.error(f"Failed to delete range: {e}")
            raise SheetError(str(e))
  • Helper function to clear contents, formatting, font, border, fill, number format, and alignment from a range of cells.
    def delete_range(worksheet: Worksheet, start_cell: str, end_cell: Optional[str] = None) -> None:
        """Delete contents and formatting of a range."""
        start_row, start_col, end_row, end_col = parse_cell_range(start_cell, end_cell)
    
        if end_row is None:
            end_row = start_row
            end_col = start_col
    
        for row in range(start_row, end_row + 1):
            for col in range(start_col, end_col + 1):
                cell = worksheet.cell(row=row, column=col)
                cell.value = None
                cell.font = Font()
                cell.border = Border()
                cell.fill = PatternFill()
                cell.number_format = "General"
                cell.alignment = None
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 mentions deletion and shifting, implying a destructive operation, but lacks details on permissions, reversibility, error handling, or what the output schema might contain. 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 that front-loads the core action and consequence with zero wasted words. It's appropriately sized for the tool's complexity.

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 destructive mutation tool with 5 parameters (4 required), 0% schema description coverage, and no annotations, the description is insufficient. While an output schema exists, the description doesn't address critical aspects like behavioral risks, parameter meanings, or usage context, leaving significant gaps.

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 undocumented parameters. It mentions 'range of cells' and 'shift direction', hinting at parameters like 'start_cell', 'end_cell', and 'shift_direction', but doesn't explain their semantics, formats, or interactions. This adds minimal value beyond the schema's property names.

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 ('Delete') and resource ('a range of cells'), and mentions the consequence ('shift remaining cells'), which distinguishes it from simple deletion tools. However, it doesn't explicitly differentiate from sibling tools like 'delete_sheet_columns' or 'delete_sheet_rows', which might perform similar operations.

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 'delete_sheet_columns' or 'delete_sheet_rows', nor does it mention prerequisites or exclusions. It only describes what the tool does, not when it's appropriate.

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