load_csv
Load local CSV files into DataFrames for data exploration and analysis. Specify file paths and optionally name datasets for organized processing.
Instructions
Load CSV File Tool
Purpose: Load a local CSV file into a DataFrame.
Usage Notes: • If a df_name is not provided, the tool will automatically assign names sequentially as df_1, df_2, and so on.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| csv_path | Yes | ||
| df_name | No |
Implementation Reference
- src/mcp_server_ds/server.py:161-175 (handler)Core handler implementation in ScriptRunner class that loads the CSV file using pandas.read_csv, assigns a dataframe name if not provided, stores it in memory, and returns a success message or raises an error.def load_csv(self, csv_path: str, df_name:str = None): self.df_count += 1 if not df_name: df_name = f"df_{self.df_count}" try: self.data[df_name] = pd.read_csv(csv_path) self.notes.append(f"Successfully loaded CSV into dataframe '{df_name}'") return [ TextContent(type="text", text=f"Successfully loaded CSV into dataframe '{df_name}'") ] except Exception as e: raise McpError( INTERNAL_ERROR, f"Error loading CSV: {str(e)}" ) from e
- src/mcp_server_ds/server.py:128-131 (schema)Pydantic BaseModel defining the input schema for the load_csv tool, with required csv_path (str) and optional df_name (str). Used for validation and tool registration.class LoadCsv(BaseModel): csv_path: str df_name: Optional[str] = None
- src/mcp_server_ds/server.py:285-289 (registration)Tool registration in the @server.list_tools() handler, specifying the name 'load_csv', description, and input schema from LoadCsv model.Tool( name = DataExplorationTools.LOAD_CSV, description = LOAD_CSV_TOOL_DESCRIPTION, inputSchema = LoadCsv.model_json_schema(), ),
- src/mcp_server_ds/server.py:302-305 (handler)Dispatch logic in the @server.call_tool() handler that extracts arguments and delegates to ScriptRunner.load_csv for execution.if name == DataExplorationTools.LOAD_CSV: csv_path = arguments.get("csv_path") df_name = arguments.get("df_name") return script_runner.load_csv(csv_path, df_name)
- src/mcp_server_ds/server.py:113-115 (helper)Enum defining the tool names, including LOAD_CSV = "load_csv", used throughout for registration and dispatching.class DataExplorationTools(str, Enum): LOAD_CSV = "load_csv" RUN_SCRIPT = "run_script"