@lightdash-tools/mcp 0.19.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.
Files changed (37) hide show
  1. package/dist/policy/envelope.d.ts +1 -1
  2. package/dist/profiles/content-reader/v1/invariants.d.ts +1 -1
  3. package/dist/profiles/content-reader/v1/invariants.js +1 -1
  4. package/dist/profiles/content-reader/v1/resources/playbooks/core.md +14 -14
  5. package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +9 -7
  6. package/dist/profiles/data-analyst/v1/prompts.js +1 -1
  7. package/dist/profiles/data-analyst/v1/resources/playbooks/core.md +10 -10
  8. package/dist/profiles/data-analyst/v1/resources/playbooks/explore.md +2 -1
  9. package/dist/tools/composition/explain-content.js +56 -6
  10. package/dist/tools/lib/artifacts.d.ts +41 -0
  11. package/dist/tools/lib/artifacts.js +90 -0
  12. package/dist/tools/project/projects.js +1 -0
  13. package/dist/tools/project/projects.test.js +1 -0
  14. package/dist/tools/project/reader-content.d.ts +11 -0
  15. package/dist/tools/project/reader-content.js +63 -5
  16. package/dist/tools/project/reader-content.sql.test.d.ts +4 -0
  17. package/dist/tools/project/reader-content.sql.test.js +113 -0
  18. package/dist/tools/project/reader-execution.js +77 -33
  19. package/dist/tools/project/reader-execution.test.js +59 -2
  20. package/dist/tools/query/chart-source.d.ts +29 -1
  21. package/dist/tools/query/chart-source.js +66 -11
  22. package/dist/tools/query/lifecycle.js +9 -4
  23. package/dist/tools/query/query-artifact-result.d.ts +25 -0
  24. package/dist/tools/query/query-artifact-result.js +64 -0
  25. package/dist/tools/query/query-artifact-result.test.d.ts +4 -0
  26. package/dist/tools/query/query-artifact-result.test.js +87 -0
  27. package/dist/tools/query/resolve-saved-sql-chart.d.ts +10 -0
  28. package/dist/tools/query/resolve-saved-sql-chart.js +48 -0
  29. package/dist/tools/query/resolve-saved-sql-chart.test.d.ts +1 -0
  30. package/dist/tools/query/resolve-saved-sql-chart.test.js +50 -0
  31. package/dist/tools/query/run-metric-query.js +9 -5
  32. package/dist/tools/query/run-metric-query.test.js +5 -0
  33. package/dist/tools/shared.artifacts.test.d.ts +1 -0
  34. package/dist/tools/shared.artifacts.test.js +93 -0
  35. package/dist/tools/shared.d.ts +40 -1
  36. package/dist/tools/shared.js +33 -0
  37. package/package.json +3 -3
@@ -2,7 +2,7 @@
2
2
  * Content response envelope helpers (RFC §10 / ADR-0006).
3
3
  */
4
4
  import type { ProfileId } from '@lightdash-tools/common';
5
- export type ContentReaderWarningCode = 'CACHE_STALE' | 'DATE_ZOOM_IGNORED' | 'FILTER_IGNORED' | 'PARAMETER_DEFAULTED' | 'PARTIAL_RESULT' | 'QUERY_RUNNING' | 'QUERY_TIMEOUT' | 'REDACTED' | 'SQL_EXECUTION_DISABLED' | 'SQL_RESULT_MAY_BE_ROW_LEVEL' | 'STALE_CONTENT' | 'TRUNCATED' | 'UNSUPPORTED_TILE' | 'UNVERIFIED_CONTENT';
5
+ export type ContentReaderWarningCode = 'CACHE_STALE' | 'DATE_ZOOM_IGNORED' | 'FILTER_IGNORED' | 'PARAMETER_DEFAULTED' | 'PARTIAL_RESULT' | 'QUERY_RUNNING' | 'QUERY_TIMEOUT' | 'REDACTED' | 'SQL_ARTIFACT_AVAILABLE' | 'SQL_EXECUTION_DISABLED' | 'SQL_RESULT_MAY_BE_ROW_LEVEL' | 'STALE_CONTENT' | 'TRUNCATED' | 'UNSUPPORTED_TILE' | 'UNVERIFIED_CONTENT';
6
6
  export type ContentReaderWarning = {
7
7
  code: ContentReaderWarningCode;
8
8
  message: string;
@@ -27,7 +27,7 @@ export declare const CONTENT_READER_INVARIANTS: readonly [{
27
27
  readonly short: "Do not claim metric equivalence from matching labels alone.";
28
28
  }, {
29
29
  readonly id: "no-secrets";
30
- readonly short: "Do not reveal secrets, warehouse credentials, hidden SQL, or inaccessible content.";
30
+ readonly short: "Do not invent secrets, warehouse credentials, or SQL text; reveal authored SQL only via includeArtifacts.";
31
31
  }];
32
32
  export declare const CONTENT_READER_HARD_BANS: string;
33
33
  export declare const CONTENT_READER_DEFAULT_INVARIANT_IDS: readonly ("project-scope" | "no-secrets" | "no-mutation" | "no-arbitrary-query" | "no-bulk-export" | "no-sql-chart-execution" | "no-override-semantics" | "no-overstate-coverage" | "no-label-equivalence")[];
@@ -40,7 +40,7 @@ exports.CONTENT_READER_INVARIANTS = [
40
40
  },
41
41
  {
42
42
  id: 'no-secrets',
43
- short: 'Do not reveal secrets, warehouse credentials, hidden SQL, or inaccessible content.',
43
+ short: 'Do not invent secrets, warehouse credentials, or SQL text; reveal authored SQL only via includeArtifacts.',
44
44
  },
45
45
  ];
