Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

remove_columns

Remove specified columns from CSV dataframes to clean datasets, reduce file size, and focus on relevant information.

Instructions

Remove columns from the dataframe.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
columnsYes

Implementation Reference

  • Core handler implementation that 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)}
  • MCP tool registration via @mcp.tool decorator. Thin wrapper that forwards to the core implementation in 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)
  • Entry-point handler registered with FastMCP, defining input schema via type hints and docstring, delegates to internal _remove_columns.
    @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)

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