Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

add_column

Add a new column to CSV data by specifying a name and optional value or formula. This tool enables data expansion and custom field creation within the CSV Editor's processing environment.

Instructions

Add a new column to the dataframe.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
nameYes
valueNo
formulaNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core implementation of the add_column tool. Handles adding a new column with constant value, list of values, or computed via formula using pandas eval. Records the operation for history.
    async def add_column(
        session_id: str, 
        name: str,
        value: Any = None,
        formula: Optional[str] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Add a new column to the dataframe.
        
        Args:
            session_id: Session identifier
            name: Name for the new column
            value: Default value for all rows (scalar or list)
            formula: Python expression to calculate values (e.g., "col1 + col2")
            ctx: FastMCP context
            
        Returns:
            Dict with success status
        """
        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
            
            if name in df.columns:
                return {"success": False, "error": f"Column '{name}' already exists"}
            
            if formula:
                # Evaluate formula in the context of the dataframe
                try:
                    session.df[name] = df.eval(formula)
                except Exception as e:
                    return {"success": False, "error": f"Formula evaluation failed: {str(e)}"}
            elif isinstance(value, list):
                if len(value) != len(df):
                    return {"success": False, "error": f"Value list length ({len(value)}) doesn't match row count ({len(df)})"}
                session.df[name] = value
            else:
                # Scalar value or None
                session.df[name] = value
            
            session.record_operation(OperationType.ADD_COLUMN, {
                "name": name,
                "value": str(value) if value is not None else None,
                "formula": formula
            })
            
            return {
                "success": True,
                "column_added": name,
                "columns": session.df.columns.tolist()
            }
            
        except Exception as e:
            logger.error(f"Error adding column: {str(e)}")
            return {"success": False, "error": str(e)}
  • MCP tool registration for 'add_column'. Thin wrapper that delegates to the implementation in transformations.py.
    async def add_column(
        session_id: str,
        name: str,
        value: Any = None,
        formula: Optional[str] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Add a new column to the dataframe."""
        return await _add_column(session_id, name, value, formula, ctx)
  • Input schema defined by the function signature of the registered tool: session_id (str), name (str), value (Any optional), formula (Optional[str]), ctx (Context optional). Returns Dict[str, Any].
    async def add_column(
        session_id: str,
        name: str,
        value: Any = None,
        formula: Optional[str] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Add a new column to the dataframe."""
        return await _add_column(session_id, name, value, formula, ctx)
  • Import of the add_column implementation aliased as _add_column for use in server.py tool wrappers.
    from .tools.transformations import (
        filter_rows as _filter_rows,
        sort_data as _sort_data,
        select_columns as _select_columns,
        rename_columns as _rename_columns,
        add_column as _add_column,
        remove_columns as _remove_columns,
        change_column_type as _change_column_type,
        fill_missing_values as _fill_missing_values,
        remove_duplicates as _remove_duplicates,
        update_column as _update_column
    )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the action without behavioral details. It doesn't disclose whether this is a mutation (likely yes), what happens to existing data, error conditions, or response format. The presence of an output schema helps, but the description adds minimal behavioral context beyond the basic operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place by conveying the essential purpose without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, mutation likely), no annotations, and 0% schema coverage, the description is incomplete. However, the presence of an output schema mitigates some gaps by documenting return values. The description covers the basic 'what' but lacks details on 'how', 'when', and behavioral aspects needed for full context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but adds no parameter information. It doesn't explain what 'session_id', 'name', 'value', or 'formula' mean, their roles in column addition, or how they interact (e.g., using 'value' vs 'formula'). With 4 parameters and no schema descriptions, this is a significant gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'add' and resource 'new column to the dataframe', making the purpose unambiguous. It distinguishes from siblings like 'rename_columns' or 'update_column' by focusing on creation rather than modification. However, it doesn't specify whether this adds to an existing dataframe or creates a new one, keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'update_column' or 'rename_columns'. It doesn't mention prerequisites (e.g., needing an active session), exclusions, or typical scenarios for adding columns. This leaves the agent without context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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