Skip to main content
Glama

Run a read-only SQL query

query
Read-only

Execute read-only SQL SELECT statements for data analysis. Write the SQL in the target datasource's dialect (get_schema lists every datasource with its dialect). Raw exploration tools do not apply probe redaction and are not bound by schema exposure: they reach any object the datasource credential reaches, and are offered to Administrators, and to members whose Role grants Full; separate access checks apply. Schema exposure governs get_schema, the ontology and approved requests. Rows are positional arrays in columns order. Pass format: "records" for one object per row in returned-column order. Duplicate exact column names collapse to one column at the first position; the surviving value is unspecified. Use unique SQL aliases to preserve every selected value. max_bytes bounds the encoded UTF-8 MCP tool result, after middleware and SDK decoration, including errors, guidance, required protocol metadata, text escaping and whitespace (default 32768; integer 1024–1048576; at most 128 JSON number characters, validated exactly). For requests successfully decoded by the SDK, invalid budgets use a 1024-byte tool-refusal bound. Malformed or overflowing protocol numbers can instead produce SDK JSON-RPC errors before query dispatch, outside CallToolResult and its budget. Infrastructure failures from query remain internal protocol errors with bounded safe text and no source error data. Rows remain a JSON array, one whole row per line. truncated means incomplete output; adapter_truncated and byte_truncated identify the causes. If no row fits, rows is empty with byte_truncated=true; oversized metadata returns result_metadata_exceeds_max_bytes. Failure codes survive diagnostic compaction (diagnostics_omitted); guidance is retained or explicitly refused with guidance_omitted and no query data. Reduce selected columns/rows or raise max_bytes within its bound. For caller-controlled paging use a deterministic unique order and keyset predicate; mutable results require your own snapshot strategy. No cursor or automatic SQL paging is provided.

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": "query"
  }
}

Input Schema

NameRequiredDescriptionDefault
sqlYesSQL SELECT statement to execute
limitNoMax rows to return (default: 100, max: 1000)
formatNoRow format (default: compact)
max_bytesNoMaximum encoded UTF-8 MCP tool-result bytes, including required SDK metadata, escaping and whitespace; default 32768, range 1024–1048576. Excludes JSON-RPC and transport framing.
datasourceNoOptional datasource ID to target. Omit to use the project's configured default; required when the project has multiple datasources and no default is configured. Each datasource has its own SQL dialect: get_schema lists every datasource with its type, dialect and identifier quote, and every result carries datasource_type and dialect. A datasource that has not finished setup is refused with datasource_not_ready. Use datasource (not datasource_id) here; Request authoring uses datasource_id. Unknown top-level arguments and malformed supplied datasource values return invalid_parameters before datasource selection. Supply a nonzero UUID string, or omit datasource intentionally to use the default/sole datasource.
natural_language_contextNoThe natural language question that prompted this query. When provided, the query is saved to history for future reference and learning.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.2/5.0
Behavior5/5

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

Annotations only declare readOnly/idempotent/destructive/openWorld hints; the description goes well beyond them, disclosing the actual access model (raw exploration bypasses probe redaction and schema exposure, limited to Administrators or Full-role members), column-collision behavior with unspecified surviving value, the exact byte accounting for max_bytes, truncation causes (adapter_truncated vs byte_truncated), diagnostic compaction semantics, and the absence of cursors. This is behavioral context an agent could not derive from annotations.

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

Conciseness3/5

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

The core purpose is correctly front-loaded in the first sentence, but the body is a dense run-on sequence of protocol minutiae (SDK JSON-RPC decode failures, 128 JSON number characters, internal protocol errors) that mixes caller-relevant rules with implementation trivia. It is information-rich but poorly partitioned and repetitive with the schema on max_bytes.

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?

There is no output schema, and the description fully compensates: it describes row shape (positional arrays in `columns` order), the records alternative, truncation flags, empty-result behavior, oversized-metadata error code, and failure-code survival. Access prerequisites, dialect prerequisites and paging strategy are all covered for a fairly complex multi-parameter tool.

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 is 3; the description still adds meaning, notably how `format: "records"` orders fields, why duplicate column names collapse and how to avoid it with aliases, and what max_bytes counts (encoded tool-result bytes after middleware, escaping and whitespace, excluding JSON-RPC framing). The `limit` parameter is never discussed in the description, which holds it back from 5.

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

Purpose4/5

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

Opens with a specific verb+resource: "Execute read-only SQL SELECT statements for data analysis," and scopes dialect selection to get_schema. It contrasts itself against schema-exposure surfaces (get_schema, ontology, approved requests), but never distinguishes itself from the sibling `execute` or `explain_query`, so an agent cannot fully disambiguate from name-level evidence alone.

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 operational guidance: omit `datasource` to use the project default, use unique SQL aliases, use keyset predicates with a deterministic unique order for paging, and reduce columns/rows or raise max_bytes when truncated. It does not state when to prefer this over `execute` or `explain_query`, leaving the closest alternatives unresolved.

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