Skip to main content
Glama

insert_rows

Add one or more rows to an Excel sheet starting at a specified row, enabling efficient data insertion and organization within workbooks.

Instructions

Insert one or more rows starting at the specified row.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo
filepathYes
sheet_nameYes
start_rowYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'insert_rows' decorated with @mcp.tool(). Handles input validation via type hints, calls helper function, and returns result or error message.
    @mcp.tool()
    def insert_rows(
        filepath: str,
        sheet_name: str,
        start_row: int,
        count: int = 1
    ) -> str:
        """Insert one or more rows starting at the specified row."""
        try:
            full_path = get_excel_path(filepath)
            result = insert_row(full_path, sheet_name, start_row, count)
            return result["message"]
        except (ValidationError, SheetError) as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error inserting rows: {e}")
            raise
  • Core helper function implementing row insertion using openpyxl. Loads workbook, validates sheet and parameters, inserts rows via worksheet.insert_rows(), saves file, and returns success message.
    def insert_row(filepath: str, sheet_name: str, start_row: int, count: int = 1) -> Dict[str, Any]:
        """Insert one or more rows starting at the specified row."""
        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 parameters
            if start_row < 1:
                raise ValidationError("Start row must be 1 or greater")
            if count < 1:
                raise ValidationError("Count must be 1 or greater")
                
            worksheet.insert_rows(start_row, count)
            wb.save(filepath)
            
            return {"message": f"Inserted {count} row(s) starting at row {start_row} in sheet '{sheet_name}'"}
        except (ValidationError, SheetError) as e:
            logger.error(str(e))
            raise
        except Exception as e:
            logger.error(f"Failed to insert rows: {e}")
            raise SheetError(str(e))
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 ('Insert') but doesn't clarify whether this is a destructive operation (e.g., shifting existing rows), what permissions are needed, or how errors are handled. The description is too minimal to provide adequate behavioral context 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 front-loads the core action and scope without any wasted words. It's appropriately sized for a straightforward tool, though its brevity contributes to gaps in other dimensions.

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 has 4 parameters with 0% schema coverage, no annotations, and sibling tools that could cause confusion, the description is insufficient. It doesn't address behavioral risks, parameter details, or usage context. While an output schema exists (not provided here), the description still lacks completeness for safe and effective use.

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 only vaguely references 'the specified row' (likely 'start_row') and 'one or more rows' (likely 'count'), but doesn't clarify 'filepath' or 'sheet_name' usage, or provide details like row indexing (1-based vs. 0-based). This leaves key parameters 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 ('Insert') and resource ('one or more rows') with a specific scope ('starting at the specified row'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'insert_columns' or 'write_data_to_excel', which would require mentioning it's for spreadsheet rows specifically.

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 'write_data_to_excel' or 'insert_columns', nor does it mention prerequisites such as file existence or sheet validity. It lacks context about typical use cases or exclusions, leaving the agent to infer usage from the tool 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

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