You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: switch list_metrics response from JSON to CSV (#709)
Closes#708
## Summary
Switches the `list_metrics` tool response from JSON to CSV format. This
is unconventional, but for this use case — tabular data with potentially
many rows — CSV offers substantial benefits over JSON as LLM context:
- **67% smaller response**: 24,855 chars (JSON) → 8,139 chars (CSV)
- **Up to 33% lower cost** to answer a question end-to-end vs JSON
baseline
- Null/empty fields are omitted dynamically: columns only appear when at
least one metric has a value, keeping output compact by default
- When the CSV still exceeds `DBT_MCP_SL_MAX_RESPONSE_CHARS`, optional
columns (`description`, `metadata`) are stripped as a fallback
### Also included
**Prompt improvements** — guide agents to skip unnecessary
`get_dimensions` calls when `metric_time` is the only dimension needed,
compounding the token savings from the smaller response.
**Where clause fix** — strip surrounding double-quotes that LLMs
sometimes add to the `where` parameter string, preventing `Invalid {{
delimiter` errors from the dbt Semantic Layer's Jinja parser.
body: Reduce list_metrics response size by switching from JSON to CSV format, cutting response size by ~67% and reducing agent cost by up to 33% per query
Copy file name to clipboardExpand all lines: src/dbt_mcp/prompts/semantic_layer/get_dimensions.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
<instructions>
2
2
Get the dimensions for specified metrics
3
3
4
+
Note: `metric_time` is a standard time dimension available on most metrics. You do not need to call this tool just to confirm time dimensions exist — call it only when you need categorical dimensions or specific granularity details. If this tool returns no results, proceed to query directly using `metric_time`.
5
+
4
6
Dimensions are the attributes, features, or characteristics
Copy file name to clipboardExpand all lines: src/dbt_mcp/prompts/semantic_layer/list_metrics.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
1
List metrics from the dbt Semantic Layer.
2
2
3
+
The response is a CSV string with a header row. Columns are dynamic: a column is only present if at least one metric has a non-empty value for it. `name` and `type` are always present; `label`, `description`, `metadata`, `dimensions`, and `entities` are included only when at least one metric has a value. The `dimensions` and `entities` cells contain comma-separated lists of names.
4
+
3
5
When the number of metrics is below the configured threshold (default: 10), each metric includes the names of its available dimensions and entities. Use get_dimensions or get_entities for full details (types, granularities, descriptions) on specific metrics.
4
6
5
-
When above the threshold, only metrics are returned. Use get_dimensions and get_entities with the specific metrics you need.
7
+
When above the threshold, only metrics are returned. `metric_time` is a standard time dimension available on most metrics — you can often query directly without calling `get_dimensions` first. Call `get_dimensions` only when you need non-time dimensions or specific granularity details.
6
8
7
9
If the user is asking a data-related or business-related question, use this tool as a first step.
0 commit comments