46
46
  exports.CONTENT_READER_HARD_BANS = (0, prompt_invariants_js_1.formatHardBansProjection)(exports.CONTENT_READER_INVARIANTS);
@@ -16,7 +16,7 @@ Discover, explain, and **optionally execute** saved Lightdash charts/dashboards
16
16
  - Do not execute content outside the resolved project.
17
17
  - Do not present truncated / incomplete coverage as a full answer.
18
18
  - Do not claim metric equivalence from matching labels alone.
19
- - Do not invent secrets, warehouse credentials, or hidden SQL text.
19
+ - Do not invent secrets, warehouse credentials, or SQL text. Authored SQL is available only via `includeArtifacts=["sql"]` (`canRevealSqlBodies=true`); never paste invented SQL.
20
20
 
21
21
  ## Default budgets (override only if the user expands scope)
22
22
 
@@ -41,23 +41,23 @@ Record budget / pagination / truncation stops in the answer.
41
41
 
42
42
  ## Allowed tools (`lightdash_*`)
43
43
 
44
- | Tool | Use for |
45
- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
46
- | `get_project` | Resolve project; read `readerCapabilities` + pin context |
47
- | `search_content` | Find charts/dashboards/spaces/data apps |
48
- | `list_verified_content` | List admin-verified charts/dashboards (prefer as trusted seeds) |
49
- | `list_spaces` / `get_space` | Space hierarchy + immediate content |
50
- | `get_dashboard` / `get_chart` | Structure / definition (saved SQL **chart** bodies hidden; semantic `tableCalculations` may appear when query is included) |
51
- | `list_project_parameters` / `get_project_parameters` | Parameter defs / values |
52
- | `explain_content` | Compact metadata explanation |
53
- | `run_chart` / `run_dashboard_tile` | Bounded saved execution (numbers) |
54
- | `export_chart_image` | PNG snapshot of a saved chart (vision); needs headless |
55
- | `get_query_result` / `cancel_query` | Poll / cancel by `queryUuid` |
44
+ | Tool | Use for |
45
+ | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
46
+ | `get_project` | Resolve project; read `readerCapabilities` + pin context |
47
+ | `search_content` | Find charts/dashboards/spaces/data apps |
48
+ | `list_verified_content` | List admin-verified charts/dashboards (prefer as trusted seeds) |
49
+ | `list_spaces` / `get_space` | Space hierarchy + immediate content |
50
+ | `get_dashboard` / `get_chart` | Structure / definition (SQL chart bodies via `includeArtifacts=["sql"]` only; semantic `tableCalculations` when query included) |
51
+ | `list_project_parameters` / `get_project_parameters` | Parameter defs / values |
52
+ | `explain_content` | Compact metadata explanation (same SQL artifact opt-in) |
53
+ | `run_chart` / `run_dashboard_tile` | Bounded saved execution; rows as data artifact by default |
54
+ | `export_chart_image` | PNG snapshot of a saved chart (vision); needs headless |
55
+ | `get_query_result` / `cancel_query` | Poll / cancel by `queryUuid` (rows as data artifact by default) |
56
56
 
57
57
  ## Phase 0 — Resolve project
