Skip to main content
Glama
NovaAI-innovation

CSV MCP Server

remove_row

Delete a specific row from a CSV file by specifying its zero-based index to manage and clean your data.

Instructions

Remove a specific row from the CSV file.

Args:
    filename: Name of the CSV file
    row_index: Zero-based index of the row to remove

Returns:
    Dictionary with removal results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
row_indexYes

Implementation Reference

  • MCP tool handler for 'remove_row', registered via @mcp.tool() decorator. Delegates execution to CSVManager instance and handles exceptions.
    @mcp.tool()
    def remove_row(filename: str, row_index: int) -> Dict[str, Any]:
        """
        Remove a specific row from the CSV file.
        
        Args:
            filename: Name of the CSV file
            row_index: Zero-based index of the row to remove
        
        Returns:
            Dictionary with removal results
        """
        try:
            return csv_manager.remove_row(filename, row_index)
        except Exception as e:
            return {"success": False, "error": str(e)}
  • Core implementation of row removal logic in CSVManager class: validates file, creates backup, loads DataFrame with pandas, drops the specified row, saves back to CSV, returns success info with removed row data.
    def remove_row(self, filename: str, row_index: int) -> Dict[str, Any]:
        """Remove a specific row from the CSV file."""
        filepath = self._get_file_path(filename)
        
        if not filepath.exists():
            raise FileNotFoundError(f"CSV file '{filename}' not found")
        
        # Create backup
        self._create_backup(filepath)
        
        try:
            df = pd.read_csv(filepath)
            
            if row_index >= len(df):
                raise IndexError(f"Row index {row_index} out of range (max: {len(df)-1})")
            
            removed_row = df.iloc[row_index].to_dict()
            df = df.drop(df.index[row_index])
            
            df.to_csv(filepath, index=False)
            
            logger.info(f"Removed row from CSV file: {filepath}")
            return {
                "success": True,
                "filename": filename,
                "removed_row": removed_row,
                "new_total_rows": len(df)
            }
        except Exception as e:
            logger.error(f"Failed to remove row: {e}")
            raise

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/NovaAI-innovation/csv-mcp-server'

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