Skip to main content
Glama
semlayer MCP server

semlayer MCP server

compile_metric

Read-onlyIdempotent

Compile a metric into correct SQL with joins, filters, and time bucketing; use legal alternatives when a request is refused.

Instructions

Compile a metric to correct SQL (joins, filters, time bucketing).

    group_by: comma-separated columns. On refusal the response lists
    legal alternatives — retry with those or ask the user; do NOT
    hand-assemble SQL for a refused request.

    scd: "current" or "asof", required when the join path crosses a
    history table. These are different questions — a customer's segment
    now, or their segment when they ordered — so ask the user which they
    meant rather than guessing.
    

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

Input Schema

NameRequiredDescriptionDefault
scdNo`current` or `asof`. Required when the join path crosses a history table.
nameYesA metric `name` exactly as `get_metrics` returned it.
filterNoAn extra SQL predicate added to the WHERE clause, on top of the metric's own filters.
dialectNoThe SQL dialect to compile to, by its sqlglot name: `duckdb`, `snowflake`, `bigquery`, `postgres`.duckdb
calendarNo`fiscal` or `calendar`. Required for quarter and year grains when the date dimension carries a verified fiscal calendar.
group_byNoColumns to group by, comma-separated. A refusal lists the legal alternatives.
time_endNoExclusive upper bound on the metric's date column, as a date such as `2026-04-01`.
time_grainNo`day`, `week`, `month`, `quarter` or `year`. Omit for no time bucketing.
time_startNoInclusive lower bound on the metric's date column, as a date such as `2026-01-01`.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed9 schema fields changedv0.1.1
    • addedInput schema / properties / calendar / description
      Added value: +"`fiscal` or `calendar`. Required for quarter and year grains when the date dimension carries a verified fiscal calendar."
    • addedInput schema / properties / dialect / description
      Added value: +"The SQL dialect to compile to, by its sqlglot name: `duckdb`, `snowflake`, `bigquery`, `postgres`."
    • addedInput schema / properties / filter / description
      Added value: +"An extra SQL predicate added to the WHERE clause, on top of the metric's own filters."
    • addedInput schema / properties / group_by / description
      Added value: +"Columns to group by, comma-separated. A refusal lists the legal alternatives."
    • addedInput schema / properties / name / description
      Added value: +"A metric `name` exactly as `get_metrics` returned it."
    • addedInput schema / properties / scd / description
      Added value: +"`current` or `asof`. Required when the join path crosses a history table."
    • addedInput schema / properties / time_end / description
      Added value: +"Exclusive upper bound on the metric's date column, as a date such as `2026-04-01`."
    • addedInput schema / properties / time_grain / description
      Added value: +"`day`, `week`, `month`, `quarter` or `year`. Omit for no time bucketing."
    • addedInput schema / properties / time_start / description
      Added value: +"Inclusive lower bound on the metric's date column, as a date such as `2026-01-01`."
  2. First observedv0.1.0

TDQS

A4.1/5.0
Behavior4/5

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

The annotations already declare this as a read-only, idempotent, non-destructive operation, and the description adds meaningful behavioral context beyond them. It discloses that refusals return legal alternatives and that SCD ambiguity should be resolved with the user rather than guessed, which helps the agent handle non-obvious outcomes.

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?

The description is front-loaded with the core action and then addresses the two edge cases that most affect correct invocation. Every sentence carries operational value, and there is no redundant restatement of schema fields.

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?

Given the rich input schema, output schema, and annotations, the description covers the purpose and the key behavioral edge cases an agent needs. It leaves most parameter detail to the schema, which is reasonable at 100% coverage, though it could more explicitly connect to the get_metrics prerequisite.

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, but the description adds useful meaning for group_by and scd. It clarifies that group_by is comma-separated and that refusals list legal alternatives, and it explains that current versus as-of SCD answers different questions, which goes beyond the schema's shorter notes.

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?

The description states a specific verb and resource: 'Compile a metric to correct SQL' with joins, filters, and time bucketing. That clearly distinguishes it from a generic SQL runner, though it does not explicitly name sibling tools such as run_sql or get_metrics.

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?

It gives actionable guidance for two important situations: after a refusal, retry with the listed legal alternatives or ask the user, and never hand-assemble SQL for a refused request. It also says to ask the user whether they mean current or as-of SCD semantics rather than guessing. It does not give broader when-to-use guidance relative to run_sql or check_sql, so it falls short of a 5.

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