delete_row
Remove a specific row from CSV data by index position while preserving deleted information for potential restoration. Maintains data integrity by tracking changes and providing operation statistics.
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
| Name | Required | Description | Default |
|---|---|---|---|
| row_index | Yes | Row index (0-based) to delete |
Implementation Reference
- The handler function that implements the delete_row tool logic: validates the row index, captures the deleted row data, removes the row from the DataFrame, updates the session, and returns a DeleteRowResult.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 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")
- src/databeak/servers/row_operations_server.py:650-650 (registration)Registration of the delete_row handler as a FastMCP tool named 'delete_row'.row_operations_server.tool(name="delete_row")(delete_row)