Skip to main content
Glama
santoshray02

CSV Editor

by santoshray02

update_column

Modify CSV column data by replacing, extracting, or splitting values to clean and transform datasets for analysis.

Instructions

Update values in a specific column with simple operations like replace, extract, split, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
columnYes
operationYes
valueNo
patternNo
replacementNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler implementing column updates via pandas operations: replace (regex), extract, split, strip, upper, lower, fillna. Records operation and returns samples.
    async def update_column(
        session_id: str,
        column: str,
        operation: str,
        value: Optional[Any] = None,
        pattern: Optional[str] = None,
        replacement: Optional[str] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Update values in a specific column with simple operations.
        
        Args:
            session_id: Session identifier
            column: Column name to update
            operation: Operation type - 'replace', 'extract', 'split', 'strip', 'upper', 'lower', 'fill'
            value: Value for certain operations (e.g., fill value)
            pattern: Pattern for replace/extract operations (regex supported)
            replacement: Replacement string for replace operation
            ctx: FastMCP context
            
        Returns:
            Dict with success status and update info
        """
        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 column not in df.columns:
                return {"success": False, "error": f"Column '{column}' not found"}
            
            original_values_sample = df[column].head(5).tolist()
            
            if operation == "replace":
                if pattern is None or replacement is None:
                    return {"success": False, "error": "Pattern and replacement required for replace operation"}
                session.df[column] = df[column].astype(str).str.replace(pattern, replacement, regex=True)
                
            elif operation == "extract":
                if pattern is None:
                    return {"success": False, "error": "Pattern required for extract operation"}
                session.df[column] = df[column].astype(str).str.extract(pattern, expand=False)
                
            elif operation == "split":
                if pattern is None:
                    pattern = " "
                if value is not None and isinstance(value, int):
                    # Extract specific part after split
                    session.df[column] = df[column].astype(str).str.split(pattern).str[value]
                else:
                    # Just do the split, take first part
                    session.df[column] = df[column].astype(str).str.split(pattern).str[0]
                    
            elif operation == "strip":
                session.df[column] = df[column].astype(str).str.strip()
                
            elif operation == "upper":
                session.df[column] = df[column].astype(str).str.upper()
                
            elif operation == "lower":
                session.df[column] = df[column].astype(str).str.lower()
                
            elif operation == "fill":
                if value is None:
                    return {"success": False, "error": "Value required for fill operation"}
                session.df[column] = df[column].fillna(value)
                
            else:
                return {"success": False, "error": f"Unknown operation: {operation}"}
            
            updated_values_sample = session.df[column].head(5).tolist()
            
            session.record_operation(OperationType.UPDATE_COLUMN, {
                "column": column,
                "operation": operation,
                "pattern": pattern,
                "replacement": replacement,
                "value": str(value) if value is not None else None
            })
            
            return {
                "success": True,
                "column": column,
                "operation": operation,
                "original_sample": original_values_sample,
                "updated_sample": updated_values_sample,
                "rows_updated": len(session.df)
            }
            
        except Exception as e:
            logger.error(f"Error updating column: {str(e)}")
            return {"success": False, "error": str(e)}
  • MCP tool registration: @mcp.tool decorator wraps and exposes the update_column handler from transformations.py
    @mcp.tool
    async def update_column(
        session_id: str,
        column: str,
        operation: str,
        value: Optional[Any] = None,
        pattern: Optional[str] = None,
        replacement: Optional[str] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """Update values in a specific column with simple operations like replace, extract, split, etc."""
        return await _update_column(session_id, column, operation, value, pattern, replacement, ctx)
  • OperationType enum value used for recording update_column operations in session history.
    UPDATE_COLUMN = "update_column"
  • Import of the update_column handler from transformations.py for use in server registration.
    update_column as _update_column
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'update values' and lists operations, but fails to describe critical traits: whether this is a destructive mutation, if it requires specific permissions, what happens to the session, error handling, or rate limits. For a tool with 6 parameters and no annotation coverage, this is a significant gap.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded in a single sentence. It efficiently conveys the core purpose without unnecessary elaboration. However, it could be slightly more structured by explicitly listing common operations or providing a brief example, which would enhance clarity without sacrificing conciseness.

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 complexity (6 parameters, no annotations, but with an output schema), the description is minimally adequate. The output schema likely covers return values, reducing the need for that in the description. However, for a mutation tool with multiple parameters and no annotations, the description should provide more context on behavior, usage, and parameter semantics to be fully complete.

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 for undocumented parameters. It only vaguely references 'operations like replace, extract, split, etc.', which partially explains the 'operation' parameter but ignores others like 'session_id', 'column', 'value', 'pattern', and 'replacement'. This adds minimal value beyond the schema, failing to adequately clarify parameter meanings.

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 tool's purpose: 'Update values in a specific column with simple operations like replace, extract, split, etc.' It specifies the verb ('update'), resource ('values in a specific column'), and scope of operations. However, it doesn't explicitly differentiate from sibling tools like 'change_column_type' or 'rename_columns', which prevents 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. It mentions operations like 'replace, extract, split' but doesn't specify prerequisites, context, or exclusions compared to siblings such as 'fill_missing_values' or 'remove_duplicates'. This lack of explicit usage instructions limits its effectiveness for an AI agent.

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