Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

rename_columns

Rename multiple columns in a CSV dataframe using a mapping dictionary. Specify old and new column names to update your data structure.

Instructions

Rename columns in the dataframe.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
mappingYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that validates column existence, uses pandas df.rename() to rename columns, records the operation, and returns success/failure response.
    async def rename_columns(
        session_id: str, mapping: dict[str, str], ctx: Context = None
    ) -> dict[str, Any]:
        """
        Rename columns in the dataframe.
    
        Args:
            session_id: Session identifier
            mapping: Dict mapping old column names to new names
            ctx: FastMCP context
    
        Returns:
            Dict with success status and renamed 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 mapping if col not in df.columns]
            if missing_cols:
                return {"success": False, "error": f"Columns not found: {missing_cols}"}
    
            session.df = df.rename(columns=mapping)
            session.record_operation(OperationType.RENAME, {"mapping": mapping})
    
            return {"success": True, "renamed": mapping, "columns": session.df.columns.tolist()}
    
        except Exception as e:
            logger.error(f"Error renaming columns: {e!s}")
            return {"success": False, "error": str(e)}
  • MCP tool registration via @mcp.tool decorator that delegates to the actual handler in transformations.py.
    @mcp.tool
    async def rename_columns(
        session_id: str, mapping: dict[str, str], ctx: Context = None
    ) -> dict[str, Any]:
        """Rename columns in the dataframe."""
        return await _rename_columns(session_id, mapping, ctx)
  • Import of rename_columns handler from transformations module, aliased as _rename_columns.
    from .tools.transformations import rename_columns as _rename_columns
  • OperationType enum defining RENAME as a supported operation type for session history tracking.
    class OperationType(str, Enum):
        """Types of operations that can be performed."""
    
        LOAD = "load"
        FILTER = "filter"
        SORT = "sort"
        TRANSFORM = "transform"
        AGGREGATE = "aggregate"
        EXPORT = "export"
        ANALYZE = "analyze"
        UPDATE_COLUMN = "update_column"
        ADD_COLUMN = "add_column"
        REMOVE_COLUMN = "remove_column"
        RENAME = "rename"
  • Tool listed in server capabilities under 'data_manipulation'.
        "rename_columns",
        "add_column",
        "remove_columns",
        "change_column_type",
        "fill_missing_values",
        "remove_duplicates",
    ],
Behavior2/5

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

No annotations are present, so the description must disclose behavior. It only states 'rename columns' without explaining effects (e.g., in-place mutation, return of modified dataframe, error conditions). Important behavioral traits are missing.

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

Conciseness2/5

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

The description is a single sentence, which is concise, but it lacks necessary detail. Oversimplification leads to ambiguity; it is not effectively compact.

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 the presence of many sibling tools (e.g., 'remove_columns', 'select_columns'), the description fails to position this tool within the workflow. The output schema exists but is not referenced. The description is insufficient for an agent to use the tool correctly.

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?

The schema coverage is 0%. The description does not explain the 'session_id' or 'mapping' parameters. The mapping object schema implies old-to-new name pairs, but the description adds no clarification beyond the schema.

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 action ('rename') and the resource ('columns in the dataframe'). The verb and object are specific, making the tool's purpose clear. However, it does not differentiate from sibling tools like 'update_column' or 'add_column'.

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 is provided on when to use this tool or when to prefer alternatives. The description does not mention prerequisites, scenarios, or exclusions.

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