select_columns
Select only the columns you need from your CSV data, simplifying analysis by removing irrelevant fields.
Instructions
Select specific columns from the dataframe.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| columns | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The actual handler for the select_columns tool. Gets the session, validates columns exist in the dataframe, selects only the specified columns using df[columns].copy(), records the operation, and returns success/error.
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: {e!s}") return {"success": False, "error": str(e)} - src/csv_editor/server.py:211-216 (registration)The MCP tool registration/decorator for select_columns. Uses @mcp.tool decorator to register the function, defines the FastMCP API with session_id and columns parameters, and delegates to the actual implementation via _select_columns.
@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) - src/csv_editor/server.py:69-80 (schema)The tool is listed under capabilities in the server info, documenting select_columns as a data_manipulation capability.
"data_manipulation": [ "filter_rows", "sort_data", "select_columns", "rename_columns", "add_column", "remove_columns", "change_column_type", "fill_missing_values", "remove_duplicates", ], "data_analysis": [