Skip to main content
Glama

Generate SQL for a metric

generate_query
Read-onlyIdempotent

Generates parameterized warehouse SQL for one GASP Standard metric from its canonical formula and your adapter mapping, enabling period-filtered metric queries with optional breakdown rows.

Instructions

SQL for one GASP Standard metric against your warehouse, compiled from its canonical formula and filled from your adapter: one scalar subquery per aggregate, each reading the table mapped to its GASP dataset, with :period_start and :period_end date parameters (both inclusive). Pairs you have not mapped stay as {{field@dataset}} placeholders, where the tag names the GASP dataset the column must come from; the output lists them with any dataset that has no table and any mapping conflict, plus the URL, dialect, datasets, grain and the mapping it used. breakdown names a breakdown the metric declares (get_formula lists them, e.g. 'by_plan' on MRR) and returns one row per value. The dialect (postgres, snowflake, bigquery or databricks; postgres also covers Redshift) is the dialect argument, else the adapter's warehouse when it names one of them, else postgres. Check the mapping with validate_mapping first.

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": {
      "metric": "<metric>",
      "adapter": "<adapter>"
    },
    "name": "generate_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
metricYesExact metric name, abbreviation, alias or formula id (e.g. 'NRR', 'CAC', 'Pipeline Value', 'ARR'), resolved as in lookup_metric
adapterYesYour mapping as text: a GASP adapter (JSON; schema: https://gaspwiki.com/schemas/gasp-adapter-v1.json) or an Ossie mapping document (YAML or JSON). Check it with validate_mapping first.
dialectNoSQL dialect: postgres (also Redshift), snowflake, bigquery or databricks. Omit to use the adapter's warehouse when it names one of them (postgresql and redshift read as postgres), else postgres.
breakdownNoName of a breakdown the metric declares (e.g. 'by_plan' on MRR). The query returns one row per value of the breakdown's field or bucket. An unknown name lists the declared ones.
semantic_modelNoWith an Ossie mapping: your semantic model document (YAML or JSON), so table names and field expressions resolve. Ignored for a GASP adapter.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.4/5.0
Behavior5/5

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

Annotations already declare this a safe, idempotent read, and the description still adds substantial behavior: :period_start/:period_end are inclusive, unmapped pairs survive as {{field@dataset}} placeholders with the dataset tag semantics, and the response enumerates placeholders, table-less datasets, mapping conflicts, URL, dialect, datasets, grain and the mapping used. The dialect resolution precedence (argument → adapter warehouse → postgres, with Redshift mapping to postgres) is fully disclosed.

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 purpose and packed with useful specifics, with essentially no filler. The mid-section sentence about placeholders is a long run-on that mixes three separate behaviors (placeholder syntax, output listing, conflict reporting), costing some readability.

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 takes on the burden of describing the return payload — and does so, listing the generated SQL plus diagnostics. For a 5-parameter tool with conditional dialect and mapping modes, nothing an agent needs before calling it correctly is missing.

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 coverage is 100%, so parameter meaning is already largely carried by the schema, including the dialect fallback chain and breakdown behavior. The description reinforces breakdown row cardinality and the placeholder/semantic_model interaction but adds little beyond what the parameter descriptions already state; baseline 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?

Opens with a precise verb+resource+scope: 'SQL for one GASP Standard metric against your warehouse, compiled from its canonical formula and filled from your adapter.' This clearly separates it from get_formula (canonical formula only) and validate_mapping (mapping checking), so an agent can pick it without opening the schema.

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?

Explicitly states the prerequisite 'Check the mapping with validate_mapping first' and routes breakdown names to get_formula ('get_formula lists them'). It does not spell out when to avoid this tool (e.g., previewing a formula rather than generating SQL), so it falls just short of a full when/when-not treatment.

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