Skip to main content
Glama

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
NameRequiredDescriptionDefault
session_idYes
columnsYes

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)}
  • 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)

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/santoshray02/csv-editor'

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