export_results_to_csv
Download full Dune Analytics query results to a local CSV file for analysis. Specify the job ID to retrieve and export data.
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)MCP tool handler for 'export_results_to_csv'. Fetches job results using dune_service and exports to CSV using data_processor.export_to_csv. The @mcp.tool() decorator registers it as an MCP tool.@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 in export_dir.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