delete_csv
Remove CSV files from your filesystem with optional backup functionality to prevent data loss during deletion operations.
Instructions
Delete a CSV file (with backup if enabled).
Args:
filename: Name of the CSV file to delete
Returns:
Dictionary with deletion results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes |
Implementation Reference
- csv_mcp_server/server.py:271-286 (handler)MCP tool handler for delete_csv. Decorated with @mcp.tool() which registers the tool. Delegates execution to csv_manager.delete_csv with error handling.@mcp.tool() def delete_csv(filename: str) -> Dict[str, Any]: """ Delete a CSV file (with backup if enabled). Args: filename: Name of the CSV file to delete Returns: Dictionary with deletion results """ try: return csv_manager.delete_csv(filename) except Exception as e: return {"success": False, "error": str(e)}
- Core deletion logic in CSVManager class. Handles file path resolution, backup creation, file deletion, logging, and returns detailed success/error information.def delete_csv(self, filename: str) -> Dict[str, Any]: """Delete a CSV file.""" filepath = self._get_file_path(filename) if not filepath.exists(): raise FileNotFoundError(f"CSV file '{filename}' not found") try: # Create backup before deletion backup_path = self._create_backup(filepath) # Delete the file filepath.unlink() logger.info(f"Deleted CSV file: {filepath}") return { "success": True, "filename": filename, "deleted_filepath": str(filepath), "backup_created": backup_path is not None, "backup_path": str(backup_path) if backup_path else None } except Exception as e: logger.error(f"Failed to delete CSV: {e}") raise