@lightdash-tools/mcp 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/profiles/semantic-layer/v1/prompts.js +3 -3
- package/dist/profiles/semantic-layer/v1/resources/playbooks/compose-compile.md +6 -3
- package/dist/profiles/semantic-layer/v1/resources/playbooks/core.md +1 -1
- package/dist/tools/semantic/explore-helpers.d.ts +6 -0
- package/dist/tools/semantic/explore-helpers.js +43 -0
- package/dist/tools/semantic/explore-helpers.test.js +17 -0
- package/dist/tools/semantic/query.js +9 -19
- package/dist/tools/semantic/query.test.js +71 -0
- package/package.json +3 -3
|
@@ -71,7 +71,7 @@ Procedure:
|
|
|
71
71
|
1. If exploreId is missing, resolve it per explore playbook (search + disambiguation). Stay on this projectUuid.
|
|
72
72
|
2. Copy fieldIds from list_dimensions and {exploreId}_{metricName} from get_explore → tables[baseTable].metrics. Never invent grains.
|
|
73
73
|
3. If the user asked for N insights, reuse one explore and compile N diverse cuts.
|
|
74
|
-
4. Build metricQuery from the compose-compile skeleton (fieldIds only; tool sets exploreName from exploreId and defaults missing tableCalculations to []). After each compile, verify every requested fieldId appears as a SELECT alias (missing alias = failure even without isError). Prefer SELECT aliases over metric name/label. ≤2 fix retries.
|
|
74
|
+
4. Build metricQuery from the compose-compile skeleton (fieldIds only; tool sets exploreName from exploreId and defaults missing tableCalculations and sorts to []). After each compile, verify every requested fieldId appears as a SELECT alias (missing alias = failure even without isError). Prefer SELECT aliases over metric name/label. ≤2 fix retries.
|
|
75
75
|
5. Deliverable: insight title(s) + fieldIds + compiled SQL (or errors). Never paste full explore/dimension/metric/lineage payloads.`,
|
|
76
76
|
invariantIds,
|
|
77
77
|
requiredTopics: [TOPIC_COMPOSE_COMPILE],
|
|
@@ -95,8 +95,8 @@ Explore: ${exploreId}
|
|
|
95
95
|
${err}
|
|
96
96
|
|
|
97
97
|
Checklist:
|
|
98
|
-
- unknown field id / empty SELECT / missing SELECT alias → use fieldIds from list_dimensions (base table) + explore-local metrics; re-compile (≤2 retries). Prefer SELECT aliases / compiledSql over metric name/label.
|
|
99
|
-
- Other OpenAPI-required keys still failing (filters,
|
|
98
|
+
- unknown field id / empty SELECT / missing SELECT alias / SQL ERROR comment → use fieldIds from list_dimensions (base table; STRUCT dots → __; ARRAY via baseTableOnly=false) + explore-local metrics; re-compile (≤2 retries). Prefer SELECT aliases / compiledSql over metric name/label.
|
|
99
|
+
- Other OpenAPI-required keys still failing (filters, limit, …) → copy the compose-compile skeleton; MCP fills exploreName and missing tableCalculations / sorts.
|
|
100
100
|
- Wrong explore → re-disambiguate (schemaName; label or name __{table}; skip empty schema / eda unless asked).
|
|
101
101
|
- Metric not found / catalog empty → get_explore tables[baseTable].metrics; tableName must be the full explore id; compile as {exploreId}_{metricName}.
|
|
102
102
|
- Verify SELECT aliases after every compile. Stop after a good compile or a clear blocker.`,
|
|
@@ -25,7 +25,7 @@ URI: `lightdash://playbooks/semantic-layer/compose-compile`
|
|
|
25
25
|
|
|
26
26
|
`metrics` may be `[]`. Every string in `dimensions` / `metrics` / `sorts[].fieldId` must appear in prior tool output.
|
|
27
27
|
|
|
28
|
-
MCP `compile_query` always sets `exploreName` from the tool `exploreId` (path is authoritative), defaults missing `tableCalculations` to `[]`, and **fills missing FilterGroup/FilterRule `id`s** (does not invent wrappers for unknown shapes). Keep the full skeleton for other OpenAPI-required keys (`filters`, `
|
|
28
|
+
MCP `compile_query` always sets `exploreName` from the tool `exploreId` (path is authoritative), defaults missing `tableCalculations` and `sorts` to `[]`, and **fills missing FilterGroup/FilterRule `id`s** (does not invent wrappers for unknown shapes). Keep the full skeleton for other OpenAPI-required keys (`filters`, `limit`, …) and for CLI/JSON callers. Prefer SELECT aliases / metric `compiledSql` over metric **name/label** when they disagree.
|
|
29
29
|
|
|
30
30
|
When filters are non-empty, prefer an explicit FilterGroup:
|
|
31
31
|
|
|
@@ -56,10 +56,13 @@ MCP may inject missing `id`s; still copy this shape so non-MCP clients and hosts
|
|
|
56
56
|
| `unknown field id` / hard error | Short names or typos | Use full `fieldId` from `list_dimensions` / `{exploreId}_{metricName}` |
|
|
57
57
|
| Server `isError` + empty SELECT | Upstream accepted bad ids with **zero** columns | Replace with real fieldIds; re-compile once |
|
|
58
58
|
| Server `isError` + missing SELECT aliases | Invented id, dotted STRUCT id (`…_customer.first_name` vs `…_customer__first_name`), or ARRAY join id without `baseTableOnly=false` | Copy `fieldId` from `list_dimensions` (STRUCT dots → `__`; ARRAY via join tables); re-compile |
|
|
59
|
+
| Server `isError` + compiled SQL `/* ERROR:` comment | Unknown filter (or other) fieldId; Lightdash embeds an ERROR comment while still returning SQL | Copy filter `fieldId`s from `list_dimensions`; re-compile |
|
|
59
60
|
| SQL “succeeds” but a requested dim/metric is **missing** from SELECT | Invented or wrong fieldId while another field still projected (pre-guard / non-MCP clients) | Re-check against `list_dimensions` / metrics map; re-compile |
|
|
60
61
|
| `UPSTREAM_VALIDATION` / `'tableCalculations' is required` | Body omitted `tableCalculations` (pre-harden / non-MCP clients) | MCP defaults to `[]`; pass `tableCalculations: []` explicitly if needed |
|
|
62
|
+
| `UPSTREAM_VALIDATION` / `'sorts' is required` | Body omitted `sorts` (pre-harden / non-MCP clients) | MCP defaults to `[]`; pass `sorts: []` explicitly if needed |
|
|
61
63
|
| `UPSTREAM_VALIDATION` / `'exploreName' is required` | Body omitted `exploreName` (pre-harden / non-MCP clients) or wrong exploreId | Pass locked `exploreId`; MCP fills `exploreName` — re-compile once |
|
|
62
64
|
| `UPSTREAM_VALIDATION` on `filters.dimensions` (`'id'/'or' required`) | FilterGroup missing top-level `id` (rules alone are not enough; pre-harden / non-MCP) | Prefer `{ "id": "…", "and": [ { "id": "…", "target": { "fieldId": "…" }, "operator": "…", "values": […] } ] }`; MCP fills missing ids |
|
|
65
|
+
| `UPSTREAM_VALIDATION` / operator `should be one of …` | Invented operator (e.g. `isNotNull`) | Use `notNull` / `isNull` (not `isNotNull`) |
|
|
63
66
|
| `Metric not found` on `get_metric` | `tableName` was warehouse label | Use full explore id |
|
|
64
67
|
| Lineage works with short name but compile fails | `get_field_lineage` accepts short names; `compile_query` does not | Always copy full `fieldId` into `metricQuery` |
|
|
65
68
|
|
|
@@ -67,7 +70,7 @@ Compiled SQL may include **extra related metrics** the semantic layer pulls in
|
|
|
67
70
|
|
|
68
71
|
## Verify after every compile (mandatory)
|
|
69
72
|
|
|
70
|
-
MCP `compile_query` sets `isError` when the SELECT is empty or when requested `dimensions` / `metrics` are missing from SELECT aliases. Still verify locally (belt-and-suspenders for hosts that ignore `isError`):
|
|
73
|
+
MCP `compile_query` sets `isError` when the SELECT is empty, when compiled SQL embeds a `/* ERROR:` comment (e.g. unknown filter fieldId), or when requested `dimensions` / `metrics` are missing from SELECT aliases. Still verify locally (belt-and-suspenders for hosts that ignore `isError`):
|
|
71
74
|
|
|
72
75
|
1. Parse the compiled `query` SELECT list (aliases / AS names).
|
|
73
76
|
2. Confirm **each** requested dimension and metric `fieldId` is present.
|
|
@@ -86,7 +89,7 @@ When the user asks for N insights on one table/explore:
|
|
|
86
89
|
## Debug checklist
|
|
87
90
|
|
|
88
91
|
- Unknown field id / short names / empty SELECT / missing SELECT alias → fix fieldIds from `list_dimensions` + explore-local metrics; re-compile (≤2 retries). Prefer SELECT aliases / `compiledSql` over metric name/label.
|
|
89
|
-
- Other OpenAPI-required keys still failing (`filters`, `
|
|
92
|
+
- Other OpenAPI-required keys still failing (`filters`, `limit`, …) → copy the skeleton; MCP already fills `exploreName`, missing `tableCalculations` / `sorts`, and missing filter `id`s.
|
|
90
93
|
- Wrong explore → re-disambiguate (`schemaName`; exact `label` or `name` `__{table}`; skip empty schema / eda unless asked).
|
|
91
94
|
- Catalog empty / metric not found → `get_explore` `tables[baseTable].metrics`; compile as `{exploreId}_{metricName}`.
|
|
92
95
|
- Stop after a good verified compile or a clear blocker.
|
|
@@ -38,7 +38,7 @@ Record when a budget stopped you.
|
|
|
38
38
|
| `list_dimensions` | Compact `{ name, label, table, type, fieldId }`. Default = base table only. Use `baseTableOnly=false` for ordinary joins **and** ARRAY UNNEST tables (`{base}__{column}`). |
|
|
39
39
|
| `get_explore` | **Preferred** metric menu: `tables[baseTable].metrics` names/labels only. Ignore join **metrics**; joined/ARRAY dims via `list_dimensions` (`baseTableOnly=false`) when needed. |
|
|
40
40
|
| `list_metrics` / `get_metric` | Optional catalog / definition dig. Filter `tableName === exploreId`. |
|
|
41
|
-
| `compile_query` | Compile only — never “run”. Sets `exploreName` from `exploreId`; defaults missing `tableCalculations` to `[]`. Prefer compiled SQL aliases over metric labels.
|
|
41
|
+
| `compile_query` | Compile only — never “run”. Sets `exploreName` from `exploreId`; defaults missing `tableCalculations` and `sorts` to `[]`. Prefer compiled SQL aliases over metric labels. |
|
|
42
42
|
| `get_field_lineage` | Optional provenance; summarize, don’t dump. |
|
|
43
43
|
|
|
44
44
|
## Project scope (critical)
|
|
@@ -57,6 +57,10 @@ export declare function summarizeDimensions(dimensions: readonly DimensionLike[]
|
|
|
57
57
|
}): DimensionSummary[];
|
|
58
58
|
/** True when compiled SQL has an empty projection (SELECT … FROM with no columns). */
|
|
59
59
|
export declare function isEmptySelectSql(sql: string): boolean;
|
|
60
|
+
/** Body of the first Lightdash ERROR block comment (`ERROR:…`), if present. */
|
|
61
|
+
export declare function extractCompileSqlErrorComment(sql: string): string | undefined;
|
|
62
|
+
/** True when Lightdash embedded a compile failure comment (e.g. unknown filter fieldId). */
|
|
63
|
+
export declare function hasCompileSqlErrorComment(sql: string): boolean;
|
|
60
64
|
/**
|
|
61
65
|
* Collect SELECT aliases from compiled SQL (`AS \`alias\``, `AS "alias"`, or `AS alias`).
|
|
62
66
|
* Heuristic only (not a SQL parser): stops at the first FROM; CAST(... AS type) may
|
|
@@ -72,6 +76,8 @@ export declare function extractSelectAliases(sql: string): string[];
|
|
|
72
76
|
export declare function findMissingFieldIds(requested: readonly string[], sql: string): string[];
|
|
73
77
|
/** Collect string fieldIds from metricQuery.dimensions and metricQuery.metrics. */
|
|
74
78
|
export declare function collectRequestedFieldIds(metricQuery: Record<string, unknown>): string[];
|
|
79
|
+
/** Diagnose post-compile SQL for agents. Returns error text, or undefined when OK. */
|
|
80
|
+
export declare function diagnoseCompiledSql(sql: string | undefined, requestedFieldIds: readonly string[]): string | undefined;
|
|
75
81
|
/** Extract SQL text from a compile_query API payload. */
|
|
76
82
|
export declare function extractCompiledSql(result: unknown): string | undefined;
|
|
77
83
|
export {};
|
|
@@ -9,9 +9,12 @@ exports.flattenExploreDimensions = flattenExploreDimensions;
|
|
|
9
9
|
exports.toFieldId = toFieldId;
|
|
10
10
|
exports.summarizeDimensions = summarizeDimensions;
|
|
11
11
|
exports.isEmptySelectSql = isEmptySelectSql;
|
|
12
|
+
exports.extractCompileSqlErrorComment = extractCompileSqlErrorComment;
|
|
13
|
+
exports.hasCompileSqlErrorComment = hasCompileSqlErrorComment;
|
|
12
14
|
exports.extractSelectAliases = extractSelectAliases;
|
|
13
15
|
exports.findMissingFieldIds = findMissingFieldIds;
|
|
14
16
|
exports.collectRequestedFieldIds = collectRequestedFieldIds;
|
|
17
|
+
exports.diagnoseCompiledSql = diagnoseCompiledSql;
|
|
15
18
|
exports.extractCompiledSql = extractCompiledSql;
|
|
16
19
|
/** Map a summary explore to a compact MCP payload (drops fat explore fields). */
|
|
17
20
|
function toExploreSummary(explore) {
|
|
@@ -112,6 +115,17 @@ function isEmptySelectSql(sql) {
|
|
|
112
115
|
const normalized = sql.replace(/\s+/g, ' ').trim();
|
|
113
116
|
return /SELECT FROM\b/i.test(normalized);
|
|
114
117
|
}
|
|
118
|
+
/** Body of the first Lightdash ERROR block comment (`ERROR:…`), if present. */
|
|
119
|
+
function extractCompileSqlErrorComment(sql) {
|
|
120
|
+
var _a;
|
|
121
|
+
const match = /\/\*\s*(ERROR:[\s\S]*?)\*\//i.exec(sql);
|
|
122
|
+
const body = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
123
|
+
return body && body.length > 0 ? body : undefined;
|
|
124
|
+
}
|
|
125
|
+
/** True when Lightdash embedded a compile failure comment (e.g. unknown filter fieldId). */
|
|
126
|
+
function hasCompileSqlErrorComment(sql) {
|
|
127
|
+
return extractCompileSqlErrorComment(sql) !== undefined;
|
|
128
|
+
}
|
|
115
129
|
/**
|
|
116
130
|
* Collect SELECT aliases from compiled SQL (`AS \`alias\``, `AS "alias"`, or `AS alias`).
|
|
117
131
|
* Heuristic only (not a SQL parser): stops at the first FROM; CAST(... AS type) may
|
|
@@ -167,6 +181,35 @@ function collectRequestedFieldIds(metricQuery) {
|
|
|
167
181
|
}
|
|
168
182
|
return requested;
|
|
169
183
|
}
|
|
184
|
+
const COMPILED_SQL_FIELD_ID_HINT = 'Copy fieldIds from list_dimensions (STRUCT name dots → `__`; ARRAY via join tables with ' +
|
|
185
|
+
'baseTableOnly=false) and explore-local metrics; re-compile.';
|
|
186
|
+
/** Diagnose post-compile SQL for agents. Returns error text, or undefined when OK. */
|
|
187
|
+
function diagnoseCompiledSql(sql, requestedFieldIds) {
|
|
188
|
+
if (!sql)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (isEmptySelectSql(sql)) {
|
|
191
|
+
return ('Error: compile_query produced an empty SELECT (no columns). ' +
|
|
192
|
+
'Use fieldId values like `{table}_{name}` from list_dimensions (base table; nested dots → `__`), ' +
|
|
193
|
+
'not short field names. Re-compile after fixing metricQuery.');
|
|
194
|
+
}
|
|
195
|
+
const errorComment = extractCompileSqlErrorComment(sql);
|
|
196
|
+
if (errorComment) {
|
|
197
|
+
return ('Error: compile_query SQL contains a Lightdash `/* ERROR:` comment ' +
|
|
198
|
+
'(often an unknown filter fieldId). ' +
|
|
199
|
+
COMPILED_SQL_FIELD_ID_HINT +
|
|
200
|
+
'\nLightdash: /* ' +
|
|
201
|
+
errorComment +
|
|
202
|
+
' */');
|
|
203
|
+
}
|
|
204
|
+
const missing = findMissingFieldIds(requestedFieldIds, sql);
|
|
205
|
+
if (missing.length > 0) {
|
|
206
|
+
return ('Error: compile_query SQL is missing SELECT aliases for requested fieldIds: ' +
|
|
207
|
+
missing.join(', ') +
|
|
208
|
+
'. ' +
|
|
209
|
+
COMPILED_SQL_FIELD_ID_HINT);
|
|
210
|
+
}
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
170
213
|
/** Extract SQL text from a compile_query API payload. */
|
|
171
214
|
function extractCompiledSql(result) {
|
|
172
215
|
if (typeof result === 'string')
|
|
@@ -202,6 +202,23 @@ const explore_helpers_js_1 = require("./explore-helpers.js");
|
|
|
202
202
|
(0, vitest_1.expect)((0, explore_helpers_js_1.extractCompiledSql)('raw')).toBe('raw');
|
|
203
203
|
});
|
|
204
204
|
});
|
|
205
|
+
(0, vitest_1.describe)('hasCompileSqlErrorComment / extractCompileSqlErrorComment', () => {
|
|
206
|
+
(0, vitest_1.it)('detects Lightdash unknown-dimension ERROR comments in compiled SQL', () => {
|
|
207
|
+
const sql = `SELECT
|
|
208
|
+
\`orders_nested_demo\`.status AS \`orders_nested_demo_status\`
|
|
209
|
+
FROM orders
|
|
210
|
+
WHERE ((
|
|
211
|
+
/* ERROR: Filter has a reference to an unknown dimension: orders_nested_demo_customer.first_name */ orders_nested_demo_customer.first_name equals ("Anna")
|
|
212
|
+
))
|
|
213
|
+
GROUP BY 1`;
|
|
214
|
+
(0, vitest_1.expect)((0, explore_helpers_js_1.hasCompileSqlErrorComment)(sql)).toBe(true);
|
|
215
|
+
(0, vitest_1.expect)((0, explore_helpers_js_1.extractCompileSqlErrorComment)(sql)).toContain('unknown dimension: orders_nested_demo_customer.first_name');
|
|
216
|
+
(0, vitest_1.expect)((0, explore_helpers_js_1.hasCompileSqlErrorComment)('SELECT 1 /* note */ FROM t')).toBe(false);
|
|
217
|
+
(0, vitest_1.expect)((0, explore_helpers_js_1.hasCompileSqlErrorComment)('SELECT 1 FROM t')).toBe(false);
|
|
218
|
+
(0, vitest_1.expect)((0, explore_helpers_js_1.hasCompileSqlErrorComment)('/*ERROR: bare */ SELECT 1')).toBe(true);
|
|
219
|
+
(0, vitest_1.expect)((0, explore_helpers_js_1.extractCompileSqlErrorComment)('/*ERROR: bare */ SELECT 1')).toBe('ERROR: bare');
|
|
220
|
+
});
|
|
221
|
+
});
|
|
205
222
|
(0, vitest_1.describe)('extractSelectAliases / findMissingFieldIds', () => {
|
|
206
223
|
const sampleSql = `
|
|
207
224
|
SELECT
|
|
@@ -17,7 +17,7 @@ const schema_fields_js_2 = require("./schema-fields.js");
|
|
|
17
17
|
function registerCompileQuery(server, contextProvider) {
|
|
18
18
|
(0, shared_js_1.registerToolSafe)(server, 'compile_query', {
|
|
19
19
|
title: 'Compile query',
|
|
20
|
-
description: 'Compile a metric query for an explore without executing it. Sets metricQuery.exploreName from exploreId (authoritative), defaults missing tableCalculations to [], and fills missing FilterGroup/FilterRule ids. Use fieldIds from list_dimensions (`{table}_{name}` with nested dots in name replaced by `__`). Empty SELECT or requested dimensions/metrics missing from SELECT aliases return isError. projectUuid optional when X-Lightdash-Project is set.',
|
|
20
|
+
description: 'Compile a metric query for an explore without executing it. Sets metricQuery.exploreName from exploreId (authoritative), defaults missing tableCalculations and sorts to [], and fills missing FilterGroup/FilterRule ids. Use fieldIds from list_dimensions (`{table}_{name}` with nested dots in name replaced by `__`). Empty SELECT, compiled SQL `/* ERROR:` comments (e.g. unknown filter fieldId), or requested dimensions/metrics missing from SELECT aliases return isError. projectUuid optional when X-Lightdash-Project is set.',
|
|
21
21
|
inputSchema: {
|
|
22
22
|
projectUuid: (0, schema_fields_js_1.optionalProjectUuidField)(),
|
|
23
23
|
exploreId: (0, schema_fields_js_2.exploreIdField)(),
|
|
@@ -30,28 +30,18 @@ function registerCompileQuery(server, contextProvider) {
|
|
|
30
30
|
var _a;
|
|
31
31
|
try {
|
|
32
32
|
const scope = (0, project_scope_js_1.resolveProjectScope)({ projectUuid });
|
|
33
|
-
// Path exploreId is authoritative; OpenAPI MetricQuery requires exploreName + tableCalculations.
|
|
33
|
+
// Path exploreId is authoritative; OpenAPI MetricQuery requires exploreName + tableCalculations + sorts.
|
|
34
34
|
const body = Object.assign(Object.assign({}, metricQuery), { filters: (0, ensure_filter_ids_js_1.ensureFilterIds)((_a = metricQuery.filters) !== null && _a !== void 0 ? _a : {}), tableCalculations: Array.isArray(metricQuery.tableCalculations)
|
|
35
35
|
? metricQuery.tableCalculations
|
|
36
|
-
: [], exploreName: exploreId });
|
|
36
|
+
: [], sorts: Array.isArray(metricQuery.sorts) ? metricQuery.sorts : [], exploreName: exploreId });
|
|
37
37
|
const result = await c.v1.query.compileQuery(scope.projectUuid, exploreId, body);
|
|
38
38
|
const sql = (0, explore_helpers_js_1.extractCompiledSql)(result);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
'Use fieldId values like `{table}_{name}` from list_dimensions (base table; nested dots → `__`), ' +
|
|
46
|
-
'not short field names. Re-compile after fixing metricQuery.');
|
|
47
|
-
}
|
|
48
|
-
if (sql) {
|
|
49
|
-
const missing = (0, explore_helpers_js_1.findMissingFieldIds)((0, explore_helpers_js_1.collectRequestedFieldIds)(metricQuery), sql);
|
|
50
|
-
if (missing.length > 0) {
|
|
51
|
-
return sqlError('Error: compile_query SQL is missing SELECT aliases for requested fieldIds: ' +
|
|
52
|
-
`${missing.join(', ')}. ` +
|
|
53
|
-
'Copy fieldIds from list_dimensions (nested name dots become `__`) and explore-local metrics; re-compile.');
|
|
54
|
-
}
|
|
39
|
+
const diagnosis = (0, explore_helpers_js_1.diagnoseCompiledSql)(sql, (0, explore_helpers_js_1.collectRequestedFieldIds)(metricQuery));
|
|
40
|
+
if (diagnosis) {
|
|
41
|
+
return {
|
|
42
|
+
content: [{ type: 'text', text: diagnosis }],
|
|
43
|
+
isError: true,
|
|
44
|
+
};
|
|
55
45
|
}
|
|
56
46
|
return (0, shared_js_1.jsonToolResult)(result);
|
|
57
47
|
}
|
|
@@ -88,6 +88,36 @@ function createCompileHandler(compileQuery) {
|
|
|
88
88
|
(0, vitest_1.expect)(result.isError).toBe(true);
|
|
89
89
|
(0, vitest_1.expect)(result.content[0].text).toContain('empty SELECT');
|
|
90
90
|
});
|
|
91
|
+
(0, vitest_1.it)('returns isError when compiled SQL embeds an ERROR comment', async () => {
|
|
92
|
+
const compileQuery = vitest_1.vi.fn().mockResolvedValue({
|
|
93
|
+
query: `SELECT
|
|
94
|
+
\`orders\`.status AS \`orders_status\`
|
|
95
|
+
FROM orders
|
|
96
|
+
WHERE ((
|
|
97
|
+
/* ERROR: Filter has a reference to an unknown dimension: orders_customer.first_name */ x
|
|
98
|
+
))
|
|
99
|
+
GROUP BY 1`,
|
|
100
|
+
});
|
|
101
|
+
const { handler } = createCompileHandler(compileQuery);
|
|
102
|
+
const result = await handler({
|
|
103
|
+
projectUuid: PROJECT,
|
|
104
|
+
exploreId: 'orders',
|
|
105
|
+
metricQuery: {
|
|
106
|
+
dimensions: ['orders_status'],
|
|
107
|
+
metrics: [],
|
|
108
|
+
filters: {},
|
|
109
|
+
sorts: [],
|
|
110
|
+
limit: 50,
|
|
111
|
+
tableCalculations: [],
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
(0, vitest_1.expect)(result.isError).toBe(true);
|
|
115
|
+
(0, vitest_1.expect)(result.content[0].text).toContain('ERROR:');
|
|
116
|
+
(0, vitest_1.expect)(result.content[0].text).toContain('unknown filter fieldId');
|
|
117
|
+
(0, vitest_1.expect)(result.content[0].text).toContain('orders_customer.first_name');
|
|
118
|
+
(0, vitest_1.expect)(result.content[0].text).toContain('list_dimensions');
|
|
119
|
+
(0, vitest_1.expect)(result.content[0].text).not.toContain('${COMPILED_SQL_FIELD_ID_HINT}');
|
|
120
|
+
});
|
|
91
121
|
(0, vitest_1.it)('defaults missing tableCalculations to []', async () => {
|
|
92
122
|
const compileQuery = vitest_1.vi.fn().mockResolvedValue({
|
|
93
123
|
query: 'SELECT `orders`.status AS `orders_status` FROM orders',
|
|
@@ -109,6 +139,47 @@ function createCompileHandler(compileQuery) {
|
|
|
109
139
|
tableCalculations: [],
|
|
110
140
|
}));
|
|
111
141
|
});
|
|
142
|
+
(0, vitest_1.it)('defaults missing sorts to []', async () => {
|
|
143
|
+
const compileQuery = vitest_1.vi.fn().mockResolvedValue({
|
|
144
|
+
query: 'SELECT `orders`.status AS `orders_status` FROM orders',
|
|
145
|
+
});
|
|
146
|
+
const { handler } = createCompileHandler(compileQuery);
|
|
147
|
+
await handler({
|
|
148
|
+
projectUuid: PROJECT,
|
|
149
|
+
exploreId: 'orders',
|
|
150
|
+
metricQuery: {
|
|
151
|
+
dimensions: ['orders_status'],
|
|
152
|
+
metrics: [],
|
|
153
|
+
filters: {},
|
|
154
|
+
limit: 50,
|
|
155
|
+
tableCalculations: [],
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
(0, vitest_1.expect)(compileQuery).toHaveBeenCalledWith(PROJECT, 'orders', vitest_1.expect.objectContaining({
|
|
159
|
+
exploreName: 'orders',
|
|
160
|
+
sorts: [],
|
|
161
|
+
}));
|
|
162
|
+
});
|
|
163
|
+
(0, vitest_1.it)('preserves explicit sorts', async () => {
|
|
164
|
+
const sorts = [{ fieldId: 'orders_status', descending: true }];
|
|
165
|
+
const compileQuery = vitest_1.vi.fn().mockResolvedValue({
|
|
166
|
+
query: 'SELECT `orders`.status AS `orders_status` FROM orders',
|
|
167
|
+
});
|
|
168
|
+
const { handler } = createCompileHandler(compileQuery);
|
|
169
|
+
await handler({
|
|
170
|
+
projectUuid: PROJECT,
|
|
171
|
+
exploreId: 'orders',
|
|
172
|
+
metricQuery: {
|
|
173
|
+
dimensions: ['orders_status'],
|
|
174
|
+
metrics: [],
|
|
175
|
+
filters: {},
|
|
176
|
+
sorts,
|
|
177
|
+
limit: 50,
|
|
178
|
+
tableCalculations: [],
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
(0, vitest_1.expect)(compileQuery).toHaveBeenCalledWith(PROJECT, 'orders', vitest_1.expect.objectContaining({ sorts }));
|
|
182
|
+
});
|
|
112
183
|
(0, vitest_1.it)('preserves explicit tableCalculations', async () => {
|
|
113
184
|
const tableCalculations = [
|
|
114
185
|
{ name: 'ratio', displayName: 'Ratio', sql: '${orders_sum_order_amount} / 100' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance, ai-agent-ops, ai-agent-chat, and data-analyst profiles.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"commander": "^15.0.0",
|
|
25
25
|
"hono": "^4.13.0",
|
|
26
26
|
"zod": "^4.4.3",
|
|
27
|
-
"@lightdash-tools/
|
|
28
|
-
"@lightdash-tools/
|
|
27
|
+
"@lightdash-tools/common": "0.24.0",
|
|
28
|
+
"@lightdash-tools/client": "0.24.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@modelcontextprotocol/client": "2.0.0",
|