export_results_to_csv
Download full query results from Dune Analytics to a local CSV file for analysis and reporting.
Instructions
Download full query results to local CSV.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes |
Implementation Reference
- src/main.py:303-313 (handler)Handler function for 'export_results_to_csv' tool. Registered via @mcp.tool() decorator. Fetches job results using dune_service and exports via data_processor.export_to_csv.@mcp.tool() def export_results_to_csv(job_id: str) -> str: """ Download full query results to local CSV. """ try: raw_result = dune_service.get_result(job_id) path = data_processor.export_to_csv(raw_result, job_id) return f"Success! Data saved to: {path}" except Exception as e: return f"Error exporting data: {str(e)}"
- src/services/data_processor.py:56-73 (helper)Supporting method in DataProcessor class that converts Dune results to pandas DataFrame and saves as CSV file.def export_to_csv(self, result_data: Any, job_id: str) -> str: """ Exports full results to CSV. """ try: rows = result_data.result.rows except AttributeError: rows = result_data if isinstance(result_data, list) else [] if not rows: return "No data to export" df = pd.DataFrame(rows) filename = f"dune_results_{job_id}.csv" filepath = os.path.join(self.export_dir, filename) df.to_csv(filepath, index=False) return filepath