@lightdash-tools/mcp 0.5.0 → 0.7.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 +133 -58
- package/dist/audit/audit.d.ts +5 -0
- package/dist/{audit.js → audit/audit.js} +1 -2
- package/dist/audit/tool-audit-context.d.ts +6 -0
- package/dist/audit/tool-audit-context.js +12 -0
- package/dist/audit/tool-audit-context.test.d.ts +1 -0
- package/dist/audit/tool-audit-context.test.js +19 -0
- package/dist/auth/auth-mode.d.ts +4 -0
- package/dist/auth/auth-mode.js +6 -0
- package/dist/auth/bearer.d.ts +3 -0
- package/dist/auth/bearer.js +13 -0
- package/dist/auth/lightdash-oauth-upstream-contract.d.ts +22 -0
- package/dist/auth/lightdash-oauth-upstream-contract.js +36 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.d.ts +1 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.js +56 -0
- package/dist/auth/oauth-broker/as-metadata.d.ts +14 -0
- package/dist/auth/oauth-broker/as-metadata.js +20 -0
- package/dist/auth/oauth-broker/lightdash-token.d.ts +20 -0
- package/dist/auth/oauth-broker/lightdash-token.js +76 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +76 -0
- package/dist/auth/oauth-broker/pending-store.js +124 -0
- package/dist/auth/oauth-broker/pkce.d.ts +2 -0
- package/dist/auth/oauth-broker/pkce.js +17 -0
- package/dist/auth/oauth-broker/routes.d.ts +9 -0
- package/dist/auth/oauth-broker/routes.js +447 -0
- package/dist/auth/oauth-broker/routes.test.d.ts +1 -0
- package/dist/auth/oauth-broker/routes.test.js +237 -0
- package/dist/auth/providers/bearer-context-provider.d.ts +24 -0
- package/dist/auth/providers/bearer-context-provider.js +52 -0
- package/dist/auth/providers/env-context-provider.d.ts +13 -0
- package/dist/auth/providers/env-context-provider.js +19 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +23 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +115 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +202 -0
- package/dist/auth/resource-server/lightdash-token-validation.d.ts +14 -0
- package/dist/auth/resource-server/lightdash-token-validation.js +82 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.js +177 -0
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +25 -0
- package/dist/auth/resource-server/oauth-protected-resource.js +67 -0
- package/dist/auth/resource-server/shared-key-middleware.d.ts +13 -0
- package/dist/auth/resource-server/shared-key-middleware.js +24 -0
- package/dist/auth/resource-server/token-scopes.d.ts +15 -0
- package/dist/auth/resource-server/token-scopes.js +76 -0
- package/dist/auth/resource-server/token-scopes.test.d.ts +1 -0
- package/dist/auth/resource-server/token-scopes.test.js +51 -0
- package/dist/auth/resource-server/token-validation-cache.d.ts +15 -0
- package/dist/auth/resource-server/token-validation-cache.js +44 -0
- package/dist/auth/resource-server/token-validation-cache.test.d.ts +1 -0
- package/dist/auth/resource-server/token-validation-cache.test.js +41 -0
- package/dist/auth/resource-server/token-validation-error.d.ts +6 -0
- package/dist/auth/resource-server/token-validation-error.js +13 -0
- package/dist/auth/resource-server/www-authenticate.d.ts +8 -0
- package/dist/auth/resource-server/www-authenticate.js +24 -0
- package/dist/auth/resource-server/www-authenticate.test.d.ts +1 -0
- package/dist/auth/resource-server/www-authenticate.test.js +64 -0
- package/dist/auth/token-hash.d.ts +2 -0
- package/dist/auth/token-hash.js +8 -0
- package/dist/bin.d.ts +0 -4
- package/dist/bin.js +41 -33
- package/dist/config/env.d.ts +50 -0
- package/dist/config/env.js +53 -0
- package/dist/config/load-mcp-config.d.ts +30 -0
- package/dist/config/load-mcp-config.js +282 -0
- package/dist/config/load-mcp-config.test.d.ts +1 -0
- package/dist/config/load-mcp-config.test.js +195 -0
- package/dist/config/normalize-url.d.ts +13 -0
- package/dist/config/normalize-url.js +52 -0
- package/dist/config/normalize-url.test.d.ts +1 -0
- package/dist/config/normalize-url.test.js +41 -0
- package/dist/config/public-url.d.ts +3 -0
- package/dist/config/public-url.js +10 -0
- package/dist/config/runtime.d.ts +15 -0
- package/dist/config/runtime.js +48 -0
- package/dist/config/runtime.test.d.ts +1 -0
- package/dist/config/runtime.test.js +69 -0
- package/dist/config/test-mcp-http-config.d.ts +3 -0
- package/dist/config/test-mcp-http-config.js +7 -0
- package/dist/governance/project-pin.d.ts +14 -0
- package/dist/governance/project-pin.js +44 -0
- package/dist/governance/project-pin.test.d.ts +1 -0
- package/dist/governance/project-pin.test.js +35 -0
- package/dist/http.d.ts +1 -2
- package/dist/http.integration.test.d.ts +1 -0
- package/dist/http.integration.test.js +688 -0
- package/dist/http.js +3 -170
- package/dist/http.test.d.ts +4 -0
- package/dist/http.test.js +131 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.integration.test.js +73 -30
- package/dist/index.js +28 -27
- package/dist/index.test.js +3 -3
- package/dist/logging/structured.d.ts +27 -0
- package/dist/logging/structured.js +32 -0
- package/dist/logging/structured.test.d.ts +1 -0
- package/dist/logging/structured.test.js +33 -0
- package/dist/personas/index.d.ts +19 -0
- package/dist/personas/index.js +57 -0
- package/dist/personas/index.test.d.ts +1 -0
- package/dist/personas/index.test.js +58 -0
- package/dist/personas/organization-audit/v1/index.d.ts +8 -0
- package/dist/personas/organization-audit/v1/index.js +42 -0
- package/dist/personas/organization-audit/v1/prompts.d.ts +5 -0
- package/dist/personas/organization-audit/v1/prompts.js +111 -0
- package/dist/personas/organization-audit/v1/prompts.test.d.ts +4 -0
- package/dist/personas/organization-audit/v1/prompts.test.js +25 -0
- package/dist/personas/organization-audit/v1/resources/playbook.d.ts +11 -0
- package/dist/personas/organization-audit/v1/resources/playbook.js +40 -0
- package/dist/personas/organization-audit/v1/resources/playbook.md +52 -0
- package/dist/personas/semantic-layer/v1/index.d.ts +8 -0
- package/dist/personas/semantic-layer/v1/index.js +32 -0
- package/dist/personas/semantic-layer/v1/prompts.d.ts +5 -0
- package/dist/personas/semantic-layer/v1/prompts.js +107 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +12 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.js +42 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.md +153 -0
- package/dist/personas/types.d.ts +19 -0
- package/dist/personas/types.js +5 -0
- package/dist/protocol-contract.test.d.ts +1 -0
- package/dist/protocol-contract.test.js +42 -0
- package/dist/server/capabilities.d.ts +15 -0
- package/dist/server/capabilities.js +19 -0
- package/dist/server/capabilities.test.d.ts +1 -0
- package/dist/server/capabilities.test.js +39 -0
- package/dist/server/errors.test.d.ts +1 -0
- package/dist/server/errors.test.js +53 -0
- package/dist/server/request-context.d.ts +13 -0
- package/dist/server/request-context.js +2 -0
- package/dist/server/server.d.ts +4 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.test.d.ts +1 -0
- package/dist/server/server.test.js +15 -0
- package/dist/server/version.d.ts +1 -0
- package/dist/server/version.js +7 -0
- package/dist/server/version.test.d.ts +1 -0
- package/dist/server/version.test.js +9 -0
- package/dist/stdio.process.test.d.ts +1 -0
- package/dist/stdio.process.test.js +126 -0
- package/dist/tools/index.d.ts +2 -4
- package/dist/tools/index.js +4 -30
- package/dist/tools/index.test.d.ts +1 -0
- package/dist/tools/index.test.js +72 -0
- package/dist/tools/lib/api-errors.d.ts +9 -0
- package/dist/tools/lib/api-errors.js +22 -0
- package/dist/tools/lib/api-shape.d.ts +16 -0
- package/dist/tools/lib/api-shape.js +47 -0
- package/dist/tools/lib/assert-safe.d.ts +13 -0
- package/dist/tools/lib/assert-safe.js +21 -0
- package/dist/tools/lib/assert-safe.test.d.ts +4 -0
- package/dist/tools/lib/assert-safe.test.js +32 -0
- package/dist/tools/lib/concurrency.d.ts +4 -0
- package/dist/tools/lib/concurrency.js +24 -0
- package/dist/tools/lib/contracts.d.ts +34 -0
- package/dist/tools/lib/contracts.js +30 -0
- package/dist/tools/lib/redaction.d.ts +107 -0
- package/dist/tools/lib/redaction.js +299 -0
- package/dist/tools/lib/redaction.test.d.ts +4 -0
- package/dist/tools/lib/redaction.test.js +216 -0
- package/dist/tools/lib/register-org-audit.d.ts +9 -0
- package/dist/tools/lib/register-org-audit.js +20 -0
- package/dist/tools/lib/schema-fields.d.ts +9 -0
- package/dist/tools/lib/schema-fields.js +19 -0
- package/dist/tools/organization/binding.d.ts +14 -0
- package/dist/tools/organization/binding.js +31 -0
- package/dist/tools/organization/invariants.test.d.ts +4 -0
- package/dist/tools/organization/invariants.test.js +28 -0
- package/dist/tools/organization/inventory.d.ts +10 -0
- package/dist/tools/organization/inventory.js +189 -0
- package/dist/tools/organization/roles.d.ts +10 -0
- package/dist/tools/organization/roles.js +213 -0
- package/dist/tools/project/content.d.ts +9 -0
- package/dist/tools/project/content.js +192 -0
- package/dist/tools/project/projects.d.ts +7 -0
- package/dist/tools/project/projects.js +42 -0
- package/dist/tools/project/projects.test.d.ts +1 -0
- package/dist/tools/project/projects.test.js +117 -0
- package/dist/tools/project/schedulers.d.ts +7 -0
- package/dist/tools/project/schedulers.js +115 -0
- package/dist/tools/registry.d.ts +104 -0
- package/dist/tools/registry.js +59 -0
- package/dist/tools/semantic/explore-helpers.d.ts +56 -0
- package/dist/tools/semantic/explore-helpers.js +115 -0
- package/dist/tools/semantic/explore-helpers.test.d.ts +1 -0
- package/dist/tools/semantic/explore-helpers.test.js +170 -0
- package/dist/tools/semantic/explores.d.ts +9 -0
- package/dist/tools/semantic/explores.js +80 -0
- package/dist/tools/semantic/metrics.d.ts +7 -0
- package/dist/tools/semantic/metrics.js +53 -0
- package/dist/tools/semantic/query.d.ts +6 -0
- package/dist/tools/semantic/query.js +42 -0
- package/dist/tools/semantic/schema-fields.d.ts +3 -0
- package/dist/tools/semantic/schema-fields.js +7 -0
- package/dist/tools/shared.d.ts +26 -13
- package/dist/tools/shared.js +112 -157
- package/dist/tools/shared.test.js +132 -183
- package/dist/tools/space/access.d.ts +66 -0
- package/dist/tools/space/access.js +322 -0
- package/dist/tools/space/access.test.d.ts +4 -0
- package/dist/tools/space/access.test.js +90 -0
- package/dist/transports/http-body.d.ts +5 -0
- package/dist/transports/http-body.js +50 -0
- package/dist/transports/http-request-utils.d.ts +2 -0
- package/dist/transports/http-request-utils.js +13 -0
- package/dist/transports/http-response.d.ts +6 -0
- package/dist/transports/http-response.js +56 -0
- package/dist/transports/session-store.d.ts +40 -0
- package/dist/transports/session-store.js +88 -0
- package/dist/transports/session-store.test.d.ts +1 -0
- package/dist/transports/session-store.test.js +111 -0
- package/dist/transports/streamable-http.d.ts +9 -0
- package/dist/transports/streamable-http.js +454 -0
- package/dist/transports/streamable-http.test.d.ts +1 -0
- package/dist/transports/streamable-http.test.js +95 -0
- package/package.json +25 -10
- package/dist/audit.d.ts +0 -6
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -82
- package/dist/tools/ai-agents.d.ts +0 -6
- package/dist/tools/ai-agents.js +0 -388
- package/dist/tools/charts.d.ts +0 -6
- package/dist/tools/charts.js +0 -55
- package/dist/tools/content.d.ts +0 -6
- package/dist/tools/content.js +0 -37
- package/dist/tools/dashboards.d.ts +0 -6
- package/dist/tools/dashboards.js +0 -28
- package/dist/tools/explores.d.ts +0 -6
- package/dist/tools/explores.js +0 -65
- package/dist/tools/groups.d.ts +0 -6
- package/dist/tools/groups.js +0 -121
- package/dist/tools/metrics.d.ts +0 -6
- package/dist/tools/metrics.js +0 -45
- package/dist/tools/projects.d.ts +0 -6
- package/dist/tools/projects.js +0 -58
- package/dist/tools/query.d.ts +0 -6
- package/dist/tools/query.js +0 -34
- package/dist/tools/schedulers.d.ts +0 -6
- package/dist/tools/schedulers.js +0 -45
- package/dist/tools/spaces.d.ts +0 -6
- package/dist/tools/spaces.js +0 -128
- package/dist/tools/tags.d.ts +0 -6
- package/dist/tools/tags.js +0 -28
- package/dist/tools/users.d.ts +0 -6
- package/dist/tools/users.js +0 -50
- package/src/audit.ts +0 -6
- package/src/bin.ts +0 -58
- package/src/config.ts +0 -83
- package/src/errors.ts +0 -27
- package/src/http.ts +0 -187
- package/src/index.integration.test.ts +0 -57
- package/src/index.test.ts +0 -8
- package/src/index.ts +0 -31
- package/src/tools/ai-agents.ts +0 -759
- package/src/tools/charts.ts +0 -85
- package/src/tools/content.ts +0 -44
- package/src/tools/dashboards.ts +0 -25
- package/src/tools/explores.ts +0 -98
- package/src/tools/groups.ts +0 -180
- package/src/tools/index.ts +0 -35
- package/src/tools/metrics.ts +0 -42
- package/src/tools/projects.ts +0 -74
- package/src/tools/query.ts +0 -47
- package/src/tools/schedulers.ts +0 -42
- package/src/tools/shared.test.ts +0 -365
- package/src/tools/shared.ts +0 -274
- package/src/tools/spaces.ts +0 -217
- package/src/tools/tags.ts +0 -25
- package/src/tools/users.ts +0 -64
- package/tsconfig.json +0 -13
- /package/dist/{errors.d.ts → server/errors.d.ts} +0 -0
- /package/dist/{errors.js → server/errors.js} +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shipped MCP personas (path → definition). No PERSONA/PATH env knobs.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PERSONAS = exports.DEFAULT_PERSONA_ID = exports.ORGANIZATION_AUDIT_PERSONA_PATH = exports.SEMANTIC_LAYER_PERSONA_PATH = void 0;
|
|
7
|
+
exports.getPersona = getPersona;
|
|
8
|
+
exports.getDefaultPersona = getDefaultPersona;
|
|
9
|
+
exports.getPersonaByPath = getPersonaByPath;
|
|
10
|
+
exports.listPersonaPaths = listPersonaPaths;
|
|
11
|
+
exports.parsePersonaId = parsePersonaId;
|
|
12
|
+
exports.getPersonaServerName = getPersonaServerName;
|
|
13
|
+
const normalize_url_js_1 = require("../config/normalize-url.js");
|
|
14
|
+
const index_js_1 = require("./organization-audit/v1/index.js");
|
|
15
|
+
const index_js_2 = require("./semantic-layer/v1/index.js");
|
|
16
|
+
var index_js_3 = require("./semantic-layer/v1/index.js");
|
|
17
|
+
Object.defineProperty(exports, "SEMANTIC_LAYER_PERSONA_PATH", { enumerable: true, get: function () { return index_js_3.SEMANTIC_LAYER_PERSONA_PATH; } });
|
|
18
|
+
var index_js_4 = require("./organization-audit/v1/index.js");
|
|
19
|
+
Object.defineProperty(exports, "ORGANIZATION_AUDIT_PERSONA_PATH", { enumerable: true, get: function () { return index_js_4.ORGANIZATION_AUDIT_PERSONA_PATH; } });
|
|
20
|
+
/** Default stdio persona (backward compatible). */
|
|
21
|
+
exports.DEFAULT_PERSONA_ID = 'semantic-layer';
|
|
22
|
+
exports.PERSONAS = {
|
|
23
|
+
'semantic-layer': index_js_2.semanticLayerPersona,
|
|
24
|
+
'organization-audit': index_js_1.organizationAuditPersona,
|
|
25
|
+
};
|
|
26
|
+
const PERSONAS_BY_PATH = new Map(Object.values(exports.PERSONAS).map((persona) => [persona.path, persona]));
|
|
27
|
+
function getPersona(id) {
|
|
28
|
+
// eslint-disable-next-line security/detect-object-injection -- PersonaId union
|
|
29
|
+
return exports.PERSONAS[id];
|
|
30
|
+
}
|
|
31
|
+
function getDefaultPersona() {
|
|
32
|
+
return getPersona(exports.DEFAULT_PERSONA_ID);
|
|
33
|
+
}
|
|
34
|
+
/** Resolve persona from an HTTP request path, or undefined if unknown. */
|
|
35
|
+
function getPersonaByPath(path) {
|
|
36
|
+
try {
|
|
37
|
+
return PERSONAS_BY_PATH.get((0, normalize_url_js_1.normalizeMcpPath)(path));
|
|
38
|
+
}
|
|
39
|
+
catch (_a) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function listPersonaPaths() {
|
|
44
|
+
return [...PERSONAS_BY_PATH.keys()];
|
|
45
|
+
}
|
|
46
|
+
/** Parse a CLI persona id; returns undefined when invalid. */
|
|
47
|
+
function parsePersonaId(value) {
|
|
48
|
+
if (value === 'semantic-layer' || value === 'organization-audit') {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
/** MCP server display name for a persona. */
|
|
54
|
+
function getPersonaServerName(persona) {
|
|
55
|
+
var _a;
|
|
56
|
+
return (_a = persona.serverName) !== null && _a !== void 0 ? _a : `lightdash-mcp-${persona.id}`;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const registry_js_1 = require("../tools/registry.js");
|
|
5
|
+
const shared_js_1 = require("../tools/shared.js");
|
|
6
|
+
const index_js_1 = require("./organization-audit/v1/index.js");
|
|
7
|
+
const index_js_2 = require("./index.js");
|
|
8
|
+
(0, vitest_1.describe)('personas', () => {
|
|
9
|
+
(0, vitest_1.it)('ships semantic-layer and organization-audit with fixed paths', () => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
(0, vitest_1.expect)(Object.keys(index_js_2.PERSONAS).sort()).toEqual(['organization-audit', 'semantic-layer']);
|
|
12
|
+
(0, vitest_1.expect)(index_js_2.DEFAULT_PERSONA_ID).toBe('semantic-layer');
|
|
13
|
+
(0, vitest_1.expect)((0, index_js_2.listPersonaPaths)().sort()).toEqual([index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH, index_js_2.SEMANTIC_LAYER_PERSONA_PATH].sort());
|
|
14
|
+
(0, vitest_1.expect)((_a = (0, index_js_2.getPersonaByPath)(index_js_2.SEMANTIC_LAYER_PERSONA_PATH)) === null || _a === void 0 ? void 0 : _a.id).toBe('semantic-layer');
|
|
15
|
+
(0, vitest_1.expect)((_b = (0, index_js_2.getPersonaByPath)(index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH)) === null || _b === void 0 ? void 0 : _b.id).toBe('organization-audit');
|
|
16
|
+
(0, vitest_1.expect)((0, index_js_2.getPersonaByPath)('/mcp')).toBeUndefined();
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.it)('normalizes trailing slashes when resolving path', () => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
(0, vitest_1.expect)((_a = (0, index_js_2.getPersonaByPath)(`${index_js_2.SEMANTIC_LAYER_PERSONA_PATH}/`)) === null || _a === void 0 ? void 0 : _a.id).toBe('semantic-layer');
|
|
21
|
+
(0, vitest_1.expect)((_b = (0, index_js_2.getPersonaByPath)(`${index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH}/`)) === null || _b === void 0 ? void 0 : _b.id).toBe('organization-audit');
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.it)('semantic-layer allowlists exactly nine tools', () => {
|
|
24
|
+
const persona = (0, index_js_2.getPersona)('semantic-layer');
|
|
25
|
+
(0, vitest_1.expect)(persona.toolIds).toHaveLength(9);
|
|
26
|
+
(0, vitest_1.expect)((0, index_js_2.getDefaultPersona)().toolIds).toEqual(persona.toolIds);
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('organization-audit allowlists 18 tools and short server name', () => {
|
|
29
|
+
const persona = (0, index_js_2.getPersona)('organization-audit');
|
|
30
|
+
(0, vitest_1.expect)(persona.toolIds).toHaveLength(18);
|
|
31
|
+
(0, vitest_1.expect)(persona.toolIds).toEqual([...index_js_1.ORGANIZATION_AUDIT_TOOL_IDS]);
|
|
32
|
+
(0, vitest_1.expect)((0, index_js_2.getPersonaServerName)(persona)).toBe('lightdash-mcp-org-audit');
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.it)('keeps combined server+tool wire names under 60 characters', () => {
|
|
35
|
+
const persona = (0, index_js_2.getPersona)('organization-audit');
|
|
36
|
+
const serverName = (0, index_js_2.getPersonaServerName)(persona);
|
|
37
|
+
for (const id of persona.toolIds) {
|
|
38
|
+
const combined = serverName.length + (shared_js_1.TOOL_PREFIX + id).length;
|
|
39
|
+
(0, vitest_1.expect)(combined, `${serverName}+${shared_js_1.TOOL_PREFIX}${id}`).toBeLessThanOrEqual(60);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('parsePersonaId validates known ids only', () => {
|
|
43
|
+
(0, vitest_1.expect)((0, index_js_2.parsePersonaId)('semantic-layer')).toBe('semantic-layer');
|
|
44
|
+
(0, vitest_1.expect)((0, index_js_2.parsePersonaId)('organization-audit')).toBe('organization-audit');
|
|
45
|
+
(0, vitest_1.expect)((0, index_js_2.parsePersonaId)('nope')).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.it)('registerToolsByIds registers only allowlisted ids', () => {
|
|
48
|
+
const registered = [];
|
|
49
|
+
const mockServer = {
|
|
50
|
+
registerTool: vitest_1.vi.fn((name) => {
|
|
51
|
+
registered.push(name);
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
const mockCtx = { getContext: async () => ({ lightdashClient: {} }) };
|
|
55
|
+
(0, registry_js_1.registerToolsByIds)(mockServer, mockCtx, ['list_projects', 'compile_query']);
|
|
56
|
+
(0, vitest_1.expect)(registered).toEqual([`${shared_js_1.TOOL_PREFIX}list_projects`, `${shared_js_1.TOOL_PREFIX}compile_query`]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Organization-audit persona: read-only org inventory, access, content health, schedulers.
|
|
3
|
+
*/
|
|
4
|
+
import type { PersonaDefinition } from '../../types.js';
|
|
5
|
+
export declare const ORGANIZATION_AUDIT_PERSONA_PATH: "/organization-audit/v1/mcp";
|
|
6
|
+
/** Explicit allowlist — must stay a deliberate subset of the shared registry. */
|
|
7
|
+
export declare const ORGANIZATION_AUDIT_TOOL_IDS: readonly ["get_org_profile", "list_org_members", "get_org_member", "list_org_groups", "list_org_projects", "list_org_role_assignments", "list_custom_roles", "get_custom_role", "list_project_roles", "list_project_direct_access", "list_space_access", "resolve_effective_access", "list_content", "get_dashboard_meta", "list_validation_results", "get_project_user_activity", "list_project_schedulers", "get_scheduler"];
|
|
8
|
+
export declare const organizationAuditPersona: PersonaDefinition;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Organization-audit persona: read-only org inventory, access, content health, schedulers.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.organizationAuditPersona = exports.ORGANIZATION_AUDIT_TOOL_IDS = exports.ORGANIZATION_AUDIT_PERSONA_PATH = void 0;
|
|
7
|
+
const prompts_js_1 = require("./prompts.js");
|
|
8
|
+
const playbook_js_1 = require("./resources/playbook.js");
|
|
9
|
+
exports.ORGANIZATION_AUDIT_PERSONA_PATH = '/organization-audit/v1/mcp';
|
|
10
|
+
/** Explicit allowlist — must stay a deliberate subset of the shared registry. */
|
|
11
|
+
exports.ORGANIZATION_AUDIT_TOOL_IDS = [
|
|
12
|
+
'get_org_profile',
|
|
13
|
+
'list_org_members',
|
|
14
|
+
'get_org_member',
|
|
15
|
+
'list_org_groups',
|
|
16
|
+
'list_org_projects',
|
|
17
|
+
'list_org_role_assignments',
|
|
18
|
+
'list_custom_roles',
|
|
19
|
+
'get_custom_role',
|
|
20
|
+
'list_project_roles',
|
|
21
|
+
'list_project_direct_access',
|
|
22
|
+
'list_space_access',
|
|
23
|
+
'resolve_effective_access',
|
|
24
|
+
'list_content',
|
|
25
|
+
'get_dashboard_meta',
|
|
26
|
+
'list_validation_results',
|
|
27
|
+
'get_project_user_activity',
|
|
28
|
+
'list_project_schedulers',
|
|
29
|
+
'get_scheduler',
|
|
30
|
+
];
|
|
31
|
+
exports.organizationAuditPersona = {
|
|
32
|
+
id: 'organization-audit',
|
|
33
|
+
path: exports.ORGANIZATION_AUDIT_PERSONA_PATH,
|
|
34
|
+
serverName: 'lightdash-mcp-org-audit',
|
|
35
|
+
toolIds: exports.ORGANIZATION_AUDIT_TOOL_IDS,
|
|
36
|
+
registerPrompts: (server) => {
|
|
37
|
+
(0, prompts_js_1.registerOrganizationAuditPrompts)(server);
|
|
38
|
+
},
|
|
39
|
+
registerResources: (server) => {
|
|
40
|
+
(0, playbook_js_1.registerOrganizationAuditPlaybook)(server);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP prompts for organization-audit workflows.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerOrganizationAuditPrompts = registerOrganizationAuditPrompts;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-deprecated -- matches semantic-layer prompt registration pattern */
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const playbook_js_1 = require("./resources/playbook.js");
|
|
10
|
+
function playbookEmbeddedResource() {
|
|
11
|
+
return {
|
|
12
|
+
type: 'resource',
|
|
13
|
+
resource: {
|
|
14
|
+
uri: playbook_js_1.ORGANIZATION_AUDIT_PLAYBOOK_URI,
|
|
15
|
+
mimeType: playbook_js_1.ORGANIZATION_AUDIT_PLAYBOOK_MIME,
|
|
16
|
+
text: (0, playbook_js_1.getPlaybookMarkdown)(),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function userMessages(text) {
|
|
21
|
+
return {
|
|
22
|
+
messages: [
|
|
23
|
+
{
|
|
24
|
+
role: 'user',
|
|
25
|
+
content: { type: 'text', text },
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
role: 'user',
|
|
29
|
+
content: playbookEmbeddedResource(),
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function registerOrganizationAuditPrompts(server) {
|
|
35
|
+
server.registerPrompt('audit_organization', {
|
|
36
|
+
title: 'Audit organization',
|
|
37
|
+
description: 'Evidence-backed read-only organization audit via primitive tools',
|
|
38
|
+
argsSchema: {
|
|
39
|
+
projectUuids: zod_1.z.string().optional().describe('Comma-separated project UUIDs'),
|
|
40
|
+
allowedEmailDomains: zod_1.z
|
|
41
|
+
.string()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Comma-separated allowed email domains'),
|
|
44
|
+
},
|
|
45
|
+
}, ({ projectUuids, allowedEmailDomains }) => userMessages(`Perform an evidence-backed, read-only audit of the current Lightdash organization.
|
|
46
|
+
|
|
47
|
+
${playbook_js_1.ORGANIZATION_AUDIT_HARD_BANS}
|
|
48
|
+
|
|
49
|
+
Scope:
|
|
50
|
+
- Use only the organization and projects visible to the authenticated caller.
|
|
51
|
+
- Respect any project pin (X-Lightdash-Project).
|
|
52
|
+
- Optional project filter: ${projectUuids !== null && projectUuids !== void 0 ? projectUuids : '(all accessible non-preview projects up to a small cap)'}.
|
|
53
|
+
- Allowed email domains for delivery review: ${allowedEmailDomains !== null && allowedEmailDomains !== void 0 ? allowedEmailDomains : '(none — treat unknown domains carefully)'}.
|
|
54
|
+
|
|
55
|
+
Procedure (primitives only — there are no lightdash_audit_* tools):
|
|
56
|
+
1. Resolve organization identity via lightdash_get_org_profile.
|
|
57
|
+
2. Follow the playbook phases: identity → projects/access → content → deliveries → report.
|
|
58
|
+
3. Paginate list tools only while pagination.complete is false, and stop after an agreed page/project budget.
|
|
59
|
+
4. Synthesize findings yourself from returned evidence; distinguish facts, inferred risks, assumptions, inaccessible areas, and truncation.
|
|
60
|
+
5. Cite every finding with lightdash_* tool names and resource UUIDs.
|
|
61
|
+
6. Do not claim formal compliance certification.`));
|
|
62
|
+
server.registerPrompt('review_access_governance', {
|
|
63
|
+
title: 'Review access governance',
|
|
64
|
+
description: 'Build an effective-access model from identity and access primitives',
|
|
65
|
+
argsSchema: {},
|
|
66
|
+
}, () => userMessages(`Review Lightdash identity and access governance.
|
|
67
|
+
|
|
68
|
+
${playbook_js_1.ORGANIZATION_AUDIT_HARD_BANS}
|
|
69
|
+
|
|
70
|
+
Use lightdash_list_org_members, lightdash_list_org_role_assignments, lightdash_list_project_roles, lightdash_list_project_direct_access, lightdash_list_space_access, and lightdash_resolve_effective_access.
|
|
71
|
+
Do not treat lightdash_list_project_direct_access as complete effective access.
|
|
72
|
+
State assumptions and coverage gaps.`));
|
|
73
|
+
server.registerPrompt('review_content_governance', {
|
|
74
|
+
title: 'Review content governance',
|
|
75
|
+
description: 'Inventory content health and ownership risks via list tools',
|
|
76
|
+
argsSchema: {},
|
|
77
|
+
}, () => userMessages(`Inventory charts, dashboards, and spaces; evaluate validation, ownership, and usage.
|
|
78
|
+
|
|
79
|
+
${playbook_js_1.ORGANIZATION_AUDIT_HARD_BANS}
|
|
80
|
+
|
|
81
|
+
Use lightdash_list_content, lightdash_list_validation_results, and lightdash_get_project_user_activity (plus lightdash_get_dashboard_meta when needed).
|
|
82
|
+
Join results in the conversation — do not assume a server-side audit tool.
|
|
83
|
+
Do not recommend deletion solely because content is unused.`));
|
|
84
|
+
server.registerPrompt('review_scheduled_deliveries', {
|
|
85
|
+
title: 'Review scheduled deliveries',
|
|
86
|
+
description: 'Inspect schedulers without executing them',
|
|
87
|
+
argsSchema: {
|
|
88
|
+
allowedEmailDomains: zod_1.z.string().optional(),
|
|
89
|
+
},
|
|
90
|
+
}, ({ allowedEmailDomains }) => userMessages(`Inspect scheduled deliveries without creating, editing, executing, enabling, disabling, or deleting schedules.
|
|
91
|
+
|
|
92
|
+
${playbook_js_1.ORGANIZATION_AUDIT_HARD_BANS}
|
|
93
|
+
|
|
94
|
+
Allowed email domains: ${allowedEmailDomains !== null && allowedEmailDomains !== void 0 ? allowedEmailDomains : '(none provided)'}.
|
|
95
|
+
Use lightdash_list_project_schedulers and lightdash_get_scheduler.
|
|
96
|
+
Redact destinations by default. External destinations are review signals, not automatic violations.`));
|
|
97
|
+
server.registerPrompt('investigate_audit_finding', {
|
|
98
|
+
title: 'Investigate audit finding',
|
|
99
|
+
description: 'Validate or refute one previously reported finding',
|
|
100
|
+
argsSchema: {
|
|
101
|
+
findingSummary: zod_1.z.string().describe('The finding claim to investigate'),
|
|
102
|
+
},
|
|
103
|
+
}, ({ findingSummary }) => userMessages(`Investigate this organization-audit finding with minimum additional metadata:
|
|
104
|
+
|
|
105
|
+
${findingSummary}
|
|
106
|
+
|
|
107
|
+
${playbook_js_1.ORGANIZATION_AUDIT_HARD_BANS}
|
|
108
|
+
|
|
109
|
+
Use only primitive list/get tools. Report supporting evidence, contradictory evidence, remaining uncertainty, and whether severity/confidence changed.`));
|
|
110
|
+
}
|
|
111
|
+
/* eslint-enable @typescript-eslint/no-deprecated */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Organization-audit prompt/playbook invariants.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const playbook_js_1 = require("./resources/playbook.js");
|
|
8
|
+
const index_js_1 = require("./index.js");
|
|
9
|
+
(0, vitest_1.describe)('organization-audit prompts/playbook', () => {
|
|
10
|
+
(0, vitest_1.it)('playbook references only registered tool short ids', () => {
|
|
11
|
+
const md = (0, playbook_js_1.getPlaybookMarkdown)();
|
|
12
|
+
for (const id of index_js_1.ORGANIZATION_AUDIT_TOOL_IDS) {
|
|
13
|
+
(0, vitest_1.expect)(md.includes(id) || md.includes(`lightdash_${id}`)).toBe(true);
|
|
14
|
+
}
|
|
15
|
+
(0, vitest_1.expect)(md).not.toMatch(/\bldt__/);
|
|
16
|
+
(0, vitest_1.expect)(md.toLowerCase()).toContain('hard bans');
|
|
17
|
+
(0, vitest_1.expect)(playbook_js_1.ORGANIZATION_AUDIT_HARD_BANS.toLowerCase()).toContain('compliance');
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.it)('playbook forbids mutation and warehouse queries', () => {
|
|
20
|
+
const md = (0, playbook_js_1.getPlaybookMarkdown)().toLowerCase();
|
|
21
|
+
(0, vitest_1.expect)(md).toContain('do not mutate');
|
|
22
|
+
(0, vitest_1.expect)(md).toContain('warehouse');
|
|
23
|
+
(0, vitest_1.expect)(md).toContain('deletion');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static organization-audit playbook resource.
|
|
3
|
+
*/
|
|
4
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
+
export declare const ORGANIZATION_AUDIT_PLAYBOOK_URI = "lightdash://playbooks/organization-audit";
|
|
6
|
+
export declare const ORGANIZATION_AUDIT_PLAYBOOK_MIME = "text/markdown";
|
|
7
|
+
export declare const ORGANIZATION_AUDIT_PLAYBOOK_NAME = "organization_audit_playbook";
|
|
8
|
+
export declare const ORGANIZATION_AUDIT_HARD_BANS = "Do not mutate users/groups/roles/content/schedulers, execute warehouse or chart queries, download user-activity CSV, reveal secrets, or claim compliance certification. Those capabilities are not available on this server.";
|
|
9
|
+
/** Loads playbook markdown from disk (next to this module after build). */
|
|
10
|
+
export declare function getPlaybookMarkdown(): string;
|
|
11
|
+
export declare function registerOrganizationAuditPlaybook(server: McpServer): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Static organization-audit playbook resource.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ORGANIZATION_AUDIT_HARD_BANS = exports.ORGANIZATION_AUDIT_PLAYBOOK_NAME = exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME = exports.ORGANIZATION_AUDIT_PLAYBOOK_URI = void 0;
|
|
7
|
+
exports.getPlaybookMarkdown = getPlaybookMarkdown;
|
|
8
|
+
exports.registerOrganizationAuditPlaybook = registerOrganizationAuditPlaybook;
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
exports.ORGANIZATION_AUDIT_PLAYBOOK_URI = 'lightdash://playbooks/organization-audit';
|
|
12
|
+
exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME = 'text/markdown';
|
|
13
|
+
exports.ORGANIZATION_AUDIT_PLAYBOOK_NAME = 'organization_audit_playbook';
|
|
14
|
+
exports.ORGANIZATION_AUDIT_HARD_BANS = 'Do not mutate users/groups/roles/content/schedulers, execute warehouse or chart queries, download user-activity CSV, reveal secrets, or claim compliance certification. Those capabilities are not available on this server.';
|
|
15
|
+
let cachedPlaybookMarkdown;
|
|
16
|
+
/** Loads playbook markdown from disk (next to this module after build). */
|
|
17
|
+
function getPlaybookMarkdown() {
|
|
18
|
+
if (cachedPlaybookMarkdown !== undefined) {
|
|
19
|
+
return cachedPlaybookMarkdown;
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- __dirname + constant filename
|
|
22
|
+
cachedPlaybookMarkdown = (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, 'playbook.md'), 'utf8');
|
|
23
|
+
return cachedPlaybookMarkdown;
|
|
24
|
+
}
|
|
25
|
+
function registerOrganizationAuditPlaybook(server) {
|
|
26
|
+
const markdown = getPlaybookMarkdown();
|
|
27
|
+
server.registerResource(exports.ORGANIZATION_AUDIT_PLAYBOOK_NAME, exports.ORGANIZATION_AUDIT_PLAYBOOK_URI, {
|
|
28
|
+
title: 'Organization-audit playbook',
|
|
29
|
+
description: 'How to inventory and audit Lightdash organization identity, access, content health, and deliveries',
|
|
30
|
+
mimeType: exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME,
|
|
31
|
+
}, async (uri) => ({
|
|
32
|
+
contents: [
|
|
33
|
+
{
|
|
34
|
+
uri: typeof uri === 'string' ? uri : uri.href,
|
|
35
|
+
mimeType: exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME,
|
|
36
|
+
text: markdown,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Organization-audit playbook
|
|
2
|
+
|
|
3
|
+
Read-only evidence collection for Lightdash organization administrators. Findings are review signals synthesized by the host from primitive tool results — not compliance certifications. There are no composed `audit_*` MCP tools; chain bounded `lightdash_*` reads instead.
|
|
4
|
+
|
|
5
|
+
## Hard bans
|
|
6
|
+
|
|
7
|
+
- Do not mutate users, groups, roles, spaces, content, or schedulers.
|
|
8
|
+
- Do not execute warehouse, SQL, chart, or underlying-data queries.
|
|
9
|
+
- Do not download user-activity CSV (`POST .../download`).
|
|
10
|
+
- Do not treat direct project access as complete effective access.
|
|
11
|
+
- Do not recommend deletion solely because content has low usage.
|
|
12
|
+
- Do not claim SOC 2 / GDPR / ISO / HIPAA certification from these tools.
|
|
13
|
+
- Do not crawl the whole org in one step — respect `pagination.complete` and stop after agreed page/project limits.
|
|
14
|
+
- Do not request warehouse/dbt connection secrets via MCP — `warehouseConnection`, `dbtConnection`, and related credentials are never returned (ADR-0011); use `@lightdash-tools/client` or the CLI when operators need them.
|
|
15
|
+
|
|
16
|
+
## Tool catalog (`lightdash_*`)
|
|
17
|
+
|
|
18
|
+
Inventory: `get_org_profile`, `list_org_members`, `get_org_member`, `list_org_groups`, `list_org_projects`
|
|
19
|
+
|
|
20
|
+
Access: `list_org_role_assignments`, `list_custom_roles`, `get_custom_role`, `list_project_roles`, `list_project_direct_access`, `list_space_access`, `resolve_effective_access`
|
|
21
|
+
|
|
22
|
+
Content / health: `list_content`, `get_dashboard_meta`, `list_validation_results`, `get_project_user_activity`
|
|
23
|
+
|
|
24
|
+
Delivery: `list_project_schedulers`, `get_scheduler`
|
|
25
|
+
|
|
26
|
+
## Phases
|
|
27
|
+
|
|
28
|
+
### Phase 0 — Scope
|
|
29
|
+
|
|
30
|
+
1. Call `lightdash_get_org_profile`.
|
|
31
|
+
2. Record organization UUID, project pin (`X-Lightdash-Project`), thresholds, and `auditVisibility`.
|
|
32
|
+
3. Downgrade organization-wide claims when visibility is `partial`.
|
|
33
|
+
|
|
34
|
+
### Phase 1 — Identity
|
|
35
|
+
|
|
36
|
+
Call `list_org_members` (paginate while `pagination.complete` is false, or stop after a small page budget). Optionally `list_org_groups`, `list_org_role_assignments`, `list_custom_roles`, `get_org_member` for spot checks.
|
|
37
|
+
|
|
38
|
+
### Phase 2 — Projects and access
|
|
39
|
+
|
|
40
|
+
Call `list_org_projects`, then for a capped set of projects: `list_project_roles`, `list_project_direct_access`, `list_space_access`, and `resolve_effective_access`. Treat `list_project_direct_access` as direct grants only; emails are masked by default — pass `includeEmail=true` only when required. Pass `allowedEmailDomains` when classifying external direct-access principals. Honor incomplete flags and truncation warnings.
|
|
41
|
+
|
|
42
|
+
### Phase 3 — Content and health
|
|
43
|
+
|
|
44
|
+
Per project (capped): `list_content` (use `sortBy`/`sortDirection`/`page` intentionally), `list_validation_results`, `get_project_user_activity`. Use `get_dashboard_meta` only when needed. Host joins validation, views, and ownership into findings — do not invent a server-side crawler.
|
|
45
|
+
|
|
46
|
+
### Phase 4 — Deliveries
|
|
47
|
+
|
|
48
|
+
Per project (capped): `list_project_schedulers` (destinations redacted by default; pass `revealDestinations` only when required). Use `get_scheduler` with `projectUuid` + `schedulerUuid` for one schedule. Pass `allowedEmailDomains` when reviewing external email destinations.
|
|
49
|
+
|
|
50
|
+
### Phase 5 — Report
|
|
51
|
+
|
|
52
|
+
Synthesize findings from tool evidence in the conversation. Always include coverage gaps, assumptions, truncation, and resource UUIDs. Never claim the inventory was exhaustive when `pagination.complete` is false.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic-layer persona: compile/discovery tools + playbook/prompts.
|
|
3
|
+
*/
|
|
4
|
+
import type { PersonaDefinition } from '../../types.js';
|
|
5
|
+
export declare const SEMANTIC_LAYER_PERSONA_PATH: "/semantic-layer/v1/mcp";
|
|
6
|
+
/** Explicit allowlist — must stay a deliberate subset of the shared registry. */
|
|
7
|
+
export declare const SEMANTIC_LAYER_TOOL_IDS: readonly ["list_projects", "get_project", "list_explores", "get_explore", "list_dimensions", "get_field_lineage", "list_metrics", "get_metric", "compile_query"];
|
|
8
|
+
export declare const semanticLayerPersona: PersonaDefinition;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Semantic-layer persona: compile/discovery tools + playbook/prompts.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.semanticLayerPersona = exports.SEMANTIC_LAYER_TOOL_IDS = exports.SEMANTIC_LAYER_PERSONA_PATH = void 0;
|
|
7
|
+
const prompts_js_1 = require("./prompts.js");
|
|
8
|
+
const playbook_js_1 = require("./resources/playbook.js");
|
|
9
|
+
exports.SEMANTIC_LAYER_PERSONA_PATH = '/semantic-layer/v1/mcp';
|
|
10
|
+
/** Explicit allowlist — must stay a deliberate subset of the shared registry. */
|
|
11
|
+
exports.SEMANTIC_LAYER_TOOL_IDS = [
|
|
12
|
+
'list_projects',
|
|
13
|
+
'get_project',
|
|
14
|
+
'list_explores',
|
|
15
|
+
'get_explore',
|
|
16
|
+
'list_dimensions',
|
|
17
|
+
'get_field_lineage',
|
|
18
|
+
'list_metrics',
|
|
19
|
+
'get_metric',
|
|
20
|
+
'compile_query',
|
|
21
|
+
];
|
|
22
|
+
exports.semanticLayerPersona = {
|
|
23
|
+
id: 'semantic-layer',
|
|
24
|
+
path: exports.SEMANTIC_LAYER_PERSONA_PATH,
|
|
25
|
+
toolIds: exports.SEMANTIC_LAYER_TOOL_IDS,
|
|
26
|
+
registerPrompts: (server) => {
|
|
27
|
+
(0, prompts_js_1.registerSemanticLayerPrompts)(server);
|
|
28
|
+
},
|
|
29
|
+
registerResources: (server) => {
|
|
30
|
+
(0, playbook_js_1.registerPlaybookResource)(server);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP prompts for semantic-layer discovery and compile workflows.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerSemanticLayerPrompts = registerSemanticLayerPrompts;
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const schema_fields_js_1 = require("../../../tools/lib/schema-fields.js");
|
|
9
|
+
const schema_fields_js_2 = require("../../../tools/semantic/schema-fields.js");
|
|
10
|
+
const playbook_js_1 = require("./resources/playbook.js");
|
|
11
|
+
function playbookEmbeddedResource() {
|
|
12
|
+
return {
|
|
13
|
+
type: 'resource',
|
|
14
|
+
resource: {
|
|
15
|
+
uri: playbook_js_1.SEMANTIC_LAYER_PLAYBOOK_URI,
|
|
16
|
+
mimeType: playbook_js_1.SEMANTIC_LAYER_PLAYBOOK_MIME,
|
|
17
|
+
text: (0, playbook_js_1.getPlaybookMarkdown)(),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function userMessages(text) {
|
|
22
|
+
return {
|
|
23
|
+
messages: [
|
|
24
|
+
{
|
|
25
|
+
role: 'user',
|
|
26
|
+
content: {
|
|
27
|
+
type: 'text',
|
|
28
|
+
text,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
role: 'user',
|
|
33
|
+
content: playbookEmbeddedResource(),
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function registerSemanticLayerPrompts(server) {
|
|
39
|
+
server.registerPrompt('lightdash_semantic_explore', {
|
|
40
|
+
title: 'Explore semantic layer',
|
|
41
|
+
description: 'Locate explores, metrics, and dimensions for a question without running warehouse queries',
|
|
42
|
+
argsSchema: zod_1.z.object({
|
|
43
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)(),
|
|
44
|
+
question: zod_1.z.string().optional().describe('Natural-language question or topic'),
|
|
45
|
+
}),
|
|
46
|
+
}, async ({ projectUuid, question }) => {
|
|
47
|
+
const topic = question ? ` Question/topic: ${question}.` : '';
|
|
48
|
+
return userMessages([
|
|
49
|
+
'Discover the Lightdash semantic layer for this project. Compile is out of scope unless asked.',
|
|
50
|
+
`Project: ${projectUuid}.${topic}`,
|
|
51
|
+
playbook_js_1.SEMANTIC_LAYER_HARD_BANS,
|
|
52
|
+
'Procedure:',
|
|
53
|
+
'1) Stick to this projectUuid (do not switch from an org-wide list_projects). Warehouse/dataset/table hints are search keys only.',
|
|
54
|
+
'2) Always lightdash_list_explores with search+limit; disambiguate per playbook (schemaName, label or name __{table}, skip empty schema when dataset known).',
|
|
55
|
+
'3) Shortlist base-table dimensions by role; once explore is known prefer get_explore → tables[baseTable].metrics only (catalog keyword optional, still filter tableName === explore id).',
|
|
56
|
+
'Deliverable: shortlist name/label/schemaName/fieldId (+ why). Do not dump full explore/dimension/metric/lineage payloads.',
|
|
57
|
+
`Follow the embedded playbook (${playbook_js_1.SEMANTIC_LAYER_PLAYBOOK_URI}). Use only lightdash_* tools.`,
|
|
58
|
+
].join('\n'));
|
|
59
|
+
});
|
|
60
|
+
server.registerPrompt('lightdash_semantic_compose_compile', {
|
|
61
|
+
title: 'Compose and compile query',
|
|
62
|
+
description: 'Build a metric query and compile it with lightdash_compile_query; never execute against the warehouse',
|
|
63
|
+
argsSchema: zod_1.z.object({
|
|
64
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)(),
|
|
65
|
+
question: zod_1.z.string().optional().describe('What the query should answer'),
|
|
66
|
+
exploreId: (0, schema_fields_js_2.exploreIdField)().optional(),
|
|
67
|
+
}),
|
|
68
|
+
}, async ({ projectUuid, question, exploreId }) => {
|
|
69
|
+
const topic = question ? ` Goal: ${question}.` : '';
|
|
70
|
+
const explore = exploreId ? ` Preferred explore: ${exploreId}.` : '';
|
|
71
|
+
return userMessages([
|
|
72
|
+
'Compose a Lightdash metric query and compile it with lightdash_compile_query. Do not run the query.',
|
|
73
|
+
`Project: ${projectUuid}.${topic}${explore}`,
|
|
74
|
+
playbook_js_1.SEMANTIC_LAYER_HARD_BANS,
|
|
75
|
+
'Procedure:',
|
|
76
|
+
'1) If exploreId is missing, resolve it per playbook (search + disambiguation).',
|
|
77
|
+
'2) Use full fieldIds from list_dimensions / {exploreId}_{metricName}; prefer get_explore → tables[baseTable].metrics once explore is known.',
|
|
78
|
+
'3) If the user asked for N insights, reuse one explore and compile N diverse cuts from available fields.',
|
|
79
|
+
'4) Compile with fieldIds only; on empty SELECT or unknown field id, fix fieldIds and re-compile once. Extra related metrics in SQL can be OK. Stop after a good compile.',
|
|
80
|
+
'Deliverable: insight title(s) + fieldIds + compiled SQL (or errors). Never paste full explore/dimension/metric/lineage payloads.',
|
|
81
|
+
`Follow the embedded playbook (${playbook_js_1.SEMANTIC_LAYER_PLAYBOOK_URI}).`,
|
|
82
|
+
].join('\n'));
|
|
83
|
+
});
|
|
84
|
+
server.registerPrompt('lightdash_semantic_compile_debug', {
|
|
85
|
+
title: 'Debug compile errors',
|
|
86
|
+
description: 'Interpret lightdash_compile_query failures, adjust the metric query, and re-compile',
|
|
87
|
+
argsSchema: zod_1.z.object({
|
|
88
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)(),
|
|
89
|
+
exploreId: (0, schema_fields_js_2.exploreIdField)(),
|
|
90
|
+
errorText: zod_1.z.string().optional().describe('Compile error text if already known'),
|
|
91
|
+
}),
|
|
92
|
+
}, async ({ projectUuid, exploreId, errorText }) => {
|
|
93
|
+
const err = errorText ? ` Error: ${errorText}` : '';
|
|
94
|
+
return userMessages([
|
|
95
|
+
'Debug a failing lightdash_compile_query call and re-compile until it succeeds or you explain blockers.',
|
|
96
|
+
`Project: ${projectUuid}`,
|
|
97
|
+
`Explore: ${exploreId}.${err}`,
|
|
98
|
+
playbook_js_1.SEMANTIC_LAYER_HARD_BANS,
|
|
99
|
+
'Checklist:',
|
|
100
|
+
'- Empty SELECT or unknown field id → use fieldIds from lightdash_list_dimensions (base table).',
|
|
101
|
+
'- Wrong explore → re-disambiguate per playbook (schemaName; label or name __{table}).',
|
|
102
|
+
'- Metric not found / catalog empty → get_explore tables[baseTable].metrics; tableName must be the full explore id; compile as {exploreId}_{metricName}.',
|
|
103
|
+
'Deliverable: successful compile (SQL with expected columns) or a clear blocker. Stop after a good compile.',
|
|
104
|
+
`Follow the embedded playbook (${playbook_js_1.SEMANTIC_LAYER_PLAYBOOK_URI}).`,
|
|
105
|
+
].join('\n'));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static semantic-layer playbook resource.
|
|
3
|
+
*/
|
|
4
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
+
export declare const SEMANTIC_LAYER_PLAYBOOK_URI = "lightdash://playbooks/semantic-layer";
|
|
6
|
+
export declare const SEMANTIC_LAYER_PLAYBOOK_MIME = "text/markdown";
|
|
7
|
+
export declare const SEMANTIC_LAYER_PLAYBOOK_NAME = "semantic_layer_playbook";
|
|
8
|
+
/** Shared hard-ban text for prompts (keep in sync with playbook.md Hard bans section). */
|
|
9
|
+
export declare const SEMANTIC_LAYER_HARD_BANS = "Do not run metric/SQL/chart queries, use SQL runner, trigger validation jobs, mutate content, or call AI/identity tools. Those are not available on this server.";
|
|
10
|
+
/** Loads playbook markdown from disk (next to this module after build). */
|
|
11
|
+
export declare function getPlaybookMarkdown(): string;
|
|
12
|
+
export declare function registerPlaybookResource(server: McpServer): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Static semantic-layer playbook resource.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SEMANTIC_LAYER_HARD_BANS = exports.SEMANTIC_LAYER_PLAYBOOK_NAME = exports.SEMANTIC_LAYER_PLAYBOOK_MIME = exports.SEMANTIC_LAYER_PLAYBOOK_URI = void 0;
|
|
7
|
+
exports.getPlaybookMarkdown = getPlaybookMarkdown;
|
|
8
|
+
exports.registerPlaybookResource = registerPlaybookResource;
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
exports.SEMANTIC_LAYER_PLAYBOOK_URI = 'lightdash://playbooks/semantic-layer';
|
|
12
|
+
exports.SEMANTIC_LAYER_PLAYBOOK_MIME = 'text/markdown';
|
|
13
|
+
exports.SEMANTIC_LAYER_PLAYBOOK_NAME = 'semantic_layer_playbook';
|
|
14
|
+
/** Shared hard-ban text for prompts (keep in sync with playbook.md Hard bans section). */
|
|
15
|
+
exports.SEMANTIC_LAYER_HARD_BANS = 'Do not run metric/SQL/chart queries, use SQL runner, trigger validation jobs, mutate content, or call AI/identity tools. Those are not available on this server.';
|
|
16
|
+
let cachedPlaybookMarkdown;
|
|
17
|
+
/** Loads playbook markdown from disk (next to this module after build). */
|
|
18
|
+
function getPlaybookMarkdown() {
|
|
19
|
+
if (cachedPlaybookMarkdown !== undefined) {
|
|
20
|
+
return cachedPlaybookMarkdown;
|
|
21
|
+
}
|
|
22
|
+
// Playbook path is fixed next to this module (copied into dist on build).
|
|
23
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- __dirname + constant filename
|
|
24
|
+
cachedPlaybookMarkdown = (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, 'playbook.md'), 'utf8');
|
|
25
|
+
return cachedPlaybookMarkdown;
|
|
26
|
+
}
|
|
27
|
+
function registerPlaybookResource(server) {
|
|
28
|
+
const markdown = getPlaybookMarkdown();
|
|
29
|
+
server.registerResource(exports.SEMANTIC_LAYER_PLAYBOOK_NAME, exports.SEMANTIC_LAYER_PLAYBOOK_URI, {
|
|
30
|
+
title: 'Semantic-layer playbook',
|
|
31
|
+
description: 'How to discover Lightdash explores/metrics and compile metric queries without running them',
|
|
32
|
+
mimeType: exports.SEMANTIC_LAYER_PLAYBOOK_MIME,
|
|
33
|
+
}, async (uri) => ({
|
|
34
|
+
contents: [
|
|
35
|
+
{
|
|
36
|
+
uri: typeof uri === 'string' ? uri : uri.href,
|
|
37
|
+
mimeType: exports.SEMANTIC_LAYER_PLAYBOOK_MIME,
|
|
38
|
+
text: markdown,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
}));
|
|
42
|
+
}
|