remove_columns
Delete specific columns from a CSV file to streamline and organize data. Use this MCP tool by specifying the columns to remove for precise data manipulation.
Instructions
Remove columns from the dataframe.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| columns | Yes | ||
| session_id | Yes |
Implementation Reference
- Core implementation of the remove_columns tool: validates columns, drops them from the pandas DataFrame using df.drop(), records the operation, and returns success info with remaining columns.async def remove_columns( session_id: str, columns: List[str], ctx: Context = None ) -> Dict[str, Any]: """ Remove columns from the dataframe. Args: session_id: Session identifier columns: List of column names to remove ctx: FastMCP context Returns: Dict with success status and removed columns """ try: manager = get_session_manager() session = manager.get_session(session_id) if not session or session.df is None: return {"success": False, "error": "Invalid session or no data loaded"} df = session.df # Validate columns exist missing_cols = [col for col in columns if col not in df.columns] if missing_cols: return {"success": False, "error": f"Columns not found: {missing_cols}"} session.df = df.drop(columns=columns) session.record_operation(OperationType.REMOVE_COLUMN, { "columns": columns }) return { "success": True, "removed_columns": columns, "remaining_columns": session.df.columns.tolist() } except Exception as e: logger.error(f"Error removing columns: {str(e)}") return {"success": False, "error": str(e)}
- src/csv_editor/server.py:249-256 (registration)MCP tool registration via @mcp.tool decorator. This wrapper function delegates to the actual implementation imported as _remove_columns from transformations.py.@mcp.tool async def remove_columns( session_id: str, columns: List[str], ctx: Context = None ) -> Dict[str, Any]: """Remove columns from the dataframe.""" return await _remove_columns(session_id, columns, ctx)