Skip to main content
Glama

load_file

Load CSV or XLSX files into DataFrames for data analysis. Specify sheet names for XLSX files and customize DataFrame names as needed.

Instructions

Load Data File Tool

Purpose: Load a local CSV or XLSX 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. • For XLSX files, you can specify the sheet_name. If not provided, the first sheet will be loaded.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
df_nameNo
sheet_nameNo

Implementation Reference

  • The core handler function in ScriptRunner class that implements the load_file tool logic: loads CSV or XLSX files into a pandas DataFrame, stores it in self.data with a given or auto-generated name, logs notes, and returns success or error TextContent.
    def load_file(self, file_path: str, df_name:str = None, sheet_name: Optional[str] = None): self.df_count += 1 if not df_name: df_name = f"df_{self.df_count}" try: file_extension = os.path.splitext(file_path)[1].lower() if file_extension == ".csv": self.data[df_name] = pd.read_csv(file_path) self.notes.append(f"Successfully loaded CSV into dataframe '{df_name}' from '{file_path}'") elif file_extension == ".xlsx": self.data[df_name] = pd.read_excel(file_path, sheet_name=sheet_name) self.notes.append(f"Successfully loaded XLSX into dataframe '{df_name}' from '{file_path}' (sheet: {sheet_name or 'first'})") else: raise ValueError(f"Unsupported file type: {file_extension}. Only .csv and .xlsx are supported.") return [ TextContent(type="text", text=f"Successfully loaded data into dataframe '{df_name}'") ] except Exception as e: error_message = f"Error loading file: {str(e)}" self.notes.append(f"ERROR: {error_message}") return [ TextContent(type="text", text=f"Error: {error_message}") ]
  • Pydantic schema (BaseModel) defining the input parameters for the load_file tool: file_path (required), optional df_name and sheet_name.
    class LoadFile(BaseModel): file_path: str df_name: Optional[str] = None sheet_name: Optional[str] = None
  • Registration of the load_file tool in the MCP server's list_tools handler, providing name, description, and input schema.
    Tool(name=DataExplorationTools.LOAD_FILE, description=LOAD_FILE_TOOL_DESCRIPTION, inputSchema=LoadFile.model_json_schema()),
  • Dispatch logic in the MCP server's call_tool handler that routes calls to the load_file tool to the ScriptRunner instance's load_file method.
    if name == DataExplorationTools.LOAD_FILE: return script_runner.load_file(arguments.get("file_path"), arguments.get("df_name"), arguments.get("sheet_name"))
  • Enum defining the tool names, including LOAD_FILE = 'load_file' used in registration and dispatch.
    class DataExplorationTools(str, Enum): LOAD_FILE = "load_file"
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/OuchiniKaeru/mcp_data_analyzer'

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