@lightdash-tools/mcp 0.13.1 → 0.14.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 +56 -11
- package/dist/auth/request-state-key.d.ts +1 -1
- package/dist/auth/request-state-key.js +1 -1
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +2 -2
- package/dist/auth/resource-server/oauth-protected-resource.js +8 -7
- package/dist/bin.js +1 -1
- package/dist/config/enabled-profiles.d.ts +23 -0
- package/dist/config/enabled-profiles.js +57 -0
- package/dist/config/enabled-profiles.test.d.ts +1 -0
- package/dist/config/enabled-profiles.test.js +62 -0
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +3 -1
- package/dist/config/load-mcp-config.d.ts +3 -0
- package/dist/config/load-mcp-config.js +20 -23
- package/dist/config/load-mcp-config.test.js +41 -0
- package/dist/config/obsolete-env.js +2 -8
- package/dist/config/read-env.d.ts +4 -0
- package/dist/config/read-env.js +13 -0
- package/dist/config/test-mcp-http-config.js +4 -1
- package/dist/http.integration.test.js +47 -24
- package/dist/index.integration.test.js +3 -12
- package/dist/profiles/content-developer/v1/prompts.js +3 -2
- package/dist/profiles/content-developer/v1/prompts.test.js +8 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/chart-types.md +3 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/core.md +18 -16
- package/dist/profiles/content-developer/v1/resources/playbooks/dashboard-design.md +11 -1
- package/dist/profiles/content-developer/v1/resources/playbooks/dashboards.md +2 -2
- package/dist/profiles/content-developer/v1/resources/playbooks/index.md +8 -7
- package/dist/profiles/content-developer/v1/resources/playbooks/table-calculations.md +131 -0
- package/dist/profiles/content-developer/v1/resources/playbooks.d.ts +1 -1
- package/dist/profiles/content-developer/v1/resources/playbooks.js +8 -1
- package/dist/profiles/content-reader/v1/index.js +1 -0
- package/dist/profiles/content-reader/v1/prompts.js +10 -9
- package/dist/profiles/content-reader/v1/resources/playbooks/compare.md +1 -1
- package/dist/profiles/content-reader/v1/resources/playbooks/core.md +12 -11
- package/dist/profiles/content-reader/v1/resources/playbooks/discover.md +12 -3
- package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +3 -2
- package/dist/profiles/index.d.ts +2 -1
- package/dist/profiles/index.js +2 -1
- package/dist/profiles/index.test.js +2 -1
- package/dist/stdio.process.test.js +2 -1
- package/dist/tools/project/reader-content.d.ts +4 -0
- package/dist/tools/project/reader-content.js +61 -6
- package/dist/tools/project/reader-content.test.d.ts +4 -0
- package/dist/tools/project/reader-content.test.js +64 -0
- package/dist/transports/streamable-http.js +6 -3
- package/dist/transports/streamable-http.test.js +16 -0
- package/package.json +3 -3
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeTestMcpHttpConfig = makeTestMcpHttpConfig;
|
|
4
|
+
const enabled_profiles_js_1 = require("./enabled-profiles.js");
|
|
4
5
|
/** Shared base `McpHttpConfig` for MCP package unit/integration tests. */
|
|
5
6
|
function makeTestMcpHttpConfig(overrides) {
|
|
6
|
-
|
|
7
|
+
var _a;
|
|
8
|
+
const enabledProfiles = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.enabledProfiles) !== null && _a !== void 0 ? _a : enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES;
|
|
9
|
+
return Object.assign({ lightdashUrl: 'https://app.lightdash.cloud', host: '127.0.0.1', port: 3100, publicUrl: 'https://mcp.example.com', mcpPath: (0, enabled_profiles_js_1.resolveRootMcpPath)(enabledProfiles), enabledProfiles, authMode: 'lightdash-oauth', allowedOrigins: [], maxBodyBytes: 1024, requiredScopes: ['mcp:read'], scopesSupported: ['mcp:read', 'mcp:write'], validateToken: true, tokenValidationCacheTtlMs: 30000 }, overrides);
|
|
7
10
|
}
|
|
@@ -5,6 +5,8 @@ const client_1 = require("@lightdash-tools/client");
|
|
|
5
5
|
const server_1 = require("@modelcontextprotocol/server");
|
|
6
6
|
const vitest_1 = require("vitest");
|
|
7
7
|
const oauth_protected_resource_js_1 = require("./auth/resource-server/oauth-protected-resource.js");
|
|
8
|
+
const enabled_profiles_js_1 = require("./config/enabled-profiles.js");
|
|
9
|
+
const test_mcp_http_config_js_1 = require("./config/test-mcp-http-config.js");
|
|
8
10
|
const streamable_http_js_1 = require("./transports/streamable-http.js");
|
|
9
11
|
const TOKEN_A = scopedAccessToken('mcp:read mcp:write', 'token-a');
|
|
10
12
|
const TOKEN_B = scopedAccessToken('mcp:read mcp:write', 'token-b');
|
|
@@ -115,23 +117,8 @@ async function startMockLightdashServer() {
|
|
|
115
117
|
}),
|
|
116
118
|
};
|
|
117
119
|
}
|
|
118
|
-
function baseOAuthConfig(lightdashUrl) {
|
|
119
|
-
return {
|
|
120
|
-
lightdashUrl,
|
|
121
|
-
host: '127.0.0.1',
|
|
122
|
-
port: 0,
|
|
123
|
-
publicUrl: 'http://127.0.0.1:0',
|
|
124
|
-
mcpPath: '/semantic-layer/v1/mcp',
|
|
125
|
-
authMode: 'lightdash-oauth',
|
|
126
|
-
oauthClientId: 'test-client-id',
|
|
127
|
-
oauthClientSecret: new client_1.SecretString('test-client-secret'),
|
|
128
|
-
allowedOrigins: [],
|
|
129
|
-
maxBodyBytes: 1024 * 1024,
|
|
130
|
-
requiredScopes: [],
|
|
131
|
-
scopesSupported: [],
|
|
132
|
-
validateToken: true,
|
|
133
|
-
tokenValidationCacheTtlMs: 30000,
|
|
134
|
-
};
|
|
120
|
+
function baseOAuthConfig(lightdashUrl, overrides) {
|
|
121
|
+
return (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)(Object.assign({ lightdashUrl, port: 0, publicUrl: 'http://127.0.0.1:0', oauthClientId: 'test-client-id', oauthClientSecret: new client_1.SecretString('test-client-secret'), maxBodyBytes: 1024 * 1024, requiredScopes: [], scopesSupported: [] }, overrides));
|
|
135
122
|
}
|
|
136
123
|
async function postMcp(baseUrl, body, options) {
|
|
137
124
|
var _a;
|
|
@@ -506,6 +493,46 @@ function parseSseOrJsonToolText(raw) {
|
|
|
506
493
|
(0, vitest_1.expect)(response.status).toBe(405);
|
|
507
494
|
});
|
|
508
495
|
});
|
|
496
|
+
(0, vitest_1.describe)('MCP HTTP profile mount allowlist', () => {
|
|
497
|
+
let mockLightdash;
|
|
498
|
+
let mcpServer;
|
|
499
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
500
|
+
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
501
|
+
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
502
|
+
mockLightdash = await startMockLightdashServer();
|
|
503
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(baseOAuthConfig(mockLightdash.baseUrl, {
|
|
504
|
+
enabledProfiles: (0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader'),
|
|
505
|
+
}));
|
|
506
|
+
});
|
|
507
|
+
(0, vitest_1.afterEach)(async () => {
|
|
508
|
+
await mcpServer.close();
|
|
509
|
+
await mockLightdash.close();
|
|
510
|
+
vitest_1.vi.restoreAllMocks();
|
|
511
|
+
});
|
|
512
|
+
(0, vitest_1.it)('404s disabled profile MCP paths and their path-specific PRM', async () => {
|
|
513
|
+
const mcpResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
|
|
514
|
+
(0, vitest_1.expect)(mcpResponse.status).toBe(404);
|
|
515
|
+
const prmResponse = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/semantic-layer/v1/mcp`);
|
|
516
|
+
(0, vitest_1.expect)(prmResponse.status).toBe(404);
|
|
517
|
+
});
|
|
518
|
+
(0, vitest_1.it)('keeps enabled profile MCP and PRM reachable', async () => {
|
|
519
|
+
const mcpResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
|
|
520
|
+
token: TOKEN_A,
|
|
521
|
+
path: '/content-reader/v1/mcp',
|
|
522
|
+
});
|
|
523
|
+
(0, vitest_1.expect)(mcpResponse.status).toBe(200);
|
|
524
|
+
const prmResponse = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/content-reader/v1/mcp`);
|
|
525
|
+
(0, vitest_1.expect)(prmResponse.status).toBe(200);
|
|
526
|
+
const metadata = (await prmResponse.json());
|
|
527
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`${mcpServer.baseUrl}/content-reader/v1/mcp`);
|
|
528
|
+
});
|
|
529
|
+
(0, vitest_1.it)('serves root PRM for the first enabled profile path', async () => {
|
|
530
|
+
const response = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource`);
|
|
531
|
+
(0, vitest_1.expect)(response.status).toBe(200);
|
|
532
|
+
const metadata = (await response.json());
|
|
533
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`${mcpServer.baseUrl}/content-reader/v1/mcp`);
|
|
534
|
+
});
|
|
535
|
+
});
|
|
509
536
|
(0, vitest_1.describe)('MCP HTTP shared-key integration', () => {
|
|
510
537
|
let mcpServer;
|
|
511
538
|
const originalEnv = Object.assign({}, process.env);
|
|
@@ -514,20 +541,16 @@ function parseSseOrJsonToolText(raw) {
|
|
|
514
541
|
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
515
542
|
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
516
543
|
process.env.LIGHTDASH_API_KEY = 'ldpat_test_key';
|
|
517
|
-
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)({
|
|
518
|
-
lightdashUrl: 'https://app.lightdash.cloud',
|
|
519
|
-
host: '127.0.0.1',
|
|
544
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)((0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
|
|
520
545
|
port: 0,
|
|
521
|
-
|
|
546
|
+
publicUrl: undefined,
|
|
522
547
|
authMode: 'shared-key',
|
|
523
548
|
sharedKey: new client_1.SecretString('shared-secret'),
|
|
524
|
-
allowedOrigins: [],
|
|
525
549
|
maxBodyBytes: 1024 * 1024,
|
|
526
550
|
requiredScopes: [],
|
|
527
551
|
scopesSupported: ['mcp:read'],
|
|
528
552
|
validateToken: false,
|
|
529
|
-
|
|
530
|
-
});
|
|
553
|
+
}));
|
|
531
554
|
});
|
|
532
555
|
(0, vitest_1.afterEach)(async () => {
|
|
533
556
|
await mcpServer.close();
|
|
@@ -7,6 +7,7 @@ const vitest_1 = require("vitest");
|
|
|
7
7
|
const env_context_provider_js_1 = require("./auth/providers/env-context-provider.js");
|
|
8
8
|
const lightdash_token_validation_js_1 = require("./auth/resource-server/lightdash-token-validation.js");
|
|
9
9
|
const runtime_js_1 = require("./config/runtime.js");
|
|
10
|
+
const test_mcp_http_config_js_1 = require("./config/test-mcp-http-config.js");
|
|
10
11
|
const server_js_1 = require("./server/server.js");
|
|
11
12
|
const shared_1 = require("./tools/shared");
|
|
12
13
|
const hasCredentials = !!process.env.LIGHTDASH_API_KEY && !!process.env.LIGHTDASH_URL;
|
|
@@ -55,20 +56,10 @@ vitest_1.describe.runIf(hasOAuthToken)('MCP Integration (OAuth access token)', (
|
|
|
55
56
|
var _a;
|
|
56
57
|
const lightdashUrl = process.env.LIGHTDASH_URL.replace(/\/$/, '');
|
|
57
58
|
const accessToken = process.env.LIGHTDASH_TOOLS_TEST_OAUTH_ACCESS_TOKEN;
|
|
58
|
-
const config = {
|
|
59
|
+
const config = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
|
|
59
60
|
lightdashUrl,
|
|
60
|
-
host: '127.0.0.1',
|
|
61
|
-
port: 3100,
|
|
62
|
-
publicUrl: 'https://mcp.example.com',
|
|
63
|
-
mcpPath: '/semantic-layer/v1/mcp',
|
|
64
|
-
authMode: 'lightdash-oauth',
|
|
65
|
-
allowedOrigins: [],
|
|
66
61
|
maxBodyBytes: 1024 * 1024,
|
|
67
|
-
|
|
68
|
-
scopesSupported: ['mcp:read', 'mcp:write'],
|
|
69
|
-
validateToken: true,
|
|
70
|
-
tokenValidationCacheTtlMs: 30000,
|
|
71
|
-
};
|
|
62
|
+
});
|
|
72
63
|
const user = await (0, lightdash_token_validation_js_1.validateLightdashAccessToken)(config, accessToken);
|
|
73
64
|
(0, vitest_1.expect)(user.userUuid).toBeDefined();
|
|
74
65
|
(0, vitest_1.expect)(user.email).toBeDefined();
|
|
@@ -21,6 +21,7 @@ const PROJECT_UUID_HINT = '(pass on every tool, or use HTTP pin — else PROJECT
|
|
|
21
21
|
const TOPIC_DASHBOARDS = 'dashboards';
|
|
22
22
|
const TOPIC_DASHBOARD_DESIGN = 'dashboard-design';
|
|
23
23
|
const TOPIC_CHART_TYPES = 'chart-types';
|
|
24
|
+
const TOPIC_TABLE_CALCULATIONS = 'table-calculations';
|
|
24
25
|
const DASHBOARD_CHART_TOPIC_IDS = [
|
|
25
26
|
TOPIC_DASHBOARDS,
|
|
26
27
|
TOPIC_DASHBOARD_DESIGN,
|
|
@@ -114,9 +115,9 @@ Dashboard slug: ${dashboardSlug !== null && dashboardSlug !== void 0 ? dashboard
|
|
|
114
115
|
|
|
115
116
|
${playbooks_js_1.CONTENT_DEVELOPER_HARD_BANS}
|
|
116
117
|
|
|
117
|
-
Follow core + chart-types (clone via get_chart_as_code; preview with top-level slug; keep customDimensions when needed; tile if dashboardSlug set).
|
|
118
|
+
Follow core + chart-types + table-calculations (clone via get_chart_as_code; preview with top-level slug; keep customDimensions when needed; tile if dashboardSlug set).
|
|
118
119
|
When dashboardSlug is set, the chart must serve a **board insight** from the approved Design Spec — do not invent a viz type for its own sake.
|
|
119
|
-
Report UUID/slug from charts[0].data; note this profile cannot run_chart / prove UI render.`, TOPIC_CHART_TYPES));
|
|
120
|
+
Report UUID/slug from charts[0].data; note this profile cannot run_chart / prove UI render.`, [TOPIC_CHART_TYPES, TOPIC_TABLE_CALCULATIONS]));
|
|
120
121
|
server.registerPrompt('move_content', {
|
|
121
122
|
title: 'Move content',
|
|
122
123
|
description: 'Move charts/dashboards into an existing space (no space create/update)',
|
|
@@ -56,6 +56,7 @@ const playbooks_js_1 = require("./resources/playbooks.js");
|
|
|
56
56
|
(0, vitest_1.expect)(md).toContain('encode');
|
|
57
57
|
(0, vitest_1.expect)(md).toMatch(/xref/);
|
|
58
58
|
(0, vitest_1.expect)(md).toContain('chart-types');
|
|
59
|
+
(0, vitest_1.expect)(md).toContain('table-calculations');
|
|
59
60
|
(0, vitest_1.expect)(md).not.toMatch(/`create_space`/);
|
|
60
61
|
(0, vitest_1.expect)(md).not.toMatch(/`update_space`/);
|
|
61
62
|
const toolIds = (0, index_js_1.listToolIds)((0, index_js_1.getProfile)('content-developer'));
|
|
@@ -189,6 +190,7 @@ const playbooks_js_1 = require("./resources/playbooks.js");
|
|
|
189
190
|
const promptArgs = [];
|
|
190
191
|
let publishText = '';
|
|
191
192
|
let authorText = '';
|
|
193
|
+
let authorUris = [];
|
|
192
194
|
let refactorText = '';
|
|
193
195
|
const server = {
|
|
194
196
|
registerPrompt: (name, _meta, handler) => {
|
|
@@ -223,6 +225,9 @@ const playbooks_js_1 = require("./resources/playbooks.js");
|
|
|
223
225
|
.map((m) => { var _a; return (_a = m.content.text) !== null && _a !== void 0 ? _a : ''; })
|
|
224
226
|
.join('\n')
|
|
225
227
|
.toLowerCase();
|
|
228
|
+
authorUris = messages
|
|
229
|
+
.filter((m) => m.content.type === 'resource')
|
|
230
|
+
.map((m) => { var _a; return (_a = m.content.resource) === null || _a === void 0 ? void 0 : _a.uri; });
|
|
226
231
|
}
|
|
227
232
|
if (name === 'refactor_dashboard') {
|
|
228
233
|
const messages = handler({
|
|
@@ -279,6 +284,9 @@ const playbooks_js_1 = require("./resources/playbooks.js");
|
|
|
279
284
|
(0, vitest_1.expect)(publishText).toMatch(/untiled|leftover/);
|
|
280
285
|
(0, vitest_1.expect)(publishText).toContain('content-governance');
|
|
281
286
|
(0, vitest_1.expect)(authorText).toContain('board insight');
|
|
287
|
+
(0, vitest_1.expect)(authorText).toContain('table-calculations');
|
|
288
|
+
(0, vitest_1.expect)(authorUris).toContain('lightdash://playbooks/content-developer/chart-types');
|
|
289
|
+
(0, vitest_1.expect)(authorUris).toContain('lightdash://playbooks/content-developer/table-calculations');
|
|
282
290
|
(0, vitest_1.expect)(refactorText).toMatch(/approved spec|user request allows/);
|
|
283
291
|
(0, vitest_1.expect)(refactorText).not.toMatch(/unless explicitly requested/);
|
|
284
292
|
});
|
|
@@ -4,6 +4,8 @@ URI: `lightdash://playbooks/content-developer/chart-types`
|
|
|
4
4
|
|
|
5
5
|
Pick a viz type to **answer an insight question** from the Design Spec Objective. The table below is a **reference map**, not a build order — do not walk every row unless the user explicitly asked for multi-viz / all chart types. Prefer **clone** (`get_chart_as_code` / `duplicate_chart`) over inventing viz configs. Docs: [overview](https://docs.lightdash.com/references/chart-types/overview).
|
|
6
6
|
|
|
7
|
+
When the insight needs period-over-period, % of total, rank, or running/rolling windows: prefer cloned native PoP metrics (`generationType: periodOverPeriod`) from the seed; otherwise append `metricQuery.tableCalculations` per `lightdash://playbooks/content-developer/table-calculations` (do not freestyle warehouse `OVER()` SQL). See [period-over-period](https://docs.lightdash.com/guides/period-over-period).
|
|
8
|
+
|
|
7
9
|
When the user **does** ask for all types: follow dashboards **Multi-viz batch SOP** (shell → ≤2 concurrent chart creates → one tile update), split the board into a decision-oriented section plus a visualization-validation appendix (see `dashboards` / `dashboard-design`), and check every candidate type against the **semantic fit gate** below before adding it.
|
|
8
10
|
|
|
9
11
|
## Semantic fit gate
|
|
@@ -131,6 +133,7 @@ chartConfig:
|
|
|
131
133
|
- Clone `chartConfig` from a rendering seed on the same `tableName`; change series `type` / top-level type only when needed.
|
|
132
134
|
- FieldIds only from seed / `get_chart` / semantic-layer — never invent. this profile has **no** explore/field list tools.
|
|
133
135
|
- Field IDs shown in the YAML examples below (e.g. `orders_status`) are **illustrative**, not guaranteed to exist on any given explore — verify against a seed via `get_chart_as_code` (or `get_chart`) before use.
|
|
136
|
+
- **Custom fields & tooltips (clone-only):** preserve `metricQuery.customDimensions` and cartesian `eChartsConfig.tooltip` from the seed ([custom fields](https://docs.lightdash.com/guides/custom-fields), [custom tooltips](https://docs.lightdash.com/guides/custom-tooltip)). Do not invent new custom SQL dimensions or freestyle tooltip field names. Metrics reused across boards belong in dbt / semantic-layer, not chart-local custom metrics.
|
|
134
137
|
- When cloning charts that use SQL/bin custom dims (e.g. coupon flags), copy `metricQuery.customDimensions` verbatim.
|
|
135
138
|
- Every `metricQuery.dimensions` entry must appear in viz layout / group / sankey source-target / pivot — unused dimensions corrupt GROUP BY (“Results may be incorrect”). **Exception:** a scatter with two metric axes legitimately keeps its grain dimension (e.g. customer id) in `metricQuery.dimensions` to produce one row per entity — `validate_chart` will still flag it as "unused" because the validator only recognizes x/y-axis or group-by references, not grain-only dimensions. That warning is expected on a correct two-metric scatter; do not drop the dimension to silence it.
|
|
136
139
|
- For dashboard work set `dashboardSlug` **and** tile via `update_dashboard` (ownership alone does not place tiles).
|
|
@@ -23,12 +23,13 @@ this profile does **not** execute queries, compile explores, create spaces, or p
|
|
|
23
23
|
- Do not treat chart create as done without a dashboard shell and tiles that reference those charts.
|
|
24
24
|
- Do not invent `fieldId`s. Copy from `get_chart_as_code` / `get_chart` (`includeQueryDefinition`) or semantic-layer.
|
|
25
25
|
- Do not invent skinny `chartConfig` (e.g. `{ series: [{ type: 'bar' }] }` only) — clone a working as-code body and keep series/layout/encode structure.
|
|
26
|
+
- Do not set chart `verified` or dashboard `preserveVerification` unless the user explicitly asks (requires verify permission; edits can drop the badge — [verified content](https://docs.lightdash.com/guides/verified-content)).
|
|
26
27
|
- Do not call a write tool without a validated, unexpired HMAC `previewToken` from the matching `preview_*` then `confirm_preview`.
|
|
27
28
|
- Do not mutate the proposed payload after `preview_*` (no edits to `description`, `name`, SQL, metrics, tiles, or other fields between preview and apply) — apply must reuse the **identical proposed** body or you get `PREVIEW_STALE` (content hash mismatch). Any intentional edit requires a new `preview_*`.
|
|
28
29
|
- Do not reuse a **draft** token after confirm (confirm returns a **new** validated token) or after payload/baseline drift (`PREVIEW_STALE`).
|
|
29
30
|
- Do not unlock with a different resource's preview — `resourceKind` / `resourceKey` must match the preview exactly.
|
|
30
31
|
- Do not treat `validate_chart` / `validate_dashboard` as unlock — saved-UUID health checks only (not UI-render proof).
|
|
31
|
-
- Do not reveal secrets, warehouse credentials, or
|
|
32
|
+
- Do not reveal secrets, warehouse credentials, or saved SQL **chart** bodies.
|
|
32
33
|
|
|
33
34
|
## Default budgets (override when the user expands scope)
|
|
34
35
|
|
|
@@ -46,21 +47,21 @@ Record when a budget stopped you. User-requested “one of every chart type” o
|
|
|
46
47
|
|
|
47
48
|
## Allowed tools (`lightdash_*`)
|
|
48
49
|
|
|
49
|
-
| Tool | Use for
|
|
50
|
-
| ------------------------------------------------------------------------------------------------ |
|
|
51
|
-
| `get_project` | Resolve project; read `developerCapabilities` (mutate yes; **execute charts/tiles = false**)
|
|
52
|
-
| `search_content` | Find charts/dashboards; prefer short tokens, not marketing phrases
|
|
53
|
-
| `list_spaces` / `get_space` | Existing spaces; pick `spaceUuid` / `spaceSlug`
|
|
54
|
-
| `get_dashboard` / `get_chart` | Metadata. `get_chart`
|
|
55
|
-
| `get_chart_as_code` | **Clone** upsert-shaped `chartConfig` + `metricQuery` before create/update
|
|
56
|
-
| `preview_chart_changes` / `preview_dashboard_changes` / `preview_content_move` | Mint draft `previewToken` + `resourceKey`
|
|
57
|
-
| `confirm_preview` | Unlock; returns **new** validated token — always pass **`projectUuid`** without HTTP pin
|
|
58
|
-
| `create_chart` / `update_chart` / `duplicate_chart` | Semantic as-code writes (after confirm); set `dashboardSlug`
|
|
59
|
-
| `create_dashboard` / `update_dashboard` / `duplicate_dashboard` | Dashboard shell then tile updates
|
|
60
|
-
| `add_dashboard_tile` / `move_dashboard_tile` / `remove_dashboard_tile` / `resize_dashboard_tile` | Tile ops; each needs preview of the **full next tiles array**
|
|
61
|
-
| `move_content` | Relocate into existing spaces
|
|
62
|
-
| `validate_chart` / `validate_dashboard` | Optional post-apply health (`chartUuid` / dashboard UUID)
|
|
63
|
-
| `compare_chart_versions` / `compare_dashboard_versions` | Drift / refactor
|
|
50
|
+
| Tool | Use for |
|
|
51
|
+
| ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `get_project` | Resolve project; read `developerCapabilities` (mutate yes; **execute charts/tiles = false**) |
|
|
53
|
+
| `search_content` | Find charts/dashboards; prefer short tokens, not marketing phrases |
|
|
54
|
+
| `list_spaces` / `get_space` | Existing spaces; pick `spaceUuid` / `spaceSlug` |
|
|
55
|
+
| `get_dashboard` / `get_chart` | Metadata (+ query fields when included). `get_chart` is inspect-only — no `chartConfig`; use `get_chart_as_code` to clone. Arg is **`chartUuidOrSlug`**. |
|
|
56
|
+
| `get_chart_as_code` | **Clone** upsert-shaped `chartConfig` + `metricQuery` before create/update |
|
|
57
|
+
| `preview_chart_changes` / `preview_dashboard_changes` / `preview_content_move` | Mint draft `previewToken` + `resourceKey` |
|
|
58
|
+
| `confirm_preview` | Unlock; returns **new** validated token — always pass **`projectUuid`** without HTTP pin |
|
|
59
|
+
| `create_chart` / `update_chart` / `duplicate_chart` | Semantic as-code writes (after confirm); set `dashboardSlug` |
|
|
60
|
+
| `create_dashboard` / `update_dashboard` / `duplicate_dashboard` | Dashboard shell then tile updates |
|
|
61
|
+
| `add_dashboard_tile` / `move_dashboard_tile` / `remove_dashboard_tile` / `resize_dashboard_tile` | Tile ops; each needs preview of the **full next tiles array** |
|
|
62
|
+
| `move_content` | Relocate into existing spaces |
|
|
63
|
+
| `validate_chart` / `validate_dashboard` | Optional post-apply health (`chartUuid` / dashboard UUID) |
|
|
64
|
+
| `compare_chart_versions` / `compare_dashboard_versions` | Drift / refactor |
|
|
64
65
|
|
|
65
66
|
## Phase 0 — Resolve project
|
|
66
67
|
|
|
@@ -107,3 +108,4 @@ Record when a budget stopped you. User-requested “one of every chart type” o
|
|
|
107
108
|
- Tile shape: `{ type: 'saved_chart', x, y, w, h, properties: { savedChartUuid, title? } }` — use the UUID from `create_chart` / `duplicate_chart` (36-column grid; half-width ≈ `w: 18`). Optional `chartSlug` is metadata only; do not omit `savedChartUuid`.
|
|
108
109
|
- `create_chart` response: extract UUID from `charts[0].data.uuid` (not a bare chart object).
|
|
109
110
|
- Viz shapes: `lightdash://playbooks/content-developer/chart-types`.
|
|
111
|
+
- PoP: prefer cloned `generationType: periodOverPeriod` metrics; else % of total / rank / windows via `lightdash://playbooks/content-developer/table-calculations`.
|
|
@@ -79,7 +79,7 @@ Skip fancy HTML/iframe unless the user asks. Loom / heading tiles: only if reque
|
|
|
79
79
|
|
|
80
80
|
## Filters (optional)
|
|
81
81
|
|
|
82
|
-
0–3 shared **dimensions**. Prefer **one explore** for all tiles that share dashboard filters. Filters guide: [Using filters](https://docs.lightdash.com/guides/limiting-data-using-filters). Official as-code targeting: [dashboard-reference `tileTargets`](https://github.com/lightdash/lightdash/blob/main/skills/developing-in-lightdash/resources/dashboard-reference.md).
|
|
82
|
+
0–3 shared **dimensions**. Prefer **one explore** for all tiles that share dashboard filters. Filters guide: [Using filters](https://docs.lightdash.com/guides/limiting-data-using-filters). Operator catalog (date windows, `is not` + NULL, etc.): [Filters reference](https://docs.lightdash.com/guides/filters). Official as-code targeting: [dashboard-reference `tileTargets`](https://github.com/lightdash/lightdash/blob/main/skills/developing-in-lightdash/resources/dashboard-reference.md).
|
|
83
83
|
|
|
84
84
|
- Prefer **empty-value** saved filters so viewers choose ([saved filters](https://docs.lightdash.com/guides/limiting-data-using-filters#adding-saved-filters-to-your-dashboard)).
|
|
85
85
|
- Prefer **clone** `filters` from `get_dashboard` on a working board over inventing rules.
|
|
@@ -138,6 +138,16 @@ filters:
|
|
|
138
138
|
|
|
139
139
|
**Apply order:** compose tiles first → if excluding, `get_dashboard` for tile UUIDs → then `preview_dashboard_changes` → `confirm_preview` → `update_dashboard({ dashboard: { filters, tiles?, name?, … } })` (second update is fine when UUIDs were not known on first tile write).
|
|
140
140
|
|
|
141
|
+
## Date zoom (optional)
|
|
142
|
+
|
|
143
|
+
When the Objective needs viewers to change time granularity without editing charts ([date zoom](https://docs.lightdash.com/guides/date-zoom)):
|
|
144
|
+
|
|
145
|
+
1. Plan in the Design Spec (Default zoom + any named controls; which tiles attach).
|
|
146
|
+
2. **Clone** dashboard `config` (`dateZoomConfig`, `defaultDateZoomGranularity`, `dateZoomGranularities`, `isDateZoomDisabled`) from a working board via `get_dashboard` — do not invent tile↔field bindings.
|
|
147
|
+
3. Attach only charts that have a zoomable date/timestamp dimension in results; a chart with no date field cannot join a control.
|
|
148
|
+
4. Optional labels: `${table_field.granularity}` in axis / big-value labels when cloning charts that already use it.
|
|
149
|
+
5. Viewer zoom is temporary in the UI; saved defaults live on the dashboard `config` you upsert.
|
|
150
|
+
|
|
141
151
|
## Tabs
|
|
142
152
|
|
|
143
153
|
Default: **no tabs**. Use only for themes / audiences / 30+ tiles ([docs tip](https://docs.lightdash.com/get-started/exploring-data/dashboards#add-tabs)).
|
|
@@ -19,7 +19,7 @@ get_project → list_spaces → discover seeds (read-only)
|
|
|
19
19
|
1. `list_spaces` → existing `spaceUuid` (dashboards) / `spaceSlug` (chart as-code).
|
|
20
20
|
2. `search_content` with **short** tokens (`orders`, space slug). Multi-word brand phrases often return empty — use `get_space`. Short tokens can also return noisy org-wide hits — prefer `get_space` inventory for seeds.
|
|
21
21
|
3. Prefer **reuse** of existing charts as tiles when they already fit.
|
|
22
|
-
4. For new charts: find a **working seed** on the same `tableName`; never invent fieldIds.
|
|
22
|
+
4. For new charts: find a **working seed** on the same `tableName`; never invent fieldIds. For PoP, prefer seeds with `generationType: periodOverPeriod` metrics (see table-calculations).
|
|
23
23
|
5. Dashboard-owned charts (`dashboardSlug` set) **do not** appear as independent space charts in `get_space` / typical search — keep the UUIDs you create, or re-open the dashboard.
|
|
24
24
|
|
|
25
25
|
## Create dashboard shell (step 1 — after Design Spec approval)
|
|
@@ -41,7 +41,7 @@ Semantic as-code only. Prefer clone, not invent.
|
|
|
41
41
|
1. Prefer **reuse** of an existing chart as a tile when it already fits.
|
|
42
42
|
2. Else `search_content` / `get_space` → pick a **rendering** seed on the same `tableName` (same explore).
|
|
43
43
|
3. `get_chart_as_code` (or `duplicate_chart`) → **keep `chartConfig` structure** (layout + series encode); edit only `name`, `slug`, and `metricQuery` fields that exist on the explore; set `dashboardSlug` = dashboard slug from step 1.
|
|
44
|
-
4. Viz type / encode details: `lightdash://playbooks/content-developer/chart-types`.
|
|
44
|
+
4. Viz type / encode details: `lightdash://playbooks/content-developer/chart-types`. PoP / % of total / rank / windows on `metricQuery.tableCalculations`: `lightdash://playbooks/content-developer/table-calculations`.
|
|
45
45
|
|
|
46
46
|
Then:
|
|
47
47
|
|
|
@@ -4,12 +4,13 @@ URI: `lightdash://playbooks/content-developer`
|
|
|
4
4
|
|
|
5
5
|
Workflow-scoped playbooks (always load **core** plus one topic with a prompt):
|
|
6
6
|
|
|
7
|
-
| Topic | URI
|
|
8
|
-
| ------------------------------------------------------------ |
|
|
9
|
-
| Core (gates & bans) | `lightdash://playbooks/content-developer/core`
|
|
10
|
-
| Dashboards & dashboard-owned charts | `lightdash://playbooks/content-developer/dashboards`
|
|
11
|
-
| Dashboard design (Design Spec + layout / markdown / filters) | `lightdash://playbooks/content-developer/dashboard-design`
|
|
12
|
-
| Chart types (cartesian + pie/funnel/…) | `lightdash://playbooks/content-developer/chart-types`
|
|
13
|
-
|
|
|
7
|
+
| Topic | URI |
|
|
8
|
+
| ------------------------------------------------------------ | ------------------------------------------------------------ |
|
|
9
|
+
| Core (gates & bans) | `lightdash://playbooks/content-developer/core` |
|
|
10
|
+
| Dashboards & dashboard-owned charts | `lightdash://playbooks/content-developer/dashboards` |
|
|
11
|
+
| Dashboard design (Design Spec + layout / markdown / filters) | `lightdash://playbooks/content-developer/dashboard-design` |
|
|
12
|
+
| Chart types (cartesian + pie/funnel/…) | `lightdash://playbooks/content-developer/chart-types` |
|
|
13
|
+
| Table calculations (template / formula / sql) | `lightdash://playbooks/content-developer/table-calculations` |
|
|
14
|
+
| Content move | `lightdash://playbooks/content-developer/content-move` |
|
|
14
15
|
|
|
15
16
|
**Authoring order:** clarify Objective → Design Spec → approve → dashboard shell → charts with `dashboardSlug` → tiles (+ optional filters; prefer one explore or `tileTargets` exclude by tile UUID). Always pass **`projectUuid`** on `confirm_preview` and apply when there is no HTTP pin. Clone via `get_chart_as_code`; never invent fieldIds or skinny `chartConfig` (cartesian series need `encode.xRef`/`yRef`). Multi-viz / all chart types only when the user explicitly asks (batch: shell → charts ≤2 parallel → one tile update). Cap concurrent writes at ≤2 on hosted tunnels. Spaces are Terraform / out-of-band (`list_spaces` / `get_space` only).
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Content-developer — table calculations
|
|
2
|
+
|
|
3
|
+
URI: `lightdash://playbooks/content-developer/table-calculations`
|
|
4
|
+
|
|
5
|
+
Add chart-local metrics on top of explore dimensions/metrics via `metricQuery.tableCalculations`. Prefer clone (`get_chart_as_code`) then append calcs. This profile **cannot** run queries to verify row values.
|
|
6
|
+
|
|
7
|
+
Docs: [overview](https://docs.lightdash.com/guides/table-calculations) · [formula](https://docs.lightdash.com/guides/formula-table-calculations) · [SQL templates](https://docs.lightdash.com/guides/table-calculations/sql-templates) · [as-code](https://docs.lightdash.com/guides/developer/dashboards-as-code) · [period-over-period](https://docs.lightdash.com/guides/period-over-period) · [row](https://docs.lightdash.com/references/table-calculation-functions/row-functions) / [pivot](https://docs.lightdash.com/references/table-calculation-functions/pivot-functions) / [aggregate](https://docs.lightdash.com/references/table-calculation-functions/aggregate-functions) functions.
|
|
8
|
+
|
|
9
|
+
## Native PoP metrics (prefer before table calcs)
|
|
10
|
+
|
|
11
|
+
Period-over-period may already exist on a seed as **system-generated metrics** ([period-over-period guide](https://docs.lightdash.com/guides/period-over-period); OpenAPI `generationType: periodOverPeriod`).
|
|
12
|
+
|
|
13
|
+
1. `get_chart_as_code` on a rendering seed.
|
|
14
|
+
2. If any metric has `generationType: periodOverPeriod` (plus `baseMetricId` / `timeDimensionId` / `periodOffset` / `granularity` as present), **preserve those metrics verbatim** — do not rebuild them as table calculations.
|
|
15
|
+
3. Else use table calculations below for % change, lag, running totals, etc.
|
|
16
|
+
4. KPI `big_number` with `showComparison` / compare-to-previous-row: keep from seed when present.
|
|
17
|
+
|
|
18
|
+
**Hard ban:** do not invent PoP metrics by hand. This profile cannot use the Explorer “Add period comparison” UI — only clone as-code bodies.
|
|
19
|
+
|
|
20
|
+
## When to use table calculations
|
|
21
|
+
|
|
22
|
+
- Chart-specific PoP (when no native PoP metrics on the seed), % of total, rank, running total, rolling window, pivot share.
|
|
23
|
+
- If the same calc is reused across many boards → put it in **dbt** / the semantic layer instead ([overview](https://docs.lightdash.com/guides/table-calculations)).
|
|
24
|
+
|
|
25
|
+
## Preference (playbook policy)
|
|
26
|
+
|
|
27
|
+
1. **`template`** — quick types + `window_function` (OpenAPI `TemplateTableCalculation`).
|
|
28
|
+
2. **`formula`** — portable spreadsheet syntax starting with `=` ([formula docs](https://docs.lightdash.com/guides/formula-table-calculations)); column names match results headers.
|
|
29
|
+
3. **`sql`** — only for `total()` / `row_total()` / real `pivot_*` helpers (`pivot_offset`, `pivot_index`, `pivot_row`, …), or when formula cannot express it. Never invent names like `pivot_row_total`.
|
|
30
|
+
|
|
31
|
+
Formula and SQL modes are **not** interconvertible — delete and recreate to switch ([formula FAQ](https://docs.lightdash.com/guides/formula-table-calculations)).
|
|
32
|
+
|
|
33
|
+
## Intent → shape
|
|
34
|
+
|
|
35
|
+
| Intent | Prefer | OpenAPI / expression |
|
|
36
|
+
| ---------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
37
|
+
| % change from previous | `template` | `type: percent_change_from_previous` + `fieldId` + `orderBy` |
|
|
38
|
+
| % of previous value | `template` | `type: percent_of_previous_value` + `fieldId` + `orderBy` |
|
|
39
|
+
| % of column total | `template` | `type: percent_of_column_total` + `fieldId` |
|
|
40
|
+
| Rank in column | `template` | `type: rank_in_column` + `fieldId` |
|
|
41
|
+
| Running total | `template` | `type: running_total` + `fieldId` |
|
|
42
|
+
| Rolling / moving window | `template` or `formula` | `window_function` + `frame`, or `MOVING_AVG` / `MOVING_SUM` |
|
|
43
|
+
| Simple ratio / IF / date math | `formula` | e.g. `=orders_sum_order_amount / orders_num_unique_order_ids` |
|
|
44
|
+
| Grand % of total (correct metric re-agg) | `sql` | `${metric} / total(${metric})` ([aggregate](https://docs.lightdash.com/references/table-calculation-functions/aggregate-functions)) |
|
|
45
|
+
| Pivot row share | `sql` | `${metric} / row_total(${metric})` ([aggregate](https://docs.lightdash.com/references/table-calculation-functions/aggregate-functions)) — **not** `pivot_row_total` (does not exist) |
|
|
46
|
+
| Cross-column pivot access | `sql` | `pivot_offset` / `pivot_index` / `pivot_row` / … **only when pivoted** ([pivot](https://docs.lightdash.com/references/table-calculation-functions/pivot-functions)) |
|
|
47
|
+
|
|
48
|
+
SQL template guides: [percent change](https://docs.lightdash.com/guides/table-calculations/table-calculation-sql-templates/percent-change-from-previous), [percent of previous](https://docs.lightdash.com/guides/table-calculations/table-calculation-sql-templates/percent-of-previous-value), [percent of column](https://docs.lightdash.com/guides/table-calculations/table-calculation-sql-templates/percent-of-total-column), [percent of group/pivot](https://docs.lightdash.com/guides/table-calculations/table-calculation-sql-templates/percent-of-group-pivot-total), [rank](https://docs.lightdash.com/guides/table-calculations/table-calculation-sql-templates/rank-in-column), [running total](https://docs.lightdash.com/guides/table-calculations/table-calculation-sql-templates/running-total), [rolling window](https://docs.lightdash.com/guides/table-calculations/table-calculation-sql-templates/rolling-window).
|
|
49
|
+
|
|
50
|
+
## Format and totals
|
|
51
|
+
|
|
52
|
+
- Percent-style calcs: set `format: { type: 'percent' }` (and `type: 'number'` when needed).
|
|
53
|
+
- `totalMode`: `formula` for ratios evaluated at total grain; `sum_of_rows` for windows / template windows; `none` when a total is meaningless ([totals](https://docs.lightdash.com/guides/table-calculations)).
|
|
54
|
+
|
|
55
|
+
## JSON skeletons
|
|
56
|
+
|
|
57
|
+
Field IDs are **illustrative** — copy real `fieldId`s from the explore / seed.
|
|
58
|
+
|
|
59
|
+
### Template (percent change)
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"name": "amount_pct_change",
|
|
64
|
+
"displayName": "% change vs previous",
|
|
65
|
+
"type": "number",
|
|
66
|
+
"format": { "type": "percent" },
|
|
67
|
+
"totalMode": "sum_of_rows",
|
|
68
|
+
"template": {
|
|
69
|
+
"type": "percent_change_from_previous",
|
|
70
|
+
"fieldId": "orders_sum_order_amount",
|
|
71
|
+
"orderBy": [{ "fieldId": "orders_order_date_month", "order": "asc" }]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Formula (ratio)
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"name": "avg_order_value",
|
|
81
|
+
"displayName": "Average order value",
|
|
82
|
+
"type": "number",
|
|
83
|
+
"totalMode": "formula",
|
|
84
|
+
"formula": "=orders_sum_order_amount / orders_num_unique_order_ids"
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### SQL (percent of grand total)
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"name": "amount_pct_of_total",
|
|
93
|
+
"displayName": "% of total",
|
|
94
|
+
"type": "number",
|
|
95
|
+
"format": { "type": "percent" },
|
|
96
|
+
"totalMode": "formula",
|
|
97
|
+
"sql": "${orders.sum_order_amount} / total(${orders.sum_order_amount})"
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### SQL (percent of pivot row — requires `pivotConfig`)
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"name": "amount_pct_of_pivot_row",
|
|
106
|
+
"displayName": "% of pivot row total",
|
|
107
|
+
"type": "number",
|
|
108
|
+
"format": { "type": "percent" },
|
|
109
|
+
"totalMode": "formula",
|
|
110
|
+
"sql": "${orders.sum_order_amount} / row_total(${orders.sum_order_amount})"
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Authoring SOP
|
|
115
|
+
|
|
116
|
+
1. Clone via `get_chart_as_code` (or `duplicate_chart`) — that returns upsert-shaped `chartConfig` + `metricQuery`. Append to `metricQuery.tableCalculations` (never omit the array — OpenAPI requires it). Use `get_chart` only to inspect existing calc expressions; it does **not** return `chartConfig`.
|
|
117
|
+
2. Align `metricQuery.sorts` with window `orderBy` / formula `ORDER BY`.
|
|
118
|
+
3. If the calc is plotted, reference its `name` in viz encode / series like any metric fieldId.
|
|
119
|
+
4. `preview_chart_changes` → `confirm_preview` → `create_chart` / `update_chart` with the **identical** proposed body.
|
|
120
|
+
5. Do not claim verified numbers — this profile has no `run_chart` / warehouse execute.
|
|
121
|
+
|
|
122
|
+
## Hard bans
|
|
123
|
+
|
|
124
|
+
- Do not invent `fieldId`s or results-header column names. Copy them from `get_chart_as_code` / explore seeds — playbook skeletons are examples only.
|
|
125
|
+
- `preview_chart_changes` / `confirm_preview` do **not** prove template `fieldId`s or formula headers exist; inventing IDs can still preview-validate and only fail at query time.
|
|
126
|
+
- Do not invent SQL helpers — use `total()` / `row_total()` ([aggregate](https://docs.lightdash.com/references/table-calculation-functions/aggregate-functions)) or documented `pivot_*` ([pivot](https://docs.lightdash.com/references/table-calculation-functions/pivot-functions)). There is no `pivot_row_total`.
|
|
127
|
+
- Do not invent native PoP metrics (`generationType: periodOverPeriod`) — clone from a seed or use table calcs instead.
|
|
128
|
+
- Do not convert formula ↔ sql in place — recreate the calc.
|
|
129
|
+
- Do not use `pivot_*` / `row_total` without a pivoted dimension (`pivotConfig.columns`).
|
|
130
|
+
- Do not author SQL **charts** or open data-analyst / raw SQL execution to “fix” a table calc on this profile.
|
|
131
|
+
- Do not freestyle warehouse-specific `OVER()` SQL when a `template` or `formula` covers the intent.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Content-developer multi-playbook resources (core + topics + index).
|
|
3
3
|
*/
|
|
4
4
|
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
-
export type ContentDeveloperPlaybookTopic = 'chart-types' | 'content-move' | 'dashboard-design' | 'dashboards';
|
|
5
|
+
export type ContentDeveloperPlaybookTopic = 'chart-types' | 'content-move' | 'dashboard-design' | 'dashboards' | 'table-calculations';
|
|
6
6
|
export declare const CONTENT_DEVELOPER_HARD_BANS: string;
|
|
7
7
|
export declare const getAllPlaybookMarkdown: () => string;
|
|
8
8
|
export declare const CONTENT_DEVELOPER_CORE_PLAYBOOK: import("../../../lib/playbook-resources.js").EmbeddedPlaybook;
|
|
@@ -22,12 +22,13 @@ Do not attach dashboard filters whose target.tableName is absent from a tile exp
|
|
|
22
22
|
Do not treat chart create as done without a dashboard shell and tiles.
|
|
23
23
|
Do not invent fieldIds — clone via get_chart_as_code / get_chart or use semantic-layer.
|
|
24
24
|
Do not invent skinny chartConfig — clone a working as-code body and keep series/layout/encode.
|
|
25
|
+
Do not set chart verified or dashboard preserveVerification unless the user explicitly asks (verify permission required).
|
|
25
26
|
Do not apply a write tool without a confirmed, unexpired HMAC previewToken from the matching preview_* tool (confirm_preview unlocks every write; use the new validated token).
|
|
26
27
|
Do not mutate the proposed payload after preview_* (description/name/SQL/metrics/tiles) — apply must reuse the identical proposed body or PREVIEW_STALE (content hash mismatch); any edit requires a new preview_*.
|
|
27
28
|
Do not treat validate_chart / validate_dashboard as a preview unlock — they are saved-UUID health checks only (validate_chart needs chartUuid).
|
|
28
29
|
Do not reuse a draft previewToken after confirm; re-run preview if the resource drifts (PREVIEW_STALE).
|
|
29
30
|
Do not use subagent-driven-development or multi-task writing-plans solely to click MCP preview/confirm/apply for lab boards (e.g. experiments) — after Design Spec approval, run Batch SOP inline in the same session.
|
|
30
|
-
Do not reveal secrets, warehouse credentials, or
|
|
31
|
+
Do not reveal secrets, warehouse credentials, or saved SQL chart bodies.`,
|
|
31
32
|
coreDescription: 'Hard bans, tools, project scope, preview gate, and apply pitfalls',
|
|
32
33
|
topics: [
|
|
33
34
|
{
|
|
@@ -48,6 +49,12 @@ Do not reveal secrets, warehouse credentials, or hidden SQL.`,
|
|
|
48
49
|
description: 'Insight-first viz pick; cartesian encode checklist; UI intent → as-code map',
|
|
49
50
|
file: 'chart-types.md',
|
|
50
51
|
},
|
|
52
|
+
{
|
|
53
|
+
id: 'table-calculations',
|
|
54
|
+
title: 'Content-developer table-calculations playbook',
|
|
55
|
+
description: 'metricQuery.tableCalculations: template → formula → sql; PoP, % of total, rank, windows',
|
|
56
|
+
file: 'table-calculations.md',
|
|
57
|
+
},
|
|
51
58
|
{
|
|
52
59
|
id: 'content-move',
|
|
53
60
|
title: 'Content-developer content-move playbook',
|
|
@@ -22,6 +22,7 @@ exports.contentReaderProfile = {
|
|
|
22
22
|
tools: [
|
|
23
23
|
projects_js_1.getProjectReaderTool,
|
|
24
24
|
reader_content_js_1.searchContentTool,
|
|
25
|
+
reader_content_js_1.listVerifiedContentTool,
|
|
25
26
|
spaces_js_1.listSpacesTool,
|
|
26
27
|
spaces_js_1.getSpaceTool,
|
|
27
28
|
reader_content_js_1.getDashboardTool,
|
|
@@ -35,15 +35,16 @@ ${playbooks_js_1.CONTENT_READER_HARD_BANS}
|
|
|
35
35
|
|
|
36
36
|
Project: ${projectUuid !== null && projectUuid !== void 0 ? projectUuid : '(use HTTP pin or ask for projectUuid — PROJECT_SCOPE_REQUIRED otherwise)'}.
|
|
37
37
|
Content types hint: ${contentTypes !== null && contentTypes !== void 0 ? contentTypes : '(any)'}.
|
|
38
|
-
Verified
|
|
38
|
+
Verified preference: ${verifiedOnly !== null && verifiedOnly !== void 0 ? verifiedOnly : false} (when true, call list_verified_content first — search_content does not filter by verification).
|
|
39
39
|
Space filter: ${spaceUuid !== null && spaceUuid !== void 0 ? spaceUuid : '(none)'}.
|
|
40
40
|
|
|
41
41
|
Procedure:
|
|
42
42
|
1. get_project with projectUuid/pin; record readerCapabilities.
|
|
43
|
-
2.
|
|
44
|
-
3.
|
|
45
|
-
4.
|
|
46
|
-
5.
|
|
43
|
+
2. When verifiedOnly is true (or the user asked for trusted/canonical content): call list_verified_content first and prefer those matches.
|
|
44
|
+
3. Else (or when the verified list is empty): search_content with short tokens (retry Japanese/single keyword / sortBy=views if empty). Use spaceUuids when given. pageSize≤25; ≤2 pages.
|
|
45
|
+
4. Prefer semantic charts (source≠sql). Rank: verified first → pinned + views + description.
|
|
46
|
+
5. Optionally list_spaces / get_space (≤3) to confirm path.
|
|
47
|
+
6. Return ≤5 candidates (name/type/uuid/space/views/verified/source/why). Do not execute unless values were requested.`, 'discover'));
|
|
47
48
|
server.registerPrompt('explain_chart', {
|
|
48
49
|
title: 'Explain chart',
|
|
49
50
|
description: 'Explain a saved chart from metadata (optional bounded execution)',
|
|
@@ -87,8 +88,8 @@ Execute tiles: ${executeTiles !== null && executeTiles !== void 0 ? executeTiles
|
|
|
87
88
|
Procedure:
|
|
88
89
|
1. get_dashboard with includeTiles (+ filters as needed). Use tileUuid (not uuid); skip non-executable/markdown tiles.
|
|
89
90
|
2. Describe purpose, filters, parameters, verification, and tile structure — summarize, do not dump all tiles.
|
|
90
|
-
3. When execution is requested, run_dashboard_tile for ≤max relevant executable tiles; preserve dashboard context; value-only overrides.
|
|
91
|
-
4. Report values/trends/failures with content + query UUIDs. Unexecuted tiles must not support conclusions.`, TOPIC_EXPLAIN_RUN));
|
|
91
|
+
3. When execution is requested, run_dashboard_tile for ≤max relevant executable tiles; preserve dashboard context; value-only overrides. Execution uses saved date-zoom defaults unless the user asks to simulate zoom via dateZoom.
|
|
92
|
+
4. Report values/trends/failures with content + query UUIDs (cite appliedDateZoom when set). Unexecuted tiles must not support conclusions.`, TOPIC_EXPLAIN_RUN));
|
|
92
93
|
server.registerPrompt('answer_from_content', {
|
|
93
94
|
title: 'Answer from content',
|
|
94
95
|
description: 'Answer a question using existing saved Lightdash content only',
|
|
@@ -105,11 +106,11 @@ ${question}
|
|
|
105
106
|
${playbooks_js_1.CONTENT_READER_HARD_BANS}
|
|
106
107
|
|
|
107
108
|
Project: ${projectUuid !== null && projectUuid !== void 0 ? projectUuid : PROJECT_UUID_HINT}.
|
|
108
|
-
Prefer verified=${verifiedOnly !== null && verifiedOnly !== void 0 ? verifiedOnly : false} when
|
|
109
|
+
Prefer verified=${verifiedOnly !== null && verifiedOnly !== void 0 ? verifiedOnly : false} when set — call list_verified_content first; else search_content (pinned + views + description). search_content does not filter by verification.
|
|
109
110
|
Max executions: ${maximumExecutions !== null && maximumExecutions !== void 0 ? maximumExecutions : 3}.
|
|
110
111
|
|
|
111
112
|
Procedure:
|
|
112
|
-
1. get_project → search_content (short tokens; retry if empty) → pick best semantic content.
|
|
113
|
+
1. get_project → when verified preferred, list_verified_content first; else search_content (short tokens; retry if empty) → pick best semantic content.
|
|
113
114
|
2. Inspect metadata; execute the smallest number of saved charts/tiles required (≤ max), cache-first.
|
|
114
115
|
3. Skip SQL / non-executable sources. Value-only parameter/filter overrides.
|
|
115
116
|
4. State answer, content used, filter/parameter context, result time/cache, truncation, and limitations.`, TOPIC_EXPLAIN_RUN));
|
|
@@ -11,7 +11,7 @@ Compare **definitions before values**. Matching titles/labels ≠ same metric, g
|
|
|
11
11
|
3. Diff checklist:
|
|
12
12
|
- Explore / `tableName`
|
|
13
13
|
- Metrics & dimensions (`fieldId`s)
|
|
14
|
-
- Filters (targets, operators, windows — e.g. `inThePast` days)
|
|
14
|
+
- Filters (targets, operators, windows — e.g. `inThePast` days; `in the last` vs completed periods vs `in the current` — [filters reference](https://docs.lightdash.com/guides/filters))
|
|
15
15
|
- Time grain / timezone fields
|
|
16
16
|
- Parameters, sorts, limits, pivots, table calculations
|
|
17
17
|
- Chart `source` / `chartType` (semantic vs SQL)
|