Skip to main content
Glama

create_csv

Create CSV files with custom headers and optional initial data for structured data storage and management.

Instructions

Create a new CSV file with headers and optional initial data. Args: filename: Name of the CSV file to create (without .csv extension) headers: List of column headers data: Optional list of rows, where each row is a list of values Returns: Dictionary with creation results and file information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
filenameYes
headersYes

Implementation Reference

  • Registration and handler function for the MCP 'create_csv' tool, which delegates execution to CSVManager.create_csv()
    @mcp.tool() def create_csv( filename: str, headers: List[str], data: Optional[List[List[Any]]] = None ) -> Dict[str, Any]: """ Create a new CSV file with headers and optional initial data. Args: filename: Name of the CSV file to create (without .csv extension) headers: List of column headers data: Optional list of rows, where each row is a list of values Returns: Dictionary with creation results and file information """ try: return csv_manager.create_csv(filename, headers, data) except Exception as e: return {"success": False, "error": str(e)}
  • Core handler logic for creating CSV files, including path validation, DataFrame creation with pandas, file writing, and size validation
    def create_csv(self, filename: str, headers: List[str], data: Optional[List[List[Any]]] = None) -> Dict[str, Any]: """Create a new CSV file with headers and optional initial data.""" filepath = self._get_file_path(filename) if filepath.exists(): raise FileExistsError(f"CSV file '{filename}' already exists") try: # Ensure directory exists for absolute paths self._ensure_directory_exists(filepath) # Create DataFrame df = pd.DataFrame(columns=headers) if data: df = pd.DataFrame(data, columns=headers) # Save to CSV df.to_csv(filepath, index=False) self._validate_file_size(filepath) logger.info(f"Created CSV file: {filepath}") return { "success": True, "filename": filename, "filepath": str(filepath), "rows_created": len(df), "columns": headers } except Exception as e: logger.error(f"Failed to create CSV: {e}") raise
  • Input schema defined by function parameters and type hints for the create_csv tool (inferred by FastMCP)
    def create_csv( filename: str, headers: List[str], data: Optional[List[List[Any]]] = None ) -> 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