query_to_file
Export SQL query results directly to CSV or JSONL files, handling large datasets without loading into context.
Instructions
Execute a SQL query and write the full result to a file (csv or jsonl) instead of returning rows — use this for large exports that must not go through the model context. Relative file_path resolves under the export dir (default /tmp/db-access-mcp/exports); absolute or ~-prefixed paths must fall under the export dir or a configured allow_export_paths root. Parent directories are created. Existing files are not overwritten unless overwrite=true. postgres/mysql stream rows (no row limit by default); redshift/mssql buffer in memory and are capped at 100000 rows.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | SQL text to execute (single statement for streamed dialects) | |
| format | No | Output format; default inferred from the file extension | |
| database | No | Database to export from; required when the connection declares multiple databases | |
| max_rows | No | Optional row cap for the export | |
| file_path | Yes | Target file path: relative to the export dir, or absolute/~ under an allowed export root | |
| overwrite | No | Replace the file if it already exists (default false) | |
| connection | Yes | Connection key from connection_list | |
| timeout_ms | No | Query timeout (default from config) |