@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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve saved SQL charts via sqlRunner GET (ADR-0032 reveal path).
|
|
3
|
+
*/
|
|
4
|
+
import type { LightdashClient, SqlChart } from '@lightdash-tools/client';
|
|
5
|
+
/**
|
|
6
|
+
* Fetch a saved SQL chart by UUID or slug (authored SQL included in the client payload).
|
|
7
|
+
* Callers must keep `sql` out of the MCP summary body (artifact opt-in only).
|
|
8
|
+
* Non-404 API failures are rethrown (not treated as “try another path”).
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveSavedSqlChart(client: LightdashClient, projectUuid: string, chartUuidOrSlug: string): Promise<SqlChart>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve saved SQL charts via sqlRunner GET (ADR-0032 reveal path).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveSavedSqlChart = resolveSavedSqlChart;
|
|
7
|
+
const common_1 = require("@lightdash-tools/common");
|
|
8
|
+
const api_errors_js_1 = require("../lib/api-errors.js");
|
|
9
|
+
const chart_source_js_1 = require("./chart-source.js");
|
|
10
|
+
function looksLikeUuid(id) {
|
|
11
|
+
try {
|
|
12
|
+
(0, common_1.validateUuid)(id);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetch a saved SQL chart by UUID or slug (authored SQL included in the client payload).
|
|
21
|
+
* Callers must keep `sql` out of the MCP summary body (artifact opt-in only).
|
|
22
|
+
* Non-404 API failures are rethrown (not treated as “try another path”).
|
|
23
|
+
*/
|
|
24
|
+
async function resolveSavedSqlChart(client, projectUuid, chartUuidOrSlug) {
|
|
25
|
+
if (looksLikeUuid(chartUuidOrSlug)) {
|
|
26
|
+
try {
|
|
27
|
+
return await client.v1.sqlRunner.getSavedSqlChart(projectUuid, chartUuidOrSlug);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (!(0, api_errors_js_1.isNotFoundError)(err)) {
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return await client.v1.sqlRunner.getSavedSqlChartBySlug(projectUuid, chartUuidOrSlug);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (!(0, api_errors_js_1.isNotFoundError)(err)) {
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const match = await (0, chart_source_js_1.findChartContentMatch)(client, projectUuid, chartUuidOrSlug);
|
|
44
|
+
if (!match || match.source !== 'sql') {
|
|
45
|
+
throw new Error(`Saved SQL chart '${chartUuidOrSlug}' was not found`);
|
|
46
|
+
}
|
|
47
|
+
return client.v1.sqlRunner.getSavedSqlChart(projectUuid, match.uuid);
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@lightdash-tools/client");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const resolve_saved_sql_chart_js_1 = require("./resolve-saved-sql-chart.js");
|
|
6
|
+
const SAVED = 'ffff6666-aaaa-4bbb-8ccc-dddddddddddd';
|
|
7
|
+
const chart = {
|
|
8
|
+
savedSqlUuid: SAVED,
|
|
9
|
+
name: 'SQL KPI',
|
|
10
|
+
slug: 'sql-kpi',
|
|
11
|
+
sql: 'SELECT 1',
|
|
12
|
+
limit: 500,
|
|
13
|
+
};
|
|
14
|
+
(0, vitest_1.describe)('resolveSavedSqlChart', () => {
|
|
15
|
+
(0, vitest_1.it)('returns SQL chart by UUID on first GET', async () => {
|
|
16
|
+
const getSavedSqlChart = vitest_1.vi.fn().mockResolvedValue(chart);
|
|
17
|
+
const client = {
|
|
18
|
+
v1: { sqlRunner: { getSavedSqlChart, getSavedSqlChartBySlug: vitest_1.vi.fn() } },
|
|
19
|
+
v2: { content: { searchContent: vitest_1.vi.fn() } },
|
|
20
|
+
};
|
|
21
|
+
await (0, vitest_1.expect)((0, resolve_saved_sql_chart_js_1.resolveSavedSqlChart)(client, 'p1', SAVED)).resolves.toEqual(chart);
|
|
22
|
+
(0, vitest_1.expect)(getSavedSqlChart).toHaveBeenCalledWith('p1', SAVED);
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)('falls through to slug only on 404 for UUID GET', async () => {
|
|
25
|
+
const getSavedSqlChart = vitest_1.vi
|
|
26
|
+
.fn()
|
|
27
|
+
.mockRejectedValueOnce(new client_1.LightdashApiError(404, { name: 'NotFound', statusCode: 404, message: 'missing' }, {}));
|
|
28
|
+
const getSavedSqlChartBySlug = vitest_1.vi.fn().mockResolvedValue(chart);
|
|
29
|
+
const client = {
|
|
30
|
+
v1: { sqlRunner: { getSavedSqlChart, getSavedSqlChartBySlug } },
|
|
31
|
+
v2: { content: { searchContent: vitest_1.vi.fn() } },
|
|
32
|
+
};
|
|
33
|
+
await (0, vitest_1.expect)((0, resolve_saved_sql_chart_js_1.resolveSavedSqlChart)(client, 'p1', SAVED)).resolves.toEqual(chart);
|
|
34
|
+
(0, vitest_1.expect)(getSavedSqlChartBySlug).toHaveBeenCalledWith('p1', SAVED);
|
|
35
|
+
});
|
|
36
|
+
(0, vitest_1.it)('rethrows non-404 errors from UUID GET', async () => {
|
|
37
|
+
const getSavedSqlChart = vitest_1.vi
|
|
38
|
+
.fn()
|
|
39
|
+
.mockRejectedValue(new client_1.LightdashApiError(503, { name: 'Unavailable', statusCode: 503, message: 'down' }, {}));
|
|
40
|
+
const getSavedSqlChartBySlug = vitest_1.vi.fn();
|
|
41
|
+
const client = {
|
|
42
|
+
v1: { sqlRunner: { getSavedSqlChart, getSavedSqlChartBySlug } },
|
|
43
|
+
v2: { content: { searchContent: vitest_1.vi.fn() } },
|
|
44
|
+
};
|
|
45
|
+
await (0, vitest_1.expect)((0, resolve_saved_sql_chart_js_1.resolveSavedSqlChart)(client, 'p1', SAVED)).rejects.toMatchObject({
|
|
46
|
+
statusCode: 503,
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.expect)(getSavedSqlChartBySlug).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -8,12 +8,13 @@ exports.registerRunMetricQuery = registerRunMetricQuery;
|
|
|
8
8
|
const zod_1 = require("zod");
|
|
9
9
|
const project_scope_js_1 = require("../../governance/project-scope.js");
|
|
10
10
|
const content_reader_js_1 = require("../../policy/content-reader.js");
|
|
11
|
-
const envelope_js_1 = require("../../policy/envelope.js");
|
|
12
11
|
const result_limits_js_1 = require("../../policy/result-limits.js");
|
|
12
|
+
const artifacts_js_1 = require("../lib/artifacts.js");
|
|
13
13
|
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
14
14
|
const shared_js_1 = require("../shared.js");
|
|
15
15
|
const types_js_1 = require("../types.js");
|
|
16
16
|
const bounded_saved_query_js_1 = require("./bounded-saved-query.js");
|
|
17
|
+
const query_artifact_result_js_1 = require("./query-artifact-result.js");
|
|
17
18
|
const reader_tool_helpers_js_1 = require("./reader-tool-helpers.js");
|
|
18
19
|
const sortFieldSchema = zod_1.z.object({
|
|
19
20
|
fieldId: zod_1.z.string(),
|
|
@@ -39,11 +40,12 @@ const runMetricQueryInputSchema = zod_1.z.object({
|
|
|
39
40
|
limit: zod_1.z.number().int().positive().optional(),
|
|
40
41
|
waitForResults: zod_1.z.boolean().optional(),
|
|
41
42
|
timeoutMs: zod_1.z.number().int().nonnegative().optional(),
|
|
43
|
+
includeArtifacts: (0, artifacts_js_1.includeArtifactsField)(['data']),
|
|
42
44
|
});
|
|
43
45
|
function registerRunMetricQuery(server, contextProvider) {
|
|
44
46
|
(0, content_reader_js_1.registerContentReaderTool)(server, 'run_metric_query', {
|
|
45
47
|
title: 'Run metric query',
|
|
46
|
-
description: 'Execute an unsaved explore metric query (dimensions, metrics, filters, sorts). Bounded rows; no chart save; no tableCalculations/SQL. Prefer fieldIds from get_explore / list_dimensions / list_metrics.',
|
|
48
|
+
description: 'Execute an unsaved explore metric query (dimensions, metrics, filters, sorts). Bounded rows as a separate data artifact by default (same shape as get_query_result); no chart save; no tableCalculations/SQL. Prefer fieldIds from get_explore / list_dimensions / list_metrics.',
|
|
47
49
|
safety: content_reader_js_1.METRIC_QUERY_SAFETY,
|
|
48
50
|
inputSchema: runMetricQueryInputSchema.shape,
|
|
49
51
|
}, (profile) => (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
@@ -51,6 +53,7 @@ function registerRunMetricQuery(server, contextProvider) {
|
|
|
51
53
|
try {
|
|
52
54
|
const scope = (0, project_scope_js_1.resolveProjectScope)({ projectUuid: args.projectUuid });
|
|
53
55
|
const limit = (0, result_limits_js_1.clampRowLimit)(args.limit);
|
|
56
|
+
const include = (0, artifacts_js_1.parseIncludeArtifacts)(args.includeArtifacts, ['data']);
|
|
54
57
|
const body = {
|
|
55
58
|
query: {
|
|
56
59
|
exploreName: args.exploreName,
|
|
@@ -77,14 +80,15 @@ function registerRunMetricQuery(server, contextProvider) {
|
|
|
77
80
|
if (!bounded.ok) {
|
|
78
81
|
return bounded.result;
|
|
79
82
|
}
|
|
80
|
-
return (0,
|
|
83
|
+
return (0, query_artifact_result_js_1.buildQueryArtifactResult)({
|
|
81
84
|
profile,
|
|
82
85
|
projectUuid: scope.projectUuid,
|
|
83
86
|
projectPinned: scope.projectPinned,
|
|
87
|
+
normalized: bounded.normalized,
|
|
88
|
+
include,
|
|
84
89
|
complete: (0, reader_tool_helpers_js_1.isCoverageComplete)(bounded.normalized),
|
|
85
|
-
truncated: bounded.normalized.truncated,
|
|
86
90
|
warnings: bounded.warnings,
|
|
87
|
-
})
|
|
91
|
+
});
|
|
88
92
|
}
|
|
89
93
|
catch (err) {
|
|
90
94
|
if (err instanceof result_limits_js_1.ResultLimitError) {
|
|
@@ -40,6 +40,7 @@ const PROJECT = '550e8400-e29b-41d4-a716-446655440000';
|
|
|
40
40
|
(0, vitest_1.expect)(toolName).toBe('lightdash_run_metric_query');
|
|
41
41
|
const sessionId = (0, mcp_client_session_js_1.resolveMcpClientSessionId)({ sessionId: 'mcp-analyst-1' });
|
|
42
42
|
await (0, mcp_client_session_js_1.runWithMcpClientSessionAsync)(sessionId, async () => {
|
|
43
|
+
var _a;
|
|
43
44
|
const result = await handler({
|
|
44
45
|
projectUuid: PROJECT,
|
|
45
46
|
exploreName: 'orders',
|
|
@@ -64,9 +65,13 @@ const PROJECT = '550e8400-e29b-41d4-a716-446655440000';
|
|
|
64
65
|
const body = JSON.parse(result.content[0].text);
|
|
65
66
|
(0, vitest_1.expect)(body.data.queryUuid).toBe('q-metric');
|
|
66
67
|
(0, vitest_1.expect)(body.data.status).toBe('complete');
|
|
68
|
+
(0, vitest_1.expect)(body.data.rows).toBeUndefined();
|
|
67
69
|
(0, vitest_1.expect)(body.context.profile).toBe('data-analyst');
|
|
68
70
|
(0, vitest_1.expect)(body.context.projectUuid).toBe(PROJECT);
|
|
69
71
|
(0, vitest_1.expect)(body.coverage.complete).toBe(true);
|
|
72
|
+
(0, vitest_1.expect)(body.artifacts).toEqual([vitest_1.expect.objectContaining({ kind: 'data', included: true })]);
|
|
73
|
+
const dataPart = result.content.find((c) => { var _a; return c.type === 'resource' && ((_a = c.resource) === null || _a === void 0 ? void 0 : _a.mimeType) === 'application/json'; });
|
|
74
|
+
(0, vitest_1.expect)((_a = dataPart === null || dataPart === void 0 ? void 0 : dataPart.resource) === null || _a === void 0 ? void 0 : _a.text).toContain('orders_order_id');
|
|
70
75
|
});
|
|
71
76
|
});
|
|
72
77
|
(0, vitest_1.it)('rejects limit above hard maximum', async () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const shared_js_1 = require("./shared.js");
|
|
5
|
+
(0, vitest_1.describe)('artifactToolResult', () => {
|
|
6
|
+
(0, vitest_1.it)('returns summary text plus embedded resource parts', () => {
|
|
7
|
+
const result = (0, shared_js_1.artifactToolResult)({
|
|
8
|
+
summary: { data: { queryUuid: 'q1' }, context: { profile: 'content-reader' } },
|
|
9
|
+
artifacts: [
|
|
10
|
+
{
|
|
11
|
+
kind: 'data',
|
|
12
|
+
uri: 'lightdash://artifacts/content-reader/data/q1',
|
|
13
|
+
mimeType: 'application/json',
|
|
14
|
+
text: '[{"a":1}]',
|
|
15
|
+
audience: ['assistant', 'user'],
|
|
16
|
+
priority: 0.8,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
kind: 'sql',
|
|
20
|
+
uri: 'lightdash://artifacts/content-reader/sql/s1',
|
|
21
|
+
mimeType: 'text/sql',
|
|
22
|
+
text: 'SELECT 1',
|
|
23
|
+
audience: ['assistant', 'user'],
|
|
24
|
+
priority: 0.6,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
catalog: [
|
|
28
|
+
{
|
|
29
|
+
kind: 'data',
|
|
30
|
+
uri: 'lightdash://artifacts/content-reader/data/q1',
|
|
31
|
+
mimeType: 'application/json',
|
|
32
|
+
included: true,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
kind: 'sql',
|
|
36
|
+
uri: 'lightdash://artifacts/content-reader/sql/s1',
|
|
37
|
+
mimeType: 'text/sql',
|
|
38
|
+
included: true,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.expect)(result.content).toHaveLength(3);
|
|
43
|
+
(0, vitest_1.expect)(result.content[0]).toMatchObject({ type: 'text' });
|
|
44
|
+
(0, vitest_1.expect)(result.content[1]).toMatchObject({
|
|
45
|
+
type: 'resource',
|
|
46
|
+
resource: {
|
|
47
|
+
uri: 'lightdash://artifacts/content-reader/data/q1',
|
|
48
|
+
mimeType: 'application/json',
|
|
49
|
+
text: '[{"a":1}]',
|
|
50
|
+
},
|
|
51
|
+
annotations: { audience: ['assistant', 'user'], priority: 0.8 },
|
|
52
|
+
});
|
|
53
|
+
(0, vitest_1.expect)(result.content[2]).toMatchObject({
|
|
54
|
+
type: 'resource',
|
|
55
|
+
resource: { mimeType: 'text/sql', text: 'SELECT 1' },
|
|
56
|
+
annotations: { audience: ['assistant', 'user'], priority: 0.6 },
|
|
57
|
+
});
|
|
58
|
+
(0, vitest_1.expect)(result.structuredContent).toMatchObject({
|
|
59
|
+
data: { queryUuid: 'q1' },
|
|
60
|
+
artifacts: [
|
|
61
|
+
{ kind: 'data', included: true },
|
|
62
|
+
{ kind: 'sql', included: true },
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
const summaryText = result.content[0].text;
|
|
66
|
+
(0, vitest_1.expect)(summaryText).not.toContain('SELECT 1');
|
|
67
|
+
(0, vitest_1.expect)(summaryText).not.toContain('[{"a":1}]');
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)('omits resource parts when catalog marks artifacts not included', () => {
|
|
70
|
+
var _a;
|
|
71
|
+
const result = (0, shared_js_1.artifactToolResult)({
|
|
72
|
+
summary: { ok: true },
|
|
73
|
+
artifacts: [],
|
|
74
|
+
catalog: [
|
|
75
|
+
{
|
|
76
|
+
kind: 'sql',
|
|
77
|
+
uri: 'lightdash://artifacts/content-reader/sql/s1',
|
|
78
|
+
mimeType: 'text/sql',
|
|
79
|
+
included: false,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
(0, vitest_1.expect)(result.content).toHaveLength(1);
|
|
84
|
+
(0, vitest_1.expect)((_a = result.structuredContent) === null || _a === void 0 ? void 0 : _a.artifacts).toEqual([
|
|
85
|
+
{
|
|
86
|
+
kind: 'sql',
|
|
87
|
+
uri: 'lightdash://artifacts/content-reader/sql/s1',
|
|
88
|
+
mimeType: 'text/sql',
|
|
89
|
+
included: false,
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
});
|
package/dist/tools/shared.d.ts
CHANGED
|
@@ -22,7 +22,20 @@ export type ImageContentBlock = {
|
|
|
22
22
|
data: string;
|
|
23
23
|
mimeType: string;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
/** MCP embedded resource content block (tool-result artifacts). */
|
|
26
|
+
export type ResourceContentBlock = {
|
|
27
|
+
type: 'resource';
|
|
28
|
+
resource: {
|
|
29
|
+
uri: string;
|
|
30
|
+
mimeType?: string;
|
|
31
|
+
text: string;
|
|
32
|
+
};
|
|
33
|
+
annotations?: {
|
|
34
|
+
audience?: Array<'assistant' | 'user'>;
|
|
35
|
+
priority?: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type ToolContentBlock = ImageContentBlock | ResourceContentBlock | {
|
|
26
39
|
type: 'text';
|
|
27
40
|
text: string;
|
|
28
41
|
};
|
|
@@ -31,6 +44,22 @@ export type TextContent = {
|
|
|
31
44
|
structuredContent?: Record<string, unknown>;
|
|
32
45
|
isError?: boolean;
|
|
33
46
|
};
|
|
47
|
+
/** Kind of bulky payload kept out of the compact summary body (ADR-0032). */
|
|
48
|
+
export type ToolArtifactKind = 'data' | 'sql';
|
|
49
|
+
export type ToolArtifactSpec = {
|
|
50
|
+
kind: ToolArtifactKind;
|
|
51
|
+
uri: string;
|
|
52
|
+
mimeType: string;
|
|
53
|
+
text: string;
|
|
54
|
+
audience: Array<'assistant' | 'user'>;
|
|
55
|
+
priority?: number;
|
|
56
|
+
};
|
|
57
|
+
export type ToolArtifactCatalogEntry = {
|
|
58
|
+
kind: ToolArtifactKind;
|
|
59
|
+
uri: string;
|
|
60
|
+
mimeType: string;
|
|
61
|
+
included: boolean;
|
|
62
|
+
};
|
|
34
63
|
/** Handler return type: normal tool content or MCP 2026-07-28 MRTR InputRequiredResult. */
|
|
35
64
|
export type ToolResult = InputRequiredResult | TextContent;
|
|
36
65
|
/** Builds a tool result with JSON text and matching structuredContent. */
|
|
@@ -51,6 +80,16 @@ export declare function imageToolResult(args: {
|
|
|
51
80
|
imageBase64: string;
|
|
52
81
|
mimeType?: string;
|
|
53
82
|
}): TextContent;
|
|
83
|
+
/**
|
|
84
|
+
* Compact summary + optional embedded resource artifacts (ADR-0032).
|
|
85
|
+
* Spec: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-result
|
|
86
|
+
* structuredContent holds summary only (no SQL body / row payloads).
|
|
87
|
+
*/
|
|
88
|
+
export declare function artifactToolResult(args: {
|
|
89
|
+
summary: object;
|
|
90
|
+
artifacts?: ToolArtifactSpec[];
|
|
91
|
+
catalog?: ToolArtifactCatalogEntry[];
|
|
92
|
+
}): TextContent;
|
|
54
93
|
/** Tool handler type used to avoid deep instantiation with SDK/Zod. Accepts (args, extra) for SDK compatibility. */
|
|
55
94
|
export type ToolHandler = (args: unknown, extra?: unknown) => Promise<ToolResult>;
|
|
56
95
|
/** Options for registerTool; inputSchema typed as ZodRawShapeCompat for SDK compatibility. Pass annotations explicitly (e.g. READ_ONLY_DEFAULT or WRITE_IDEMPOTENT) for visibility. */
|
package/dist/tools/shared.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.READ_ONLY_DEFAULT = exports.TOOL_PREFIX = void 0;
|
|
|
15
15
|
exports.jsonToolResult = jsonToolResult;
|
|
16
16
|
exports.toolErrorResult = toolErrorResult;
|
|
17
17
|
exports.imageToolResult = imageToolResult;
|
|
18
|
+
exports.artifactToolResult = artifactToolResult;
|
|
18
19
|
exports.blockedToolContent = blockedToolContent;
|
|
19
20
|
exports.withLightdashBlockedMarker = withLightdashBlockedMarker;
|
|
20
21
|
exports.withAuditStatus = withAuditStatus;
|
|
@@ -75,6 +76,38 @@ function imageToolResult(args) {
|
|
|
75
76
|
structuredContent: toStructuredContent(args.meta),
|
|
76
77
|
};
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Compact summary + optional embedded resource artifacts (ADR-0032).
|
|
81
|
+
* Spec: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-result
|
|
82
|
+
* structuredContent holds summary only (no SQL body / row payloads).
|
|
83
|
+
*/
|
|
84
|
+
function artifactToolResult(args) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const artifacts = (_a = args.artifacts) !== null && _a !== void 0 ? _a : [];
|
|
87
|
+
const catalog = (_b = args.catalog) !== null && _b !== void 0 ? _b : artifacts.map((a) => ({
|
|
88
|
+
kind: a.kind,
|
|
89
|
+
uri: a.uri,
|
|
90
|
+
mimeType: a.mimeType,
|
|
91
|
+
included: true,
|
|
92
|
+
}));
|
|
93
|
+
const summary = Object.assign({}, args.summary, { artifacts: catalog });
|
|
94
|
+
const content = [
|
|
95
|
+
{ type: 'text', text: JSON.stringify(summary, null, 2) },
|
|
96
|
+
...artifacts.map((a) => ({
|
|
97
|
+
type: 'resource',
|
|
98
|
+
resource: {
|
|
99
|
+
uri: a.uri,
|
|
100
|
+
mimeType: a.mimeType,
|
|
101
|
+
text: a.text,
|
|
102
|
+
},
|
|
103
|
+
annotations: Object.assign({ audience: a.audience }, (a.priority !== undefined ? { priority: a.priority } : {})),
|
|
104
|
+
})),
|
|
105
|
+
];
|
|
106
|
+
return {
|
|
107
|
+
content,
|
|
108
|
+
structuredContent: toStructuredContent(summary),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
78
111
|
/**
|
|
79
112
|
* When a handler returns JSON text only, attach structuredContent for MCP clients.
|
|
80
113
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance,
|
|
3
|
+
"version": "0.20.0",
|
|
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": {
|
|
7
7
|
"type": "git",
|
|
@@ -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/client": "0.
|
|
28
|
-
"@lightdash-tools/common": "0.
|
|
27
|
+
"@lightdash-tools/client": "0.20.0",
|
|
28
|
+
"@lightdash-tools/common": "0.20.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@modelcontextprotocol/client": "2.0.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance ai-agent-ops data-analyst; do mkdir -p dist/profiles/$p/v1/resources/playbooks && cp -R src/profiles/$p/v1/resources/playbooks/. dist/profiles/$p/v1/resources/playbooks/; done",
|
|
38
|
+
"build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance ai-agent-ops ai-agent-chat data-analyst; do mkdir -p dist/profiles/$p/v1/resources/playbooks && cp -R src/profiles/$p/v1/resources/playbooks/. dist/profiles/$p/v1/resources/playbooks/; done",
|
|
39
39
|
"start:http": "node dist/bin.js http",
|
|
40
40
|
"start:stdio": "node dist/bin.js stdio --profile semantic-layer",
|
|
41
41
|
"test": "pnpm --dir ../.. exec vitest run packages/mcp/src"
|