Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

add_column

Add a new column to your CSV data with a specified name, optional static value, or formula-based calculation.

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. Adds a new column to the dataframe, supporting scalar values, lists, and formula-based calculations via df.eval(). Records the operation in session history.
    async def add_column(
        session_id: str, name: str, value: Any = None, formula: str | None = 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: {e!s}"}
            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: {e!s}")
            return {"success": False, "error": str(e)}
  • MCP tool registration decorator (@mcp.tool) for add_column. Defines the tool's interface (session_id, name, value, formula, ctx) and delegates to the handler in transformations.py.
    @mcp.tool
    async def add_column(
        session_id: str, name: str, value: Any = None, formula: str | None = None, ctx: Context = None
    ) -> dict[str, Any]:
        """Add a new column to the dataframe."""
        return await _add_column(session_id, name, value, formula, ctx)
  • Enum entry ADD_COLUMN = 'add_column' in OperationType, used for operation history tracking.
    ADD_COLUMN = "add_column"
  • Records the add_column operation in session history with the operation name, column name, value, and formula.
    session.record_operation(
        OperationType.ADD_COLUMN,
        {"name": name, "value": str(value) if value is not None else None, "formula": formula},
    )
Behavior2/5

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

No annotations provided, so the description carries full burden. It lacks disclosure on behavior like column existence checks, session requirements, or the relationship between 'value' and 'formula' parameters.

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

Conciseness3/5

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

A single sentence is concise but not optimally structured; it lacks front-loading of key behavioral constraints or parameter nuances.

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

Completeness2/5

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

Given 4 parameters (2 required), no output schema explanation, and no annotations, the description is insufficient for an agent to fully understand invocation and result.

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

Parameters1/5

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

Schema description coverage is 0%, and the description adds no meaning to the parameters ('session_id', 'name', 'value', 'formula'). Nothing clarifies their roles or interactions.

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 states a specific action ('Add a new column') and the resource ('dataframe'). However, it does not differentiate from sibling tools like 'update_column' or 'rename_columns', missing scope details.

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?

No guidance on when to use this tool versus alternatives; no mention of prerequisites or situations where add_column is preferred over others.

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