Skip to main content
Glama

run_sql

Run a validated read-only PostgreSQL/PostGIS SELECT query when structured spatial tools cannot express your request; returns attributes and GeoJSON geometry with row limits and timeout safeguards.

Instructions

Run a custom READ-ONLY SQL query (single SELECT, PostgreSQL/PostGIS syntax) when the structured tools do not fit. Validated by a SQL parser, executed in a READ ONLY transaction with a timeout and row cap. Geometry columns are returned as GeoJSON (EPSG:4326). Prefer list_layers/describe_layer first; alias every column.

Input Schema

NameRequiredDescriptionDefault
limitNoMax rows to return (default 100; server-side cap applies).
queryYesOne SELECT statement (WITH/UNION allowed). No semicolon-separated batches.
geometryNo'auto' (default): full geometry if small, else representative points; 'full'; 'centroid'; 'none' (attributes only). The complete geometry is always kept server-side under result_id for render_map.auto

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.2.0

TDQS

A4.6/5.0
Behavior5/5

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

With zero annotations, the description carries the full burden and does so: parser validation, READ ONLY transaction, timeout and row cap, GeoJSON/EPSG:4326 conversion, and the fact that full geometry persists server-side under result_id for render_map. The only omissions are the literal timeout/cap values, which are operational rather than decision-critical.

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?

Four compact clauses, front-loaded with the READ-ONLY constraint and the purpose, followed by safety behavior, output format, and usage routing. No sentence is redundant and nothing important is buried at the end.

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?

There is no output schema, so the description must cover returns: it does, specifying GeoJSON geometry at EPSG:4326 and the server-side result_id handoff to render_map. It stops short of describing the general row/column result envelope or error behavior, a minor gap for a 3-parameter tool.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already explains query, limit and geometry including enum meanings and the default of 100. The description adds only one genuinely new constraint ('alias every column') plus the single-statement syntax rule, so the baseline of 3 applies.

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 SQL query, single SELECT, PostgreSQL/PostGIS) and explicitly positions it as the escape hatch when 'the structured tools do not fit', which separates it from siblings like find_features, aggregate and spatial_filter.

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 condition for use ('when the structured tools do not fit') and a named fallback order ('Prefer list_layers/describe_layer first'), so an agent knows both when to reach for it and what to try before it. It also constrains the query shape (single SELECT, alias every column).

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