select_columns
Extract specific columns from CSV data to focus on relevant information and simplify analysis.
Instructions
Select specific columns from the dataframe.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| columns | Yes |
Implementation Reference
- Core handler function that performs column selection on the session's pandas DataFrame, including validation, operation recording, and response generation.async def select_columns( session_id: str, columns: List[str], ctx: Context = None ) -> Dict[str, Any]: """ Select specific columns from the dataframe. Args: session_id: Session identifier columns: List of column names to keep ctx: FastMCP context Returns: Dict with success status and selected 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[columns].copy() session.record_operation(OperationType.SELECT, { "columns": columns, "columns_before": df.columns.tolist(), "columns_after": columns }) return { "success": True, "selected_columns": columns, "columns_removed": [col for col in df.columns if col not in columns] } except Exception as e: logger.error(f"Error selecting columns: {str(e)}") return {"success": False, "error": str(e)}
- src/csv_editor/server.py:220-227 (registration)Registers the 'select_columns' tool using the FastMCP @mcp.tool decorator, delegating execution to the imported handler function.@mcp.tool async def select_columns( session_id: str, columns: List[str], ctx: Context = None ) -> Dict[str, Any]: """Select specific columns from the dataframe.""" return await _select_columns(session_id, columns, ctx)