Skip to main content
Glama
NovaAI-innovation

CSV MCP Server

add_row

Add a new row of data to a CSV file by specifying column names and values. This tool inserts records into CSV files for data management.

Instructions

Add a new row to the CSV file.

Args:
    filename: Name of the CSV file
    row_data: Dictionary mapping column names to values

Returns:
    Dictionary with addition results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
row_dataYes

Implementation Reference

  • MCP tool handler for 'add_row': decorated with @mcp.tool(), defines input schema via type hints and docstring, delegates execution to CSVManager.add_row with error handling.
    @mcp.tool()
    def add_row(filename: str, row_data: Dict[str, Any]) -> Dict[str, Any]:
        """
        Add a new row to the CSV file.
        
        Args:
            filename: Name of the CSV file
            row_data: Dictionary mapping column names to values
        
        Returns:
            Dictionary with addition results
        """
        try:
            return csv_manager.add_row(filename, row_data)
        except Exception as e:
            return {"success": False, "error": str(e)}
  • Core logic implementation in CSVManager.add_row: loads CSV with pandas, creates new row from dict, appends it, saves with backup and size validation.
    def add_row(self, filename: str, row_data: Dict[str, Any]) -> Dict[str, Any]:
        """Add a new row to 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)
            
            # Create new row DataFrame
            new_row = pd.DataFrame([row_data])
            
            # Append the new row
            df = pd.concat([df, new_row], ignore_index=True)
            
            df.to_csv(filepath, index=False)
            self._validate_file_size(filepath)
            
            logger.info(f"Added row to CSV file: {filepath}")
            return {
                "success": True,
                "filename": filename,
                "row_added": row_data,
                "new_total_rows": len(df)
            }
        except Exception as e:
            logger.error(f"Failed to add row: {e}")
            raise
  • Registration of the 'add_row' tool via FastMCP @mcp.tool() decorator.
    @mcp.tool()
  • Input schema defined by function signature: filename (str), row_data (Dict[str, Any]); output Dict[str, Any].
    def add_row(filename: str, row_data: Dict[str, Any]) -> Dict[str, Any]:

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