Skip to main content
Glama

Export a query to a file

pg_export_query
Read-onlyIdempotent

Run read-only PostgreSQL queries and export large results to CSV, JSON, or JSON Lines files instead of returning rows, with only the file path, row count, and size reported.

Instructions

Run a read-only query and save the result to a local file (CSV, JSON or JSON Lines) instead of sending the rows to the conversation. Use it for results too big to read: the answer holds only the path, the row count and the size.

The query goes through the same safety checks as pg_query (one statement, read only, protected columns refused, credential-like columns redacted); use params ($1, $2, ...) for values. filename is a plain file name, written to the connection's export folder (default ~/pgharbor-exports). Up to max_rows rows, never more than 100,000; the file is not overwritten unless overwrite=true. Exports can be turned off per connection.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "sql": "<sql>",
      "filename": "<filename>"
    },
    "name": "pg_export_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYes
formatNocsv
paramsNo
filenameYes
max_rowsNo
overwriteNo
connectionNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well past the annotations: it discloses the safety pipeline (single statement, read-only, protected columns refused, credential-like columns redacted), the destination folder and its default (~/pgharbor-exports), the hard 100,000-row cap, overwrite protection, and that exports can be disabled per connection. This tells the agent what gets written, where, and under what constraints — a write-to-disk behavior the readOnlyHint does not convey.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three tight paragraphs: purpose first, safety/binding context second, file-handling details third. No filler, and the critical contrast with pg_query is front-loaded in the first sentence.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With 7 parameters, no output schema, and no schema descriptions, this tool needed a lot of prose — and the description supplies it, including what the response contains (path, row count, size), which substitutes for the missing output schema. Nothing an agent needs to invoke it correctly appears absent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must carry the load, and it largely does: `filename` is a bare name placed in the export folder, `params` are positional $1/$2 bind values, `max_rows` is capped at 100,000, `overwrite` must be set true to replace a file, and `format` is enumerated by name. The `connection` parameter is only obliquely referenced ('the connection's export folder', 'turned off per connection') without stating what values it accepts or that it selects the target database.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and outcome — run a read-only query and write the result to a local file rather than returning rows — plus the supported formats (CSV, JSON, JSON Lines). It clearly delineates itself from the pg_query sibling by contrast: 'instead of sending the rows to the conversation'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives an explicit when-to-use trigger ('results too big to read') and names the contrasting alternative (pg_query, whose rows come into the conversation, and whose safety checks this tool shares). An agent can decide between the two without opening either schema.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.