58
58
 
59
59
  1. Always pass **`projectUuid`** (or rely on HTTP `X-Lightdash-Project` pin). Without either → `PROJECT_SCOPE_REQUIRED`; stop.
60
- 2. Call `get_project`. Record UUID, name, `context.projectPinned`, and `readerCapabilities` (`canExecuteSavedCharts`, `canExecuteSqlCharts`, `canExecuteDashboardTiles`, `canExecuteDashboardSqlTiles`).
60
+ 2. Call `get_project`. Record UUID, name, `context.projectPinned`, and `readerCapabilities` (`canExecuteSavedCharts`, `canExecuteSqlCharts`, `canExecuteDashboardTiles`, `canExecuteDashboardSqlTiles`, `canRevealSqlBodies`).
61
61
  3. There is **no** org-wide project list on this profile — never invent one.
62
62
 
63
63
  ## Answer shape
@@ -11,13 +11,15 @@ URI: `lightdash://playbooks/content-reader/explain-run`
11
11
 
12
12
  ## SQL vs semantic (critical)
13
13
 
14
- | Signal | Action |
15
- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
16
- | Search `source=sql` | Do **not** call `run_chart`; explain metadata only; cite `CONTENT_NOT_EXECUTABLE` / `canExecuteSqlCharts=false` |
17
- | `get_chart` → `chartType=sql` + warnings | Same — saved SQL **chart** body hidden; standalone execution disabled |
18
- | Dashboard tile `type=sql_chart` and `executable=true` | Call `run_dashboard_tile` (not `run_chart`). Cite `canExecuteDashboardSqlTiles=true`. SQL text stays hidden |
19
- | Opaque API errors (e.g. “Saved query not found”) on SQL ids | Treat as non-executable; do not retry endlessly |
20
- | `readerCapabilities.canExecuteSqlCharts=false` | Hard stop for **standalone** SQL chart execution (`run_chart`); dashboard SQL tiles use the dashboard-sql-chart API |
14
+ | Signal | Action |
15
+ | ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
16
+ | Search `source=sql` | Do **not** call `run_chart`; use `get_chart` / `explain_content` for metadata; cite `canExecuteSqlCharts=false` |
17
+ | Need authored SQL body | Pass `includeArtifacts=["sql"]` on `get_chart` / `explain_content` / `run_dashboard_tile`. SQL arrives as a separate MCP `resource` part |
18
+ | Warning `SQL_ARTIFACT_AVAILABLE` | SQL exists but was not attached — re-call with `includeArtifacts` including `sql` if the user asked to see SQL |
19
+ | Dashboard tile `type=sql_chart` and `executable=true` | Call `run_dashboard_tile` (not `run_chart`). Cite `canExecuteDashboardSqlTiles=true`. Default rows artifact; SQL only with `includeArtifacts` |
20
+ | Opaque API errors (e.g. “Saved query not found”) on SQL ids | Treat as non-executable; do not retry endlessly |
21
+ | `readerCapabilities.canExecuteSqlCharts=false` | Hard stop for **standalone** SQL chart execution (`run_chart`); dashboard SQL tiles use the dashboard-sql-chart API |
22
+ | `readerCapabilities.canRevealSqlBodies=true` | Authored SQL reveal allowed via artifacts only — never invent SQL |
21
23
 
22
24
  ## Decide whether to execute
23
25
 
@@ -40,7 +40,7 @@ Procedure:
40
40
  1. get_project; record analystCapabilities.
41
41
  2. list_explores (search+limit≤15) → get_explore → lock exploreName.
42
42
  3. Copy fieldIds from list_dimensions / list_metrics (or get_explore base-table metrics). Never invent fieldIds.
