load_and_analyze_data
Load and analyze data files from local paths or URLs in formats like CSV, JSON, Excel, and Parquet to extract DataFrame information and metadata for data understanding.
Instructions
Use to understand local or remote data files. Must be called with absolute paths or URLs.
Supported formats:
- CSV (.csv)
- JSON (.json)
- HTML (.html, .htm)
- Excel (.xls, .xlsx)
- OpenDocument Spreadsheet (.ods)
- Parquet (.parquet)
Returns:
DataAnalysisResults object containing DataFrame information and metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path_or_url | Yes | Absolute (important!) local file path or URL to a data file |
Implementation Reference
- The primary handler function for the 'load_and_analyze_data' tool. It is decorated with @mcp.tool() for registration in the FastMCP server. This function loads data from local or remote paths/URLs, analyzes it, and returns structured results including DataFrame info and metadata.@mcp.tool() def load_and_analyze_data( path_or_url: str = Field(description="Absolute (important!) local file path or URL to a data file"), ) -> DataAnalysisResults: """Use to understand local or remote data files. Must be called with absolute paths or URLs. Supported formats: - CSV (.csv) - JSON (.json) - HTML (.html, .htm) - Excel (.xls, .xlsx) - OpenDocument Spreadsheet (.ods) - Parquet (.parquet) Returns: DataAnalysisResults object containing DataFrame information and metadata """ # Handle files and URLs path_or_url_type = path_or_url_check(path_or_url) mime_type, _ = mimetypes.guess_type(str(path_or_url)) processed_path_or_url = path_or_url if path_or_url_type == "remote": processed_path_or_url = convert_github_url_to_raw(path_or_url) elif path_or_url_type == "local": processed_path_or_url = Path(path_or_url) else: return DataAnalysisResults(valid=False, message="Invalid path or URL", df_info=None, df_metadata=None) try: df, read_fn = load_dataframe_by_format(processed_path_or_url, mime_type) except Exception as e: return DataAnalysisResults( valid=False, message=f"""Failed to load data: {e!s}. Remember to use the ABSOLUTE path or URL! Alternatively, you can use any data analysis means available to you. Most important information are the column names and column types for passing along to the `validate_dashboard_config` or `validate_chart_code` tools.""", df_info=None, df_metadata=None, ) df_info = get_dataframe_info(df) df_metadata = DFMetaData( file_name=Path(path_or_url).stem if isinstance(processed_path_or_url, Path) else Path(path_or_url).name, file_path_or_url=str(processed_path_or_url), file_location_type=path_or_url_type, read_function_string=read_fn, ) return DataAnalysisResults(valid=True, message="Data loaded successfully", df_info=df_info, df_metadata=df_metadata)
- Dataclass defining the output schema for the load_and_analyze_data tool.class DataAnalysisResults: """Results of the data analysis tool.""" valid: bool message: str df_info: DFInfo | None df_metadata: DFMetaData | None