Skip to main content
Glama
MCPg - Production-grade PostgreSQL MCP Server

MCPg - Production-grade PostgreSQL MCP Server

Run SELECT tuned

run_select_tuned
Read-only

Run read-only SELECTs with a bounded, statement-local work_mem boost for heavy analytical sorts, hash joins, and GROUP BY queries that spill to disk under default settings.

Instructions

Run a read-only SELECT with an elevated, bounded work_mem (and optionally maintenance_work_mem) for THIS statement only. Useful for heavy analytical SELECTs (large sorts / hash joins / GROUP BY) that spill to disk under the default work_mem. The knob is set via SET LOCAL inside the same read-only transaction, so it never leaks back into the pool. Both knobs must match ^\d+(kB|MB|GB)$ and are hard-capped at 2GB (unbounded values are an OOM risk). SQL is validated read-only by the same allowlist as run_select. SET LOCAL only affects transactional statements — non-transactional maintenance (CREATE INDEX CONCURRENTLY, VACUUM) is out of scope.

Example: run_select_tuned(sql='SELECT a, count(*) FROM big GROUP BY a', work_mem='256MB')

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>",
      "work_mem": "<work_mem>"
    },
    "name": "run_select_tuned"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYes
databaseNoOptional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected.
max_rowsNo
work_memYes
maintenance_work_memNo

Output Schema

NameRequiredDescriptionDefault
rowsYes
columnsYes
row_countYes
truncatedYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.4
    • changedInput schema / properties / database / description
      Previous value: -"Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids."New value: +"Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected."
  2. First observedv0.6.8

TDQS

A4.1/5.0
Behavior3/5

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

Annotations already declare readOnlyHint=true and openWorldHint=false, so safety is covered; the description adds genuinely useful behavior beyond that: SET LOCAL scoping inside the same read-only transaction, no leakage back into the pool, allowlist validation identical to run_select, and a hard 2GB cap framed as an OOM safeguard. These are real operational constraints an agent could not infer from annotations or schema.

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

Conciseness4/5

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

Front-loaded with the core purpose, then constraints, then a concrete call example — every sentence carries information. It is dense and parenthesis-heavy, and the out-of-scope note trails at the end, but nothing is redundant.

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

Completeness4/5

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

For a read-only tool with annotations and an output schema, the description covers the mechanism, hard limits, validation and scope exclusions; return values needn't be explained. The only missing piece an agent would want is what `max_rows` does and whether the 2GB/allowlist limits are configurable.

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 only 20% (just `database`), so the description has to carry the load and largely does: it specifies that both knobs use `^\d+(kB|MB|GB)$`, are capped at 2GB, and that `maintenance_work_mem` is optional, plus it notes `sql` is read-only-validated. The gap is `max_rows` (default 1000), which neither the schema nor the description explains.

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 resource ("Run a read-only SELECT") plus the defining trait that separates it from siblings: a per-statement elevated, bounded `work_mem`. The reader instantly understands this is run_select with a tuned memory knob, not a generic query runner.

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

Usage Guidelines4/5

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

Gives explicit when-to-use ("heavy analytical SELECTs (large sorts / hash joins / GROUP BY) that spill to disk under the default work_mem") and an explicit when-not ("non-transactional maintenance (CREATE INDEX CONCURRENTLY, VACUUM) is out of scope"). What it never does is name run_select or run_select_parallel as the fallback for ordinary or parallel queries, leaving that routing to inference.

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

Deploy Server

Other Tools