Skip to main content
Glama

run_sql

Read-only

Run one read-only SQL query (SELECT, WITH, WITH RECURSIVE, UNION, window functions) in the DataFusion dialect (https://datafusion.apache.org/user-guide/sql/). DML, DDL, COPY, SET and EXPLAIN are rejected.

Use the table ids (tab-…) and column ids (col-…) describe_table returns, in double quotes. Column NAMES are NOT accepted.

JOINS: no bare CROSS JOIN. Check a result with unlinked_joins before reporting a number from it.

ARRAYS (list_string): array_has(list_col, needle) tests membership, in WHERE or as a JOIN predicate (list first; a membership link carries the exact join_predicate). UNNEST(list_col) in a CTE, then GROUP BY the element, aggregates across lists. An empty list is NULL and array_has(NULL, x) is NULL, so NOT array_has(...) silently drops untagged rows: use NOT COALESCE(array_has(col, x), false). An attachment column is NOT a list: it reads as one text value of file names; filter it with LIKE.

TIME: a - b on timestamps gives an interval AVG/SUM cannot use. Use mycorr_seconds_between(a, b) (Float64 seconds, any Date/Timestamp) or mycorr_days_between(a, b) (Int64 days, two Dates).

_row_id IS selectable and is the handle edit_rows takes; scan order is not row-id order, so ORDER BY when pairing ids across queries.

RESULTS: columns, rows, truncated (also set when a result is too large to hold), served. FLOAT/REAL are 32-bit: cast to DOUBLE.

join_fan_out means a join matched rows of one side more than once while something still depends on that side: confirm the key is unique, or aggregate that side first, before reporting a total. saveable means the result can be kept: create_table with sql writes it once into a new table when it reads one model's tables; create_recipe + materialize_recipe keep it refreshable.

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

Input Schema

NameRequiredDescriptionDefault
sqlYesOne read-only SQL statement, tables and columns by id in double quotes (see the tool description).
max_rowsNoMaximum result rows: default 10000, cap 100000.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.6/5.0
Behavior5/5

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

Annotations only declare readOnlyHint, and the description adds substantial behavior beyond that: the result envelope (columns, rows, truncated, served), truncation semantics, the max_rows default/cap, join_fan_out and saveable diagnostics, and the silent-row-drop hazard with NOT array_has on NULL lists. Consistent with readOnlyHint and materially richer than the annotation.

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-loads the core capability and dialect before the operational rules, and the labeled sections (JOINS, ARRAYS, TIME, RESULTS) make skimming viable. It is long and drifts toward reference material on downstream tooling (saveable/create_recipe), but nearly every line carries non-obvious, decision-relevant content for a SQL tool.

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 no output schema, the description compensates by describing the return envelope and truncation behavior. It covers dialect, identifier format, join validation, array/time pitfalls, type casting, and error diagnostics, which is enough for an agent to construct a correct query and interpret the result.

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 100%, so the baseline would be 3, but the description supplies a hard constraint the schema does not: only tab-…/col-… ids in double quotes are accepted, and column names are rejected outright. max_rows is left to the schema, which already documents default and cap, so the added meaning is real but concentrated in one parameter.

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 one read-only SQL query") plus the exact dialect, and enumerates the accepted statement classes (SELECT, WITH, UNION, window functions) against the rejected ones (DML, DDL, COPY, SET, EXPLAIN). That level of scoping makes it unmistakable next to siblings like search, create_table, or run_recipe.

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 concrete when-not guidance (rejected statement types), prerequisites (table/column ids from describe_table, quoted), and routes to alternatives for follow-on work (unlinked_joins to validate, create_table with sql or create_recipe + materialize_recipe to persist). It never explicitly says when to prefer search or search_units over a raw query, so the alternative routing is partial.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources