save_last_query_to_csv
Exports the complete results of the most recently executed query to a CSV file. Includes column headers and handles null values.
Instructions
Save the last executed query results to a CSV file.
This tool exports the complete results from the most recently executed query
to a CSV file at the specified path. The query must have been executed
successfully and its results must be within the 5GB cache size limit.
Features:
- Exports ALL rows from the last query
- Includes column headers
- Uses comma delimiter
- Handles NULL values as empty strings
- Formats datetime values in ISO format
- Optionally exports the SQL query to a .sql file (enabled by default)
Parameters:
- file_path: Path where the CSV file should be saved (absolute paths recommended)
Note: Relative paths are resolved from the MCP server's working directory
- export_sql: Whether to also export the SQL query to a .sql file (default: true)
Requirements:
- A query must have been executed successfully using execute_query
- Query results must be under 5GB (cache limit)
Examples:
- save_last_query_to_csv("~/Downloads/customers.csv")
- save_last_query_to_csv("/tmp/query_results.csv")
- save_last_query_to_csv("./data/export.csv", export_sql=false)
Notes:
- When export_sql is true, the SQL file will be saved with the same name as the CSV file
but with a .sql extension (e.g., customers.csv → customers.sql)
- The SQL file will be formatted for readability with proper indentationInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| export_sql | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||