Skip to main content
Glama

load_data

Load data from files in formats like CSV, JSON, or XLSX to enable analysis and visualization within the VisiData environment.

Instructions

Load data from a file using VisiData.

Args: file_path: Path to the data file file_type: Optional file type hint (csv, json, xlsx, etc.)

Returns: String representation of the loaded data structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
file_typeNo

Implementation Reference

  • The load_data tool handler that loads data from files (CSV, JSON, Excel, TSV) using pandas and returns basic dataset information including filename, row count, column count, column names, column types, and file size.
    @mcp.tool()
    def load_data(file_path: str, file_type: Optional[str] = None) -> str:
        """
        Load data from a file using VisiData.
        
        Args:
            file_path: Path to the data file
            file_type: Optional file type hint (csv, json, xlsx, etc.)
        
        Returns:
            String representation of the loaded data structure
        """
        try:
            # Use pandas as a reliable fallback for common formats
            import pandas as pd
            from pathlib import Path
            
            file_extension = Path(file_path).suffix.lower()
            
            # Load with pandas first for reliability
            if file_extension == '.csv':
                df = pd.read_csv(file_path)
            elif file_extension == '.json':
                df = pd.read_json(file_path)
            elif file_extension in ['.xlsx', '.xls']:
                df = pd.read_excel(file_path)
            elif file_extension == '.tsv':
                df = pd.read_csv(file_path, sep='\t')
            else:
                # Try CSV as default
                df = pd.read_csv(file_path)
            
            # Get basic information about the dataset
            info = {
                "filename": Path(file_path).name,
                "rows": len(df),
                "columns": len(df.columns),
                "column_names": list(df.columns)[:10],  # First 10 columns
                "column_types": [str(df[col].dtype) for col in df.columns[:10]],
                "file_size": Path(file_path).stat().st_size if Path(file_path).exists() else 0
            }
            
            return json.dumps(info, indent=2)
            
        except Exception as e:
            return f"Error loading data: {str(e)}\n{traceback.format_exc()}"
  • The @mcp.tool() decorator registers the load_data function as an MCP tool with the server.
    @mcp.tool()
    def load_data(file_path: str, file_type: Optional[str] = None) -> str:

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/moeloubani/visidata-mcp'

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