Skip to main content
Glama

delete_row

Remove a specific row from CSV data while preserving deleted information for potential restoration. This tool tracks changes and provides operation statistics for data management.

Instructions

Delete row at specified index with comprehensive tracking.

Captures deleted data for undo operations. Returns operation result with before/after statistics.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
row_indexYesRow index (0-based) to delete

Implementation Reference

  • The core handler function implementing the delete_row tool. It validates the row index, captures the deleted row's data, removes the row from the DataFrame, updates the session, and returns a detailed result.
    def delete_row(
        ctx: Annotated[Context, Field(description="FastMCP context for session access")],
        row_index: Annotated[int, Field(description="Row index (0-based) to delete")],
    ) -> DeleteRowResult:
        """Delete row at specified index with comprehensive tracking.
    
        Captures deleted data for undo operations. Returns operation result with before/after
        statistics.
        """
        session_id = ctx.session_id
        session, df = get_session_data(session_id)
        rows_before = len(df)
    
        # Validate row index
        if row_index < 0 or row_index >= len(df):
            msg = f"Row index {row_index} out of range (0-{len(df) - 1})"
            raise ToolError(msg)
    
        # Get the data that will be deleted for tracking
        deleted_data = df.iloc[row_index].to_dict()
    
        # Handle pandas/numpy types for JSON serialization
        for key, value in deleted_data.items():
            if pd.isna(value):
                deleted_data[key] = None
            elif hasattr(value, "item"):  # numpy scalar
                deleted_data[key] = value.item()
    
        # Delete the row
        df_new = df.drop(df.index[row_index]).reset_index(drop=True)
    
        # Update session data
        session.df = df_new
    
        # No longer recording operations (simplified MCP architecture)
    
        return DeleteRowResult(
            row_index=row_index,
            rows_before=rows_before,
            rows_after=len(df_new),
            deleted_data=deleted_data,
        )
  • Pydantic model defining the output schema and structure for the delete_row tool response.
    class DeleteRowResult(BaseToolResponse):
        """Response model for row deletion operations."""
    
        operation: str = Field(default="delete_row", description="Operation type identifier")
        row_index: int = Field(description="Index of deleted row")
        rows_before: int = Field(description="Row count before deletion")
        rows_after: int = Field(description="Row count after deletion")
        deleted_data: dict[str, CsvCellValue] = Field(description="Data from the deleted row")
  • Registers the delete_row function as an MCP tool with the name 'delete_row' on the row_operations_server.
    row_operations_server.tool(name="delete_row")(delete_row)

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/jonpspri/databeak'

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