Skip to main content
Glama
NovaAI-innovation

CSV MCP Server

update_csv

Modify specific data points in CSV files by updating individual cells with new values, enabling precise data correction and maintenance.

Instructions

Update a specific cell in the CSV file.

Args:
    filename: Name of the CSV file to update
    row_index: Zero-based index of the row to update
    column: Name of the column to update
    value: New value for the cell

Returns:
    Dictionary with update results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
row_indexYes
columnYes
valueYes

Implementation Reference

  • MCP tool handler for 'update_csv'. Registers the tool and delegates execution to CSVManager.update_csv, with error handling. The function signature defines the input schema.
    @mcp.tool()
    def update_csv(
        filename: str,
        row_index: int,
        column: str,
        value: Any
    ) -> Dict[str, Any]:
        """
        Update a specific cell in the CSV file.
        
        Args:
            filename: Name of the CSV file to update
            row_index: Zero-based index of the row to update
            column: Name of the column to update
            value: New value for the cell
        
        Returns:
            Dictionary with update results
        """
        try:
            return csv_manager.update_csv(filename, row_index, column, value)
        except Exception as e:
            return {"success": False, "error": str(e)}
  • Core implementation of CSV update logic in CSVManager class. Handles file path resolution, backup creation, pandas DataFrame loading, cell update, saving, validation, and returns detailed results.
    def update_csv(self, filename: str, row_index: int, column: str, value: Any) -> Dict[str, Any]:
        """Update a specific cell in the CSV file."""
        filepath = self._get_file_path(filename)
        
        if not filepath.exists():
            raise FileNotFoundError(f"CSV file '{filename}' not found")
        
        # Create backup
        self._create_backup(filepath)
        
        try:
            df = pd.read_csv(filepath)
            
            if row_index >= len(df):
                raise IndexError(f"Row index {row_index} out of range (max: {len(df)-1})")
            
            if column not in df.columns:
                raise ValueError(f"Column '{column}' not found in CSV")
            
            old_value = df.loc[row_index, column]
            df.loc[row_index, column] = value
            
            df.to_csv(filepath, index=False)
            self._validate_file_size(filepath)
            
            logger.info(f"Updated CSV file: {filepath}")
            return {
                "success": True,
                "filename": filename,
                "row_index": row_index,
                "column": column,
                "old_value": old_value,
                "new_value": value
            }
        except Exception as e:
            logger.error(f"Failed to update CSV: {e}")
            raise
  • The @mcp.tool() decorator registers the update_csv function as an MCP tool.
    @mcp.tool()

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/NovaAI-innovation/csv-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server