43
- 4. Optional compile_query; then run_metric_query with small limit. Poll get_query_result if needed.
43
+ 4. Optional compile_query; then run_metric_query with small limit (rows arrive as a data artifact). Poll get_query_result if needed.
44
44
  5. Iterate filters/fields. Do not save charts unless the user asks.`,
45
45
  invariantIds,
46
46
  requiredTopics: [TOPIC_EXPLORE],
@@ -21,19 +21,19 @@ Explore a Lightdash project's semantic layer and **run unsaved metric queries**
21
21
  | `list_explores` | Always `search` + `limit≤15`; inspect ≤10 candidates |
22
22
  | Field shortlists | Prefer base-table dimensions; explore-local metrics |
23
23
  | `run_metric_query` | Prefer `limit≤100` (hard max 1000); ≤5 exploratory runs per answer unless asked |
24
- | Result rows kept in the answer | ≤20 (even if more returned) |
25
- | `get_query_result` polls | Only while status is non-terminal |
24
+ | Result rows kept in the answer | ≤20 (even if more returned via data artifact) |
25
+ | `get_query_result` polls | Only while status is non-terminal; rows are data artifacts, not `data.rows` |
26
26
 
27
27
  ## Allowed tools (`lightdash_*`)
28
28
 
29
- | Tool | Use for |
30
- | ----------------------------------- | ------------------------------------------- |
31
- | `get_project` | Resolve project; read `analystCapabilities` |
32
- | `list_explores` / `get_explore` | Find and lock an explore |
33
- | `list_dimensions` / `list_metrics` | Copy fieldIds |
34
- | `compile_query` | Optional SQL pre-flight (no warehouse rows) |
35
- | `run_metric_query` | Bounded ad-hoc execution |
36
- | `get_query_result` / `cancel_query` | Poll / cancel by `queryUuid` |
29
+ | Tool | Use for |
30
+ | ----------------------------------- | --------------------------------------------------------- |
31
+ | `get_project` | Resolve project; read `analystCapabilities` |
32
+ | `list_explores` / `get_explore` | Find and lock an explore |
33
+ | `list_dimensions` / `list_metrics` | Copy fieldIds |
34
+ | `compile_query` | Optional SQL pre-flight (no warehouse rows) |
35
+ | `run_metric_query` | Bounded ad-hoc execution; rows as data artifact (default) |
36
+ | `get_query_result` / `cancel_query` | Poll / cancel by `queryUuid` (same artifact shape) |
37
37
 
38
38
  ## Phase 0 — Resolve project
39
39
 
@@ -17,7 +17,8 @@ Answer a data question by iterating Explore-style queries **without saving** a c
17
17
  - `exploreName` = locked explore name
18
18
  - `dimensions` / `metrics` = full **fieldIds** only (`{table}_{name}`)
19
19
  - `filters` (dimensions/metrics only) / `sorts` / `limit` as needed — never send `tableCalculations`
20
- 7. If status is running, poll `get_query_result` with the returned `queryUuid`. Cancel with `cancel_query` when abandoning.
20
+ - Rows are a **data artifact** by default (not inlined in the summary). Read `content[]` resource parts or `artifacts` catalog — do not expect `data.rows` in the summary JSON.
21
+ 7. If status is running, poll `get_query_result` with the returned `queryUuid` (same artifact shape). Cancel with `cancel_query` when abandoning.
21
22
  8. Iterate: change dims/metrics/filters and re-run. Do **not** create charts unless the user asks to save (then hand off to content-developer).
22
23
 
23
24
  ## Coverage
@@ -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 preClass = await (0, chart_source_js_1.classifyChartSource)(c, scope.projectUuid, args.contentUuidOrSlug);
37
- if (preClass === 'sql') {
38
- return (0, reader_tool_helpers_js_1.codedErrorResult)('CONTENT_NOT_EXECUTABLE', 'Saved SQL chart definitions are not loaded via the semantic chart API on content-reader');
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 = ((_a = chart.metricQuery) !== null && _a !== void 0 ? _a : {});
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
+ }
@@ -19,6 +19,7 @@ const READER_CAPABILITIES = {
19
19
  canExecuteSqlCharts: false,
20
20
  canExecuteDashboardTiles: true,
21
21
  canExecuteDashboardSqlTiles: true,
22
+ canRevealSqlBodies: true,
22
23
  };
23
24
  const DEVELOPER_CAPABILITIES = {
24
25
  canDiscoverContent: true,
@@ -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' ? ['SQL text is hidden; SQL chart execution is disabled by default'] : [],
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 semantic chart definition (saved SQL chart bodies stay hidden; tableCalculations expressions included when includeQueryDefinition)',
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 preClass = await (0, chart_source_js_1.classifyChartSource)(c, scope.projectUuid, args.chartUuidOrSlug);
269
- if (preClass === 'sql') {
270
- return (0, reader_tool_helpers_js_1.codedErrorResult)('CONTENT_NOT_EXECUTABLE', 'Saved SQL chart definitions are not loaded via the semantic chart API on content-reader');
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,4 @@
1
+ /**
2
+ * get_chart SQL reveal + summary helpers (ADR-0032).
3
+ */
4
+ export {};