@lightdash-tools/mcp 0.18.0 → 0.20.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/README.md +17 -12
- package/dist/config/enabled-profiles.test.js +6 -0
- package/dist/policy/envelope.d.ts +1 -1
- package/dist/profiles/ai-agent-chat/v1/index.d.ts +6 -0
- package/dist/profiles/ai-agent-chat/v1/index.js +29 -0
- package/dist/profiles/ai-agent-chat/v1/invariants.d.ts +33 -0
- package/dist/profiles/ai-agent-chat/v1/invariants.js +47 -0
- package/dist/profiles/ai-agent-chat/v1/prompts.d.ts +9 -0
- package/dist/profiles/ai-agent-chat/v1/prompts.js +68 -0
- package/dist/profiles/ai-agent-chat/v1/prompts.test.d.ts +4 -0
- package/dist/profiles/ai-agent-chat/v1/prompts.test.js +62 -0
- package/dist/profiles/ai-agent-chat/v1/resources/playbooks/conversation.md +70 -0
- package/dist/profiles/ai-agent-chat/v1/resources/playbooks/core.md +56 -0
- package/dist/profiles/ai-agent-chat/v1/resources/playbooks/index.md +8 -0
- package/dist/profiles/ai-agent-chat/v1/resources/playbooks.d.ts +11 -0
- package/dist/profiles/ai-agent-chat/v1/resources/playbooks.js +32 -0
- package/dist/profiles/content-reader/v1/invariants.d.ts +1 -1
- package/dist/profiles/content-reader/v1/invariants.js +1 -1
- package/dist/profiles/content-reader/v1/resources/playbooks/core.md +14 -14
- package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +9 -7
- package/dist/profiles/data-analyst/v1/prompts.js +1 -1
- package/dist/profiles/data-analyst/v1/resources/playbooks/core.md +10 -10
- package/dist/profiles/data-analyst/v1/resources/playbooks/explore.md +2 -1
- package/dist/profiles/index.d.ts +1 -0
- package/dist/profiles/index.js +33 -29
- package/dist/profiles/index.test.js +27 -7
- package/dist/tools/ai-agents/agents.d.ts +3 -1
- package/dist/tools/ai-agents/agents.js +16 -4
- package/dist/tools/ai-agents/agents.test.js +27 -31
- package/dist/tools/ai-agents/discovery.js +4 -4
- package/dist/tools/ai-agents/evaluations.js +9 -9
- package/dist/tools/ai-agents/helpers.d.ts +13 -2
- package/dist/tools/ai-agents/helpers.js +8 -4
- package/dist/tools/ai-agents/router.d.ts +12 -0
- package/dist/tools/ai-agents/router.js +33 -0
- package/dist/tools/ai-agents/router.test.d.ts +1 -0
- package/dist/tools/ai-agents/router.test.js +99 -0
- package/dist/tools/ai-agents/test-support.d.ts +24 -0
- package/dist/tools/ai-agents/test-support.js +34 -0
- package/dist/tools/ai-agents/threads.d.ts +12 -1
- package/dist/tools/ai-agents/threads.js +72 -5
- package/dist/tools/ai-agents/threads.test.d.ts +4 -0
- package/dist/tools/ai-agents/threads.test.js +184 -0
- package/dist/tools/composition/explain-content.js +56 -6
- package/dist/tools/lib/artifacts.d.ts +41 -0
- package/dist/tools/lib/artifacts.js +90 -0
- package/dist/tools/project/projects.js +1 -0
- package/dist/tools/project/projects.test.js +1 -0
- package/dist/tools/project/reader-content.d.ts +11 -0
- package/dist/tools/project/reader-content.js +63 -5
- package/dist/tools/project/reader-content.sql.test.d.ts +4 -0
- package/dist/tools/project/reader-content.sql.test.js +113 -0
- package/dist/tools/project/reader-execution.js +77 -33
- package/dist/tools/project/reader-execution.test.js +59 -2
- package/dist/tools/query/chart-source.d.ts +29 -1
- package/dist/tools/query/chart-source.js +66 -11
- package/dist/tools/query/lifecycle.js +9 -4
- package/dist/tools/query/query-artifact-result.d.ts +25 -0
- package/dist/tools/query/query-artifact-result.js +64 -0
- package/dist/tools/query/query-artifact-result.test.d.ts +4 -0
- package/dist/tools/query/query-artifact-result.test.js +87 -0
- package/dist/tools/query/resolve-saved-sql-chart.d.ts +10 -0
- package/dist/tools/query/resolve-saved-sql-chart.js +48 -0
- package/dist/tools/query/resolve-saved-sql-chart.test.d.ts +1 -0
- package/dist/tools/query/resolve-saved-sql-chart.test.js +50 -0
- package/dist/tools/query/run-metric-query.js +9 -5
- package/dist/tools/query/run-metric-query.test.js +5 -0
- package/dist/tools/shared.artifacts.test.d.ts +1 -0
- package/dist/tools/shared.artifacts.test.js +93 -0
- package/dist/tools/shared.d.ts +40 -1
- package/dist/tools/shared.js +33 -0
- package/package.json +5 -5
|
@@ -10,35 +10,85 @@ const project_scope_js_1 = require("../../governance/project-scope.js");
|
|
|
10
10
|
const content_reader_js_1 = require("../../policy/content-reader.js");
|
|
11
11
|
const envelope_js_1 = require("../../policy/envelope.js");
|
|
12
12
|
const api_shape_js_1 = require("../lib/api-shape.js");
|
|
13
|
+
const artifacts_js_1 = require("../lib/artifacts.js");
|
|
13
14
|
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
14
15
|
const reader_content_js_1 = require("../project/reader-content.js");
|
|
15
16
|
const chart_source_js_1 = require("../query/chart-source.js");
|
|
16
17
|
const reader_tool_helpers_js_1 = require("../query/reader-tool-helpers.js");
|
|
18
|
+
const resolve_saved_sql_chart_js_1 = require("../query/resolve-saved-sql-chart.js");
|
|
17
19
|
const shared_js_1 = require("../shared.js");
|
|
18
20
|
const types_js_1 = require("../types.js");
|
|
21
|
+
function sqlExplainSummary(args) {
|
|
22
|
+
return {
|
|
23
|
+
identity: {
|
|
24
|
+
uuid: args.savedSqlUuid,
|
|
25
|
+
name: args.name,
|
|
26
|
+
type: 'chart',
|
|
27
|
+
},
|
|
28
|
+
businessDescription: args.description,
|
|
29
|
+
verification: { verified: false },
|
|
30
|
+
measures: [],
|
|
31
|
+
groupings: [],
|
|
32
|
+
filters: [],
|
|
33
|
+
parameters: [],
|
|
34
|
+
timeContext: [],
|
|
35
|
+
knownWarnings: ['SQL chart; standalone execution disabled by default on content-reader'],
|
|
36
|
+
executionRequirements: ['Not executable via run_chart on content-reader v1'],
|
|
37
|
+
summary: (0, reader_content_js_1.toReaderSqlChartSummary)(args),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
19
40
|
function registerExplainContent(server, contextProvider) {
|
|
20
41
|
(0, content_reader_js_1.registerContentReaderTool)(server, 'explain_content', {
|
|
21
42
|
title: 'Explain content',
|
|
22
|
-
description: 'Produce a deterministic metadata-based explanation of a chart or dashboard',
|
|
43
|
+
description: 'Produce a deterministic metadata-based explanation of a chart or dashboard. For saved SQL charts, pass includeArtifacts=["sql"] to attach the authored SQL body as a separate MCP resource.',
|
|
23
44
|
safety: content_reader_js_1.METADATA_SAFETY,
|
|
24
45
|
inputSchema: {
|
|
25
46
|
projectUuid: (0, schema_fields_js_1.projectUuidField)().optional(),
|
|
26
47
|
contentType: zod_1.z.enum(['chart', 'dashboard']),
|
|
27
48
|
contentUuidOrSlug: (0, schema_fields_js_1.uuidOrSlugField)('Content UUID or slug'),
|
|
49
|
+
includeArtifacts: (0, artifacts_js_1.includeArtifactsField)(['sql']),
|
|
28
50
|
},
|
|
29
51
|
},
|
|
30
52
|
/* eslint-disable sonarjs/cognitive-complexity, sonarjs/cyclomatic-complexity -- explain branches */
|
|
31
53
|
(profile) => (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
32
|
-
var _a;
|
|
54
|
+
var _a, _b;
|
|
33
55
|
try {
|
|
34
56
|
const scope = (0, project_scope_js_1.resolveProjectScope)({ projectUuid: args.projectUuid });
|
|
35
57
|
if (args.contentType === 'chart') {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
const include = (0, artifacts_js_1.parseIncludeArtifacts)(args.includeArtifacts, []);
|
|
59
|
+
const preClass = await (0, chart_source_js_1.resolveChartSource)(c, scope.projectUuid, args.contentUuidOrSlug);
|
|
60
|
+
if (preClass.class === 'sql') {
|
|
61
|
+
const savedSqlUuid = (_a = preClass.uuid) !== null && _a !== void 0 ? _a : args.contentUuidOrSlug;
|
|
62
|
+
if (include.has('sql')) {
|
|
63
|
+
const sqlChart = await (0, resolve_saved_sql_chart_js_1.resolveSavedSqlChart)(c, scope.projectUuid, savedSqlUuid);
|
|
64
|
+
return (0, artifacts_js_1.sqlRevealToolResult)({
|
|
65
|
+
profile,
|
|
66
|
+
projectUuid: scope.projectUuid,
|
|
67
|
+
projectPinned: scope.projectPinned,
|
|
68
|
+
include,
|
|
69
|
+
savedSqlUuid: sqlChart.savedSqlUuid,
|
|
70
|
+
sql: sqlChart.sql,
|
|
71
|
+
summaryData: sqlExplainSummary(sqlChart),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return (0, artifacts_js_1.sqlRevealToolResult)({
|
|
75
|
+
profile,
|
|
76
|
+
projectUuid: scope.projectUuid,
|
|
77
|
+
projectPinned: scope.projectPinned,
|
|
78
|
+
include,
|
|
79
|
+
savedSqlUuid,
|
|
80
|
+
summaryData: sqlExplainSummary({
|
|
81
|
+
savedSqlUuid,
|
|
82
|
+
name: preClass.name,
|
|
83
|
+
description: preClass.description,
|
|
84
|
+
slug: preClass.slug,
|
|
85
|
+
space: preClass.space,
|
|
86
|
+
lastUpdatedAt: preClass.lastUpdatedAt,
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
39
89
|
}
|
|
40
90
|
const chart = (0, api_shape_js_1.asRecord)(await c.v2.charts.getSavedChart(scope.projectUuid, args.contentUuidOrSlug));
|
|
41
|
-
const metricQuery = ((
|
|
91
|
+
const metricQuery = ((_b = chart.metricQuery) !== null && _b !== void 0 ? _b : {});
|
|
42
92
|
const verification = chart.verification;
|
|
43
93
|
const chartType = (0, reader_content_js_1.detectChartType)(chart);
|
|
44
94
|
const explanation = {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-reader tool-result artifact helpers (ADR-0032).
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import type { ContentReaderWarning } from '../../policy/envelope.js';
|
|
6
|
+
import type { TextContent, ToolArtifactCatalogEntry, ToolArtifactKind, ToolArtifactSpec } from '../shared.js';
|
|
7
|
+
import type { ProfileId } from '@lightdash-tools/common';
|
|
8
|
+
/** Per-tool allowlist — do not advertise kinds the tool cannot attach. */
|
|
9
|
+
export declare function includeArtifactsField(kinds: readonly [ToolArtifactKind, ...ToolArtifactKind[]]): z.ZodType<ToolArtifactKind[] | undefined>;
|
|
10
|
+
export declare function parseIncludeArtifacts(value: Array<'data' | 'sql'> | undefined, defaults: ToolArtifactKind[]): Set<ToolArtifactKind>;
|
|
11
|
+
export declare function contentReaderArtifactUri(kind: ToolArtifactKind, id: string): string;
|
|
12
|
+
export declare const SQL_ARTIFACT_AVAILABLE_WARNING: ContentReaderWarning;
|
|
13
|
+
/** Opted-in SQL is model-facing (ADR-0032). */
|
|
14
|
+
export declare function buildSqlArtifact(args: {
|
|
15
|
+
savedSqlUuid: string;
|
|
16
|
+
sql: string;
|
|
17
|
+
}): ToolArtifactSpec;
|
|
18
|
+
export declare function buildDataArtifact(args: {
|
|
19
|
+
queryUuid: string;
|
|
20
|
+
rows: unknown;
|
|
21
|
+
}): ToolArtifactSpec;
|
|
22
|
+
export declare function catalogEntry(kind: ToolArtifactKind, uri: string, mimeType: string, included: boolean): ToolArtifactCatalogEntry;
|
|
23
|
+
/** Catalog (+ optional attach) for an authored SQL body. */
|
|
24
|
+
export declare function buildSqlArtifactParts(include: Set<ToolArtifactKind>, sql: {
|
|
25
|
+
savedSqlUuid: string;
|
|
26
|
+
sql?: string;
|
|
27
|
+
}): {
|
|
28
|
+
artifacts: ToolArtifactSpec[];
|
|
29
|
+
catalog: ToolArtifactCatalogEntry[];
|
|
30
|
+
};
|
|
31
|
+
/** Discover/explain SQL chart: envelope summary + optional SQL resource part. */
|
|
32
|
+
export declare function sqlRevealToolResult(args: {
|
|
33
|
+
profile: ProfileId;
|
|
34
|
+
projectUuid: string;
|
|
35
|
+
projectPinned: boolean;
|
|
36
|
+
include: Set<ToolArtifactKind>;
|
|
37
|
+
savedSqlUuid: string;
|
|
38
|
+
/** Present only when `include` has `'sql'` (avoids downloading the body otherwise). */
|
|
39
|
+
sql?: string;
|
|
40
|
+
summaryData: object;
|
|
41
|
+
}): TextContent;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-reader tool-result artifact helpers (ADR-0032).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SQL_ARTIFACT_AVAILABLE_WARNING = void 0;
|
|
7
|
+
exports.includeArtifactsField = includeArtifactsField;
|
|
8
|
+
exports.parseIncludeArtifacts = parseIncludeArtifacts;
|
|
9
|
+
exports.contentReaderArtifactUri = contentReaderArtifactUri;
|
|
10
|
+
exports.buildSqlArtifact = buildSqlArtifact;
|
|
11
|
+
exports.buildDataArtifact = buildDataArtifact;
|
|
12
|
+
exports.catalogEntry = catalogEntry;
|
|
13
|
+
exports.buildSqlArtifactParts = buildSqlArtifactParts;
|
|
14
|
+
exports.sqlRevealToolResult = sqlRevealToolResult;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const envelope_js_1 = require("../../policy/envelope.js");
|
|
17
|
+
const shared_js_1 = require("../shared.js");
|
|
18
|
+
/** Per-tool allowlist — do not advertise kinds the tool cannot attach. */
|
|
19
|
+
function includeArtifactsField(kinds) {
|
|
20
|
+
const kindList = kinds.join(', ');
|
|
21
|
+
const values = [...kinds];
|
|
22
|
+
return zod_1.z
|
|
23
|
+
.array(zod_1.z.enum(values))
|
|
24
|
+
.optional()
|
|
25
|
+
.describe(`Bulky payloads to attach as separate MCP resource parts (allowed: ${kindList}). Omitted kinds use each tool's default.`);
|
|
26
|
+
}
|
|
27
|
+
function parseIncludeArtifacts(value, defaults) {
|
|
28
|
+
return new Set(value !== null && value !== void 0 ? value : defaults);
|
|
29
|
+
}
|
|
30
|
+
function contentReaderArtifactUri(kind, id) {
|
|
31
|
+
return `lightdash://artifacts/content-reader/${kind}/${encodeURIComponent(id)}`;
|
|
32
|
+
}
|
|
33
|
+
exports.SQL_ARTIFACT_AVAILABLE_WARNING = {
|
|
34
|
+
code: 'SQL_ARTIFACT_AVAILABLE',
|
|
35
|
+
message: 'Authored SQL is available; pass includeArtifacts=["sql"] to attach it as a separate resource part',
|
|
36
|
+
};
|
|
37
|
+
/** Opted-in SQL is model-facing (ADR-0032). */
|
|
38
|
+
function buildSqlArtifact(args) {
|
|
39
|
+
return {
|
|
40
|
+
kind: 'sql',
|
|
41
|
+
uri: contentReaderArtifactUri('sql', args.savedSqlUuid),
|
|
42
|
+
mimeType: 'text/sql',
|
|
43
|
+
text: args.sql,
|
|
44
|
+
audience: ['assistant', 'user'],
|
|
45
|
+
priority: 0.6,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function buildDataArtifact(args) {
|
|
49
|
+
return {
|
|
50
|
+
kind: 'data',
|
|
51
|
+
uri: contentReaderArtifactUri('data', args.queryUuid),
|
|
52
|
+
mimeType: 'application/json',
|
|
53
|
+
text: JSON.stringify(args.rows),
|
|
54
|
+
audience: ['assistant', 'user'],
|
|
55
|
+
priority: 0.8,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function catalogEntry(kind, uri, mimeType, included) {
|
|
59
|
+
return { kind, uri, mimeType, included };
|
|
60
|
+
}
|
|
61
|
+
/** Catalog (+ optional attach) for an authored SQL body. */
|
|
62
|
+
function buildSqlArtifactParts(include, sql) {
|
|
63
|
+
const uri = contentReaderArtifactUri('sql', sql.savedSqlUuid);
|
|
64
|
+
const included = include.has('sql') && typeof sql.sql === 'string';
|
|
65
|
+
const catalog = [catalogEntry('sql', uri, 'text/sql', included)];
|
|
66
|
+
const artifacts = included && sql.sql !== undefined
|
|
67
|
+
? [buildSqlArtifact({ savedSqlUuid: sql.savedSqlUuid, sql: sql.sql })]
|
|
68
|
+
: [];
|
|
69
|
+
return { artifacts, catalog };
|
|
70
|
+
}
|
|
71
|
+
/** Discover/explain SQL chart: envelope summary + optional SQL resource part. */
|
|
72
|
+
function sqlRevealToolResult(args) {
|
|
73
|
+
const includeSql = args.include.has('sql');
|
|
74
|
+
const warnings = includeSql ? [] : [exports.SQL_ARTIFACT_AVAILABLE_WARNING];
|
|
75
|
+
const envelope = (0, envelope_js_1.contentReaderEnvelope)(args.summaryData, {
|
|
76
|
+
profile: args.profile,
|
|
77
|
+
projectUuid: args.projectUuid,
|
|
78
|
+
projectPinned: args.projectPinned,
|
|
79
|
+
warnings,
|
|
80
|
+
});
|
|
81
|
+
const { artifacts, catalog } = buildSqlArtifactParts(args.include, {
|
|
82
|
+
savedSqlUuid: args.savedSqlUuid,
|
|
83
|
+
sql: includeSql ? args.sql : undefined,
|
|
84
|
+
});
|
|
85
|
+
return (0, shared_js_1.artifactToolResult)({
|
|
86
|
+
summary: envelope,
|
|
87
|
+
artifacts,
|
|
88
|
+
catalog,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -177,6 +177,7 @@ function mockContext(listProjects, getProject) {
|
|
|
177
177
|
canExecuteSqlCharts: false,
|
|
178
178
|
canExecuteDashboardTiles: true,
|
|
179
179
|
canExecuteDashboardSqlTiles: true,
|
|
180
|
+
canRevealSqlBodies: true,
|
|
180
181
|
});
|
|
181
182
|
(0, vitest_1.expect)(body.context.projectUuid).toBe(PINNED);
|
|
182
183
|
(0, vitest_1.expect)(getProject).toHaveBeenCalledWith(PINNED);
|
|
@@ -18,6 +18,17 @@ export type DashboardTileClass = {
|
|
|
18
18
|
export declare function classifyDashboardTile(type: string, props: Record<string, unknown>): DashboardTileClass;
|
|
19
19
|
/** Pass through OpenAPI TableCalculation fields agents need to clone. */
|
|
20
20
|
export declare function toReaderTableCalculation(tc: unknown): Record<string, unknown>;
|
|
21
|
+
/** Metadata summary for a saved SQL chart — never includes the authored SQL body. */
|
|
22
|
+
export declare function toReaderSqlChartSummary(chart: {
|
|
23
|
+
savedSqlUuid: string;
|
|
24
|
+
slug?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
description?: string | null;
|
|
27
|
+
chartKind?: unknown;
|
|
28
|
+
limit?: unknown;
|
|
29
|
+
space?: unknown;
|
|
30
|
+
lastUpdatedAt?: string | null;
|
|
31
|
+
}): Record<string, unknown>;
|
|
21
32
|
export declare function toReaderDashboard(dashboard: Record<string, unknown>, includeTiles: boolean): {
|
|
22
33
|
description: unknown;
|
|
23
34
|
filters: unknown;
|
|
@@ -7,6 +7,7 @@ exports.getChartTool = exports.getDashboardTool = exports.listVerifiedContentToo
|
|
|
7
7
|
exports.detectChartType = detectChartType;
|
|
8
8
|
exports.classifyDashboardTile = classifyDashboardTile;
|
|
9
9
|
exports.toReaderTableCalculation = toReaderTableCalculation;
|
|
10
|
+
exports.toReaderSqlChartSummary = toReaderSqlChartSummary;
|
|
10
11
|
exports.toReaderDashboard = toReaderDashboard;
|
|
11
12
|
exports.registerSearchContent = registerSearchContent;
|
|
12
13
|
exports.registerListVerifiedContent = registerListVerifiedContent;
|
|
@@ -18,10 +19,12 @@ const project_scope_js_1 = require("../../governance/project-scope.js");
|
|
|
18
19
|
const content_reader_js_1 = require("../../policy/content-reader.js");
|
|
19
20
|
const envelope_js_1 = require("../../policy/envelope.js");
|
|
20
21
|
const api_shape_js_1 = require("../lib/api-shape.js");
|
|
22
|
+
const artifacts_js_1 = require("../lib/artifacts.js");
|
|
21
23
|
const contracts_js_1 = require("../lib/contracts.js");
|
|
22
24
|
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
23
25
|
const chart_source_js_1 = require("../query/chart-source.js");
|
|
24
26
|
const reader_tool_helpers_js_1 = require("../query/reader-tool-helpers.js");
|
|
27
|
+
const resolve_saved_sql_chart_js_1 = require("../query/resolve-saved-sql-chart.js");
|
|
25
28
|
const shared_js_1 = require("../shared.js");
|
|
26
29
|
const types_js_1 = require("../types.js");
|
|
27
30
|
function detectChartType(chart) {
|
|
@@ -109,7 +112,32 @@ function toReaderChart(chart, includeQuery) {
|
|
|
109
112
|
parameters: (_d = chart.parameters) !== null && _d !== void 0 ? _d : {},
|
|
110
113
|
verification: chart.verification,
|
|
111
114
|
updatedAt: chart.updatedAt,
|
|
112
|
-
warnings: chartType === 'sql'
|
|
115
|
+
warnings: chartType === 'sql'
|
|
116
|
+
? ['SQL chart; pass includeArtifacts=["sql"] on get_chart to attach authored SQL']
|
|
117
|
+
: [],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Metadata summary for a saved SQL chart — never includes the authored SQL body. */
|
|
121
|
+
function toReaderSqlChartSummary(chart) {
|
|
122
|
+
return {
|
|
123
|
+
uuid: chart.savedSqlUuid,
|
|
124
|
+
savedSqlUuid: chart.savedSqlUuid,
|
|
125
|
+
slug: chart.slug,
|
|
126
|
+
name: chart.name,
|
|
127
|
+
description: chart.description,
|
|
128
|
+
chartType: 'sql',
|
|
129
|
+
chartKind: chart.chartKind,
|
|
130
|
+
limit: chart.limit,
|
|
131
|
+
space: chart.space && typeof chart.space === 'object'
|
|
132
|
+
? (() => {
|
|
133
|
+
const space = chart.space;
|
|
134
|
+
return typeof space.uuid === 'string' && typeof space.name === 'string'
|
|
135
|
+
? { uuid: space.uuid, name: space.name }
|
|
136
|
+
: undefined;
|
|
137
|
+
})()
|
|
138
|
+
: undefined,
|
|
139
|
+
updatedAt: chart.lastUpdatedAt,
|
|
140
|
+
executable: false,
|
|
113
141
|
};
|
|
114
142
|
}
|
|
115
143
|
function toReaderDashboard(dashboard, includeTiles) {
|
|
@@ -255,19 +283,49 @@ function registerGetDashboard(server, contextProvider) {
|
|
|
255
283
|
function registerGetChart(server, contextProvider) {
|
|
256
284
|
(0, content_reader_js_1.registerContentReaderTool)(server, 'get_chart', {
|
|
257
285
|
title: 'Get chart',
|
|
258
|
-
description: 'Explain a saved
|
|
286
|
+
description: 'Explain a saved chart definition. Semantic charts return query fields when includeQueryDefinition. Saved SQL charts return metadata; pass includeArtifacts=["sql"] for the authored SQL body as a separate MCP resource (never inlined in the summary). Standalone SQL execution stays disabled.',
|
|
259
287
|
safety: content_reader_js_1.METADATA_SAFETY,
|
|
260
288
|
inputSchema: {
|
|
261
289
|
projectUuid: (0, schema_fields_js_1.projectUuidField)().optional(),
|
|
262
290
|
chartUuidOrSlug: (0, schema_fields_js_1.uuidOrSlugField)('Chart UUID or slug'),
|
|
263
291
|
includeQueryDefinition: zod_1.z.boolean().optional(),
|
|
292
|
+
includeArtifacts: (0, artifacts_js_1.includeArtifactsField)(['sql']),
|
|
264
293
|
},
|
|
265
294
|
}, (profile) => (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
295
|
+
var _a;
|
|
266
296
|
try {
|
|
267
297
|
const scope = (0, project_scope_js_1.resolveProjectScope)({ projectUuid: args.projectUuid });
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
298
|
+
const include = (0, artifacts_js_1.parseIncludeArtifacts)(args.includeArtifacts, []);
|
|
299
|
+
const preClass = await (0, chart_source_js_1.resolveChartSource)(c, scope.projectUuid, args.chartUuidOrSlug);
|
|
300
|
+
if (preClass.class === 'sql') {
|
|
301
|
+
const savedSqlUuid = (_a = preClass.uuid) !== null && _a !== void 0 ? _a : args.chartUuidOrSlug;
|
|
302
|
+
if (include.has('sql')) {
|
|
303
|
+
const sqlChart = await (0, resolve_saved_sql_chart_js_1.resolveSavedSqlChart)(c, scope.projectUuid, savedSqlUuid);
|
|
304
|
+
return (0, artifacts_js_1.sqlRevealToolResult)({
|
|
305
|
+
profile,
|
|
306
|
+
projectUuid: scope.projectUuid,
|
|
307
|
+
projectPinned: scope.projectPinned,
|
|
308
|
+
include,
|
|
309
|
+
savedSqlUuid: sqlChart.savedSqlUuid,
|
|
310
|
+
sql: sqlChart.sql,
|
|
311
|
+
summaryData: toReaderSqlChartSummary(sqlChart),
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return (0, artifacts_js_1.sqlRevealToolResult)({
|
|
315
|
+
profile,
|
|
316
|
+
projectUuid: scope.projectUuid,
|
|
317
|
+
projectPinned: scope.projectPinned,
|
|
318
|
+
include,
|
|
319
|
+
savedSqlUuid,
|
|
320
|
+
summaryData: toReaderSqlChartSummary({
|
|
321
|
+
savedSqlUuid,
|
|
322
|
+
slug: preClass.slug,
|
|
323
|
+
name: preClass.name,
|
|
324
|
+
description: preClass.description,
|
|
325
|
+
space: preClass.space,
|
|
326
|
+
lastUpdatedAt: preClass.lastUpdatedAt,
|
|
327
|
+
}),
|
|
328
|
+
});
|
|
271
329
|
}
|
|
272
330
|
const chart = (0, api_shape_js_1.asRecord)(await c.v2.charts.getSavedChart(scope.projectUuid, args.chartUuidOrSlug));
|
|
273
331
|
return (0, shared_js_1.jsonToolResult)((0, envelope_js_1.contentReaderEnvelope)(toReaderChart(chart, args.includeQueryDefinition !== false), {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* get_chart SQL reveal + summary helpers (ADR-0032).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const server_profile_js_1 = require("../../audit/server-profile.js");
|
|
8
|
+
const reader_content_js_1 = require("./reader-content.js");
|
|
9
|
+
const PROJECT = '550e8400-e29b-41d4-a716-446655440000';
|
|
10
|
+
const SAVED_SQL = 'ffff6666-aaaa-4bbb-8ccc-dddddddddddd';
|
|
11
|
+
function readerContext(lightdashClient) {
|
|
12
|
+
return {
|
|
13
|
+
getContext: async () => ({
|
|
14
|
+
lightdashClient,
|
|
15
|
+
auth: { mode: 'none' },
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
(0, vitest_1.describe)('toReaderSqlChartSummary', () => {
|
|
20
|
+
(0, vitest_1.it)('omits authored sql from the summary', () => {
|
|
21
|
+
const chart = {
|
|
22
|
+
savedSqlUuid: SAVED_SQL,
|
|
23
|
+
name: 'SQL KPI',
|
|
24
|
+
slug: 'sql-kpi',
|
|
25
|
+
description: null,
|
|
26
|
+
sql: 'SELECT 1',
|
|
27
|
+
limit: 100,
|
|
28
|
+
chartKind: 'table',
|
|
29
|
+
space: { uuid: 's1', name: 'Space' },
|
|
30
|
+
lastUpdatedAt: '2026-01-01T00:00:00Z',
|
|
31
|
+
};
|
|
32
|
+
const summary = (0, reader_content_js_1.toReaderSqlChartSummary)(chart);
|
|
33
|
+
(0, vitest_1.expect)(summary).not.toHaveProperty('sql');
|
|
34
|
+
(0, vitest_1.expect)(summary.savedSqlUuid).toBe(SAVED_SQL);
|
|
35
|
+
(0, vitest_1.expect)(summary.executable).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.describe)('registerGetChart SQL reveal', () => {
|
|
39
|
+
(0, vitest_1.beforeEach)(() => {
|
|
40
|
+
vitest_1.vi.restoreAllMocks();
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('returns metadata with SQL_ARTIFACT_AVAILABLE by default', async () => {
|
|
43
|
+
const searchContent = vitest_1.vi.fn().mockResolvedValue({
|
|
44
|
+
data: [
|
|
45
|
+
{
|
|
46
|
+
contentType: 'chart',
|
|
47
|
+
uuid: SAVED_SQL,
|
|
48
|
+
slug: 'sql-kpi',
|
|
49
|
+
source: 'sql',
|
|
50
|
+
name: 'SQL KPI',
|
|
51
|
+
description: null,
|
|
52
|
+
space: { uuid: 's1', name: 'Space' },
|
|
53
|
+
lastUpdatedAt: '2026-01-01T00:00:00Z',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
const getSavedSqlChart = vitest_1.vi.fn();
|
|
58
|
+
const mockServer = { registerTool: vitest_1.vi.fn() };
|
|
59
|
+
(0, server_profile_js_1.bindServerProfile)(mockServer, 'content-reader');
|
|
60
|
+
(0, reader_content_js_1.registerGetChart)(mockServer, readerContext({
|
|
61
|
+
v1: { sqlRunner: { getSavedSqlChart } },
|
|
62
|
+
v2: { content: { searchContent } },
|
|
63
|
+
}));
|
|
64
|
+
const [, , handler] = mockServer.registerTool.mock.calls[0];
|
|
65
|
+
const result = await handler({
|
|
66
|
+
projectUuid: PROJECT,
|
|
67
|
+
chartUuidOrSlug: SAVED_SQL,
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.expect)(getSavedSqlChart).not.toHaveBeenCalled();
|
|
70
|
+
const body = JSON.parse(result.content[0].text);
|
|
71
|
+
(0, vitest_1.expect)(body.data.chartType).toBe('sql');
|
|
72
|
+
(0, vitest_1.expect)(body.data.savedSqlUuid).toBe(SAVED_SQL);
|
|
73
|
+
(0, vitest_1.expect)(body.data.name).toBe('SQL KPI');
|
|
74
|
+
(0, vitest_1.expect)(JSON.stringify(body)).not.toContain('SELECT metric');
|
|
75
|
+
(0, vitest_1.expect)(body.warnings.map((w) => w.code)).toContain('SQL_ARTIFACT_AVAILABLE');
|
|
76
|
+
(0, vitest_1.expect)(body.artifacts).toEqual([vitest_1.expect.objectContaining({ kind: 'sql', included: false })]);
|
|
77
|
+
(0, vitest_1.expect)(result.content).toHaveLength(1);
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.it)('attaches SQL resource when includeArtifacts includes sql', async () => {
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
const searchContent = vitest_1.vi.fn().mockResolvedValue({
|
|
82
|
+
data: [{ contentType: 'chart', uuid: SAVED_SQL, slug: 'sql-kpi', source: 'sql' }],
|
|
83
|
+
});
|
|
84
|
+
const getSavedSqlChart = vitest_1.vi.fn().mockResolvedValue({
|
|
85
|
+
savedSqlUuid: SAVED_SQL,
|
|
86
|
+
name: 'SQL KPI',
|
|
87
|
+
slug: 'sql-kpi',
|
|
88
|
+
description: null,
|
|
89
|
+
sql: 'SELECT metric FROM kpi',
|
|
90
|
+
limit: 500,
|
|
91
|
+
chartKind: 'table',
|
|
92
|
+
space: { uuid: 's1', name: 'Space' },
|
|
93
|
+
lastUpdatedAt: '2026-01-01T00:00:00Z',
|
|
94
|
+
});
|
|
95
|
+
const mockServer = { registerTool: vitest_1.vi.fn() };
|
|
96
|
+
(0, server_profile_js_1.bindServerProfile)(mockServer, 'content-reader');
|
|
97
|
+
(0, reader_content_js_1.registerGetChart)(mockServer, readerContext({
|
|
98
|
+
v1: { sqlRunner: { getSavedSqlChart } },
|
|
99
|
+
v2: { content: { searchContent } },
|
|
100
|
+
}));
|
|
101
|
+
const [, , handler] = mockServer.registerTool.mock.calls[0];
|
|
102
|
+
const result = await handler({
|
|
103
|
+
projectUuid: PROJECT,
|
|
104
|
+
chartUuidOrSlug: SAVED_SQL,
|
|
105
|
+
includeArtifacts: ['sql'],
|
|
106
|
+
});
|
|
107
|
+
(0, vitest_1.expect)(result.content).toHaveLength(2);
|
|
108
|
+
(0, vitest_1.expect)((_b = (_a = result.content[1]) === null || _a === void 0 ? void 0 : _a.resource) === null || _b === void 0 ? void 0 : _b.text).toBe('SELECT metric FROM kpi');
|
|
109
|
+
const body = JSON.parse(result.content[0].text);
|
|
110
|
+
(0, vitest_1.expect)((_c = body.artifacts[0]) === null || _c === void 0 ? void 0 : _c.included).toBe(true);
|
|
111
|
+
(0, vitest_1.expect)(body.warnings).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
});
|