@lightdash-tools/mcp 0.6.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,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP tools: projects (list, get) — shared catalog entries.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerListProjects = registerListProjects;
|
|
7
|
+
exports.registerGetProject = registerGetProject;
|
|
8
|
+
const project_pin_js_1 = require("../../governance/project-pin.js");
|
|
9
|
+
const redaction_js_1 = require("../lib/redaction.js");
|
|
10
|
+
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
11
|
+
const shared_js_1 = require("../shared.js");
|
|
12
|
+
function registerListProjects(server, contextProvider) {
|
|
13
|
+
(0, shared_js_1.registerToolSafe)(server, 'list_projects', {
|
|
14
|
+
title: 'List projects',
|
|
15
|
+
description: 'List project metadata in the current organization (or the pinned project when X-Lightdash-Project is set). Connection credentials are never returned.',
|
|
16
|
+
inputSchema: {},
|
|
17
|
+
annotations: shared_js_1.READ_ONLY_DEFAULT,
|
|
18
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async () => {
|
|
19
|
+
const pinned = (0, project_pin_js_1.getPinnedProjectUuid)();
|
|
20
|
+
const projects = pinned
|
|
21
|
+
? [await c.v1.projects.getProject(pinned)]
|
|
22
|
+
: await c.v1.projects.listProjects();
|
|
23
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
24
|
+
data: projects.map((p) => (0, redaction_js_1.toProjectSummary)(p)),
|
|
25
|
+
warnings: [redaction_js_1.CREDENTIALS_OMITTED_WARNING],
|
|
26
|
+
});
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
function registerGetProject(server, contextProvider) {
|
|
30
|
+
(0, shared_js_1.registerToolSafe)(server, 'get_project', {
|
|
31
|
+
title: 'Get project',
|
|
32
|
+
description: 'Get project metadata by UUID (no warehouse/dbt credentials or contact overrides)',
|
|
33
|
+
inputSchema: { projectUuid: (0, schema_fields_js_1.projectUuidField)() },
|
|
34
|
+
annotations: shared_js_1.READ_ONLY_DEFAULT,
|
|
35
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async ({ projectUuid }) => {
|
|
36
|
+
const project = await c.v1.projects.getProject(projectUuid);
|
|
37
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
38
|
+
data: (0, redaction_js_1.toProjectSummary)(project),
|
|
39
|
+
warnings: [redaction_js_1.CREDENTIALS_OMITTED_WARNING],
|
|
40
|
+
});
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const project_pin_js_1 = require("../../governance/project-pin.js");
|
|
5
|
+
const redaction_js_1 = require("../lib/redaction.js");
|
|
6
|
+
const projects_js_1 = require("./projects.js");
|
|
7
|
+
const PINNED = '550e8400-e29b-41d4-a716-446655440000';
|
|
8
|
+
const OTHER = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
|
|
9
|
+
function mockContext(listProjects, getProject) {
|
|
10
|
+
return {
|
|
11
|
+
getContext: async () => ({
|
|
12
|
+
lightdashClient: {
|
|
13
|
+
v1: { projects: { listProjects, getProject } },
|
|
14
|
+
},
|
|
15
|
+
auth: { mode: 'none' },
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
(0, vitest_1.describe)('registerListProjects', () => {
|
|
20
|
+
(0, vitest_1.afterEach)(() => {
|
|
21
|
+
vitest_1.vi.restoreAllMocks();
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.it)('returns only the pinned project summary when X-Lightdash-Project ALS is set', async () => {
|
|
24
|
+
const pinnedProject = {
|
|
25
|
+
projectUuid: PINNED,
|
|
26
|
+
name: 'Pinned',
|
|
27
|
+
type: 'DEFAULT',
|
|
28
|
+
warehouseConnection: { type: 'bigquery', password: 'secret' },
|
|
29
|
+
dbtConnection: { type: 'github', personal_access_token: 'ghp_x' },
|
|
30
|
+
schedulerFailureContactOverride: 'ops@example.com',
|
|
31
|
+
};
|
|
32
|
+
const listProjects = vitest_1.vi.fn();
|
|
33
|
+
const getProject = vitest_1.vi.fn().mockResolvedValue(pinnedProject);
|
|
34
|
+
const mockServer = { registerTool: vitest_1.vi.fn() };
|
|
35
|
+
(0, projects_js_1.registerListProjects)(mockServer, mockContext(listProjects, getProject));
|
|
36
|
+
const [, , handler] = mockServer.registerTool.mock.calls[0];
|
|
37
|
+
await (0, project_pin_js_1.runWithProjectPinAsync)(PINNED, async () => {
|
|
38
|
+
const result = await handler({});
|
|
39
|
+
(0, vitest_1.expect)(result.isError).toBeUndefined();
|
|
40
|
+
const body = JSON.parse(result.content[0].text);
|
|
41
|
+
(0, vitest_1.expect)(body.data).toEqual([
|
|
42
|
+
{
|
|
43
|
+
projectUuid: PINNED,
|
|
44
|
+
name: 'Pinned',
|
|
45
|
+
type: 'DEFAULT',
|
|
46
|
+
warehouseType: 'bigquery',
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
(0, vitest_1.expect)(body.warnings).toEqual([redaction_js_1.CREDENTIALS_OMITTED_WARNING]);
|
|
50
|
+
(0, vitest_1.expect)(JSON.stringify(body)).not.toContain('secret');
|
|
51
|
+
(0, vitest_1.expect)(JSON.stringify(body)).not.toContain('ghp_x');
|
|
52
|
+
(0, vitest_1.expect)(getProject).toHaveBeenCalledWith(PINNED);
|
|
53
|
+
(0, vitest_1.expect)(listProjects).not.toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.it)('lists project summaries when no pin is set', async () => {
|
|
57
|
+
const all = [
|
|
58
|
+
{ projectUuid: PINNED, name: 'A', type: 'DEFAULT', warehouseType: 'snowflake' },
|
|
59
|
+
{ projectUuid: OTHER, name: 'B', type: 'DEFAULT', warehouseType: 'bigquery' },
|
|
60
|
+
];
|
|
61
|
+
const listProjects = vitest_1.vi.fn().mockResolvedValue(all);
|
|
62
|
+
const getProject = vitest_1.vi.fn();
|
|
63
|
+
const mockServer = { registerTool: vitest_1.vi.fn() };
|
|
64
|
+
(0, projects_js_1.registerListProjects)(mockServer, mockContext(listProjects, getProject));
|
|
65
|
+
const [, , handler] = mockServer.registerTool.mock.calls[0];
|
|
66
|
+
const result = await handler({});
|
|
67
|
+
(0, vitest_1.expect)(result.isError).toBeUndefined();
|
|
68
|
+
const body = JSON.parse(result.content[0].text);
|
|
69
|
+
(0, vitest_1.expect)(body.data).toEqual([
|
|
70
|
+
{
|
|
71
|
+
projectUuid: PINNED,
|
|
72
|
+
name: 'A',
|
|
73
|
+
type: 'DEFAULT',
|
|
74
|
+
warehouseType: 'snowflake',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
projectUuid: OTHER,
|
|
78
|
+
name: 'B',
|
|
79
|
+
type: 'DEFAULT',
|
|
80
|
+
warehouseType: 'bigquery',
|
|
81
|
+
},
|
|
82
|
+
]);
|
|
83
|
+
(0, vitest_1.expect)(body.warnings).toEqual([redaction_js_1.CREDENTIALS_OMITTED_WARNING]);
|
|
84
|
+
(0, vitest_1.expect)(listProjects).toHaveBeenCalled();
|
|
85
|
+
(0, vitest_1.expect)(getProject).not.toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.describe)('registerGetProject', () => {
|
|
89
|
+
(0, vitest_1.afterEach)(() => {
|
|
90
|
+
vitest_1.vi.restoreAllMocks();
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.it)('returns metadata summary without connection secrets', async () => {
|
|
93
|
+
const getProject = vitest_1.vi.fn().mockResolvedValue({
|
|
94
|
+
projectUuid: PINNED,
|
|
95
|
+
name: 'Pinned',
|
|
96
|
+
type: 'DEFAULT',
|
|
97
|
+
organizationUuid: 'org-1',
|
|
98
|
+
warehouseConnection: { type: 'postgres', password: 'db-pass' },
|
|
99
|
+
dbtConnection: { type: 'github', personal_access_token: 'token' },
|
|
100
|
+
schedulerFailureContactOverride: 'alert@example.com',
|
|
101
|
+
});
|
|
102
|
+
const listProjects = vitest_1.vi.fn();
|
|
103
|
+
const mockServer = { registerTool: vitest_1.vi.fn() };
|
|
104
|
+
(0, projects_js_1.registerGetProject)(mockServer, mockContext(listProjects, getProject));
|
|
105
|
+
const [, , handler] = mockServer.registerTool.mock.calls[0];
|
|
106
|
+
const result = await handler({ projectUuid: PINNED });
|
|
107
|
+
const body = JSON.parse(result.content[0].text);
|
|
108
|
+
(0, vitest_1.expect)(body.data.projectUuid).toBe(PINNED);
|
|
109
|
+
(0, vitest_1.expect)(body.data.name).toBe('Pinned');
|
|
110
|
+
(0, vitest_1.expect)(body.data.warehouseType).toBe('postgres');
|
|
111
|
+
(0, vitest_1.expect)(body.warnings).toEqual([redaction_js_1.CREDENTIALS_OMITTED_WARNING]);
|
|
112
|
+
(0, vitest_1.expect)(body.data).not.toHaveProperty('warehouseConnection');
|
|
113
|
+
(0, vitest_1.expect)(body.data).not.toHaveProperty('dbtConnection');
|
|
114
|
+
(0, vitest_1.expect)(JSON.stringify(body)).not.toContain('db-pass');
|
|
115
|
+
(0, vitest_1.expect)(JSON.stringify(body)).not.toContain('token');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduler inventory tools with destination redaction.
|
|
3
|
+
*/
|
|
4
|
+
import type { McpContextProvider } from '../../server/request-context.js';
|
|
5
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
+
export declare function registerListProjectSchedulers(server: McpServer, contextProvider: McpContextProvider): void;
|
|
7
|
+
export declare function registerGetScheduler(server: McpServer, contextProvider: McpContextProvider): void;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scheduler inventory tools with destination redaction.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerListProjectSchedulers = registerListProjectSchedulers;
|
|
7
|
+
exports.registerGetScheduler = registerGetScheduler;
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const project_pin_js_1 = require("../../governance/project-pin.js");
|
|
10
|
+
const api_shape_js_1 = require("../lib/api-shape.js");
|
|
11
|
+
const contracts_js_1 = require("../lib/contracts.js");
|
|
12
|
+
const redaction_js_1 = require("../lib/redaction.js");
|
|
13
|
+
const register_org_audit_js_1 = require("../lib/register-org-audit.js");
|
|
14
|
+
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
15
|
+
const binding_js_1 = require("../organization/binding.js");
|
|
16
|
+
const shared_js_1 = require("../shared.js");
|
|
17
|
+
const SCHEDULER_MEMBERSHIP_PAGE_BUDGET = 10;
|
|
18
|
+
/** Confirm schedulerUuid appears in the project's scheduler list (when response omits projectUuid). */
|
|
19
|
+
async function schedulerBelongsToProject(client, projectUuid, schedulerUuid) {
|
|
20
|
+
for (let page = 1; page <= SCHEDULER_MEMBERSHIP_PAGE_BUDGET; page += 1) {
|
|
21
|
+
const result = await client.v1.schedulers.listSchedulers(projectUuid, {
|
|
22
|
+
page,
|
|
23
|
+
pageSize: 100,
|
|
24
|
+
});
|
|
25
|
+
const { data, pagination } = (0, api_shape_js_1.asPaginated)(result);
|
|
26
|
+
if (data.some((row) => { var _a, _b; return String((_b = (_a = row.schedulerUuid) !== null && _a !== void 0 ? _a : row.uuid) !== null && _b !== void 0 ? _b : '') === schedulerUuid; })) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if ((0, contracts_js_1.isPageComplete)(data.length, pagination === null || pagination === void 0 ? void 0 : pagination.totalResults, pagination === null || pagination === void 0 ? void 0 : pagination.totalPageCount, page)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
function registerListProjectSchedulers(server, contextProvider) {
|
|
36
|
+
(0, register_org_audit_js_1.registerOrgAuditTool)(server, 'list_project_schedulers', {
|
|
37
|
+
title: 'List project schedulers',
|
|
38
|
+
description: 'List scheduled deliveries for a project (destinations redacted by default; never executes)',
|
|
39
|
+
inputSchema: {
|
|
40
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)(),
|
|
41
|
+
search: zod_1.z.string().optional(),
|
|
42
|
+
formats: zod_1.z.string().optional(),
|
|
43
|
+
revealDestinations: zod_1.z.boolean().optional(),
|
|
44
|
+
allowedEmailDomains: (0, schema_fields_js_1.allowedEmailDomainsField)(),
|
|
45
|
+
page: zod_1.z.number().int().positive().optional(),
|
|
46
|
+
pageSize: zod_1.z.number().int().positive().optional(),
|
|
47
|
+
includeLatestRun: zod_1.z.boolean().optional(),
|
|
48
|
+
},
|
|
49
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const session = await (0, binding_js_1.resolveSessionOrganization)(c);
|
|
52
|
+
const result = await c.v1.schedulers.listSchedulers(args.projectUuid, {
|
|
53
|
+
searchQuery: args.search,
|
|
54
|
+
formats: args.formats,
|
|
55
|
+
page: args.page,
|
|
56
|
+
pageSize: args.pageSize,
|
|
57
|
+
includeLatestRun: (_a = args.includeLatestRun) !== null && _a !== void 0 ? _a : true,
|
|
58
|
+
});
|
|
59
|
+
const { data: rows, pagination } = (0, api_shape_js_1.asPaginated)(result);
|
|
60
|
+
const reveal = args.revealDestinations === true;
|
|
61
|
+
const data = rows.map((row) => (0, redaction_js_1.normalizeScheduler)(row, reveal, args.allowedEmailDomains));
|
|
62
|
+
const complete = (0, contracts_js_1.isPageComplete)(data.length, pagination === null || pagination === void 0 ? void 0 : pagination.totalResults, pagination === null || pagination === void 0 ? void 0 : pagination.totalPageCount, (_b = args.page) !== null && _b !== void 0 ? _b : pagination === null || pagination === void 0 ? void 0 : pagination.page);
|
|
63
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
64
|
+
data,
|
|
65
|
+
pagination: {
|
|
66
|
+
returned: data.length,
|
|
67
|
+
totalResults: pagination === null || pagination === void 0 ? void 0 : pagination.totalResults,
|
|
68
|
+
complete,
|
|
69
|
+
},
|
|
70
|
+
coverage: Object.assign(Object.assign({}, (0, contracts_js_1.emptyCoverage)(session.organizationUuid, (0, project_pin_js_1.getPinnedProjectUuid)())), { projectUuids: [args.projectUuid], complete, apiResolutions: [
|
|
71
|
+
{
|
|
72
|
+
capability: 'project_schedulers',
|
|
73
|
+
selectedVersion: 'v1',
|
|
74
|
+
method: 'GET',
|
|
75
|
+
pathTemplate: '/api/v1/schedulers/{projectUuid}/list',
|
|
76
|
+
reason: 'v2_preferred',
|
|
77
|
+
},
|
|
78
|
+
] }),
|
|
79
|
+
warnings: (0, redaction_js_1.destinationRedactionWarnings)(reveal),
|
|
80
|
+
});
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
function registerGetScheduler(server, contextProvider) {
|
|
84
|
+
(0, register_org_audit_js_1.registerOrgAuditTool)(server, 'get_scheduler', {
|
|
85
|
+
title: 'Get scheduler',
|
|
86
|
+
description: 'Get one scheduler by UUID within a project (destinations redacted by default; never executes)',
|
|
87
|
+
inputSchema: {
|
|
88
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)(),
|
|
89
|
+
schedulerUuid: zod_1.z.string(),
|
|
90
|
+
revealDestinations: zod_1.z.boolean().optional(),
|
|
91
|
+
allowedEmailDomains: (0, schema_fields_js_1.allowedEmailDomainsField)(),
|
|
92
|
+
},
|
|
93
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
94
|
+
const session = await (0, binding_js_1.resolveSessionOrganization)(c);
|
|
95
|
+
const pinned = (0, project_pin_js_1.getPinnedProjectUuid)();
|
|
96
|
+
const raw = (0, api_shape_js_1.asRecord)(await c.v1.schedulers.getScheduler(args.schedulerUuid));
|
|
97
|
+
const schedulerProject = typeof raw.projectUuid === 'string' ? raw.projectUuid : undefined;
|
|
98
|
+
if (schedulerProject) {
|
|
99
|
+
if (schedulerProject !== args.projectUuid) {
|
|
100
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
101
|
+
error: `Scheduler ${args.schedulerUuid} belongs to project ${schedulerProject}, not ${args.projectUuid}`,
|
|
102
|
+
isError: true,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (!(await schedulerBelongsToProject(c, args.projectUuid, args.schedulerUuid))) {
|
|
107
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
108
|
+
error: `Scheduler ${args.schedulerUuid} was not found in project ${args.projectUuid}`,
|
|
109
|
+
isError: true,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const reveal = args.revealDestinations === true;
|
|
113
|
+
return (0, shared_js_1.jsonToolResult)(Object.assign(Object.assign({}, (0, redaction_js_1.normalizeScheduler)(raw, reveal, args.allowedEmailDomains)), { coverage: Object.assign(Object.assign({}, (0, contracts_js_1.emptyCoverage)(session.organizationUuid, pinned)), { projectUuids: [args.projectUuid] }), warnings: (0, redaction_js_1.destinationRedactionWarnings)(reveal) }));
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared MCP tool registry: short id → register(server, ctx).
|
|
3
|
+
* Wire names are always `lightdash_` + id via registerToolSafe.
|
|
4
|
+
*/
|
|
5
|
+
import { registerGetOrgMember, registerGetOrgProfile, registerListOrgGroups, registerListOrgMembers, registerListOrgProjects } from './organization/inventory.js';
|
|
6
|
+
import { registerGetCustomRole, registerListCustomRoles, registerListOrgRoleAssignments, registerListProjectDirectAccess, registerListProjectRoles } from './organization/roles.js';
|
|
7
|
+
import { registerGetDashboardMeta, registerGetProjectUserActivity, registerListContent, registerListValidationResults } from './project/content.js';
|
|
8
|
+
import { registerGetProject, registerListProjects } from './project/projects.js';
|
|
9
|
+
import { registerGetScheduler, registerListProjectSchedulers } from './project/schedulers.js';
|
|
10
|
+
import { registerGetExplore, registerGetFieldLineage, registerListDimensions, registerListExplores } from './semantic/explores.js';
|
|
11
|
+
import { registerGetMetric, registerListMetrics } from './semantic/metrics.js';
|
|
12
|
+
import { registerCompileQuery } from './semantic/query.js';
|
|
13
|
+
import { registerListSpaceAccess, registerResolveEffectiveAccess } from './space/access.js';
|
|
14
|
+
import type { McpContextProvider } from '../server/request-context.js';
|
|
15
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
16
|
+
export type ToolRegistration = {
|
|
17
|
+
register: (server: McpServer, contextProvider: McpContextProvider) => void;
|
|
18
|
+
};
|
|
19
|
+
export declare const toolRegistry: {
|
|
20
|
+
readonly compile_query: {
|
|
21
|
+
readonly register: typeof registerCompileQuery;
|
|
22
|
+
};
|
|
23
|
+
readonly get_explore: {
|
|
24
|
+
readonly register: typeof registerGetExplore;
|
|
25
|
+
};
|
|
26
|
+
readonly get_field_lineage: {
|
|
27
|
+
readonly register: typeof registerGetFieldLineage;
|
|
28
|
+
};
|
|
29
|
+
readonly get_metric: {
|
|
30
|
+
readonly register: typeof registerGetMetric;
|
|
31
|
+
};
|
|
32
|
+
readonly get_project: {
|
|
33
|
+
readonly register: typeof registerGetProject;
|
|
34
|
+
};
|
|
35
|
+
readonly list_dimensions: {
|
|
36
|
+
readonly register: typeof registerListDimensions;
|
|
37
|
+
};
|
|
38
|
+
readonly list_explores: {
|
|
39
|
+
readonly register: typeof registerListExplores;
|
|
40
|
+
};
|
|
41
|
+
readonly list_metrics: {
|
|
42
|
+
readonly register: typeof registerListMetrics;
|
|
43
|
+
};
|
|
44
|
+
readonly list_projects: {
|
|
45
|
+
readonly register: typeof registerListProjects;
|
|
46
|
+
};
|
|
47
|
+
readonly get_org_profile: {
|
|
48
|
+
readonly register: typeof registerGetOrgProfile;
|
|
49
|
+
};
|
|
50
|
+
readonly list_org_members: {
|
|
51
|
+
readonly register: typeof registerListOrgMembers;
|
|
52
|
+
};
|
|
53
|
+
readonly get_org_member: {
|
|
54
|
+
readonly register: typeof registerGetOrgMember;
|
|
55
|
+
};
|
|
56
|
+
readonly list_org_groups: {
|
|
57
|
+
readonly register: typeof registerListOrgGroups;
|
|
58
|
+
};
|
|
59
|
+
readonly list_org_projects: {
|
|
60
|
+
readonly register: typeof registerListOrgProjects;
|
|
61
|
+
};
|
|
62
|
+
readonly list_org_role_assignments: {
|
|
63
|
+
readonly register: typeof registerListOrgRoleAssignments;
|
|
64
|
+
};
|
|
65
|
+
readonly list_custom_roles: {
|
|
66
|
+
readonly register: typeof registerListCustomRoles;
|
|
67
|
+
};
|
|
68
|
+
readonly get_custom_role: {
|
|
69
|
+
readonly register: typeof registerGetCustomRole;
|
|
70
|
+
};
|
|
71
|
+
readonly list_project_roles: {
|
|
72
|
+
readonly register: typeof registerListProjectRoles;
|
|
73
|
+
};
|
|
74
|
+
readonly list_project_direct_access: {
|
|
75
|
+
readonly register: typeof registerListProjectDirectAccess;
|
|
76
|
+
};
|
|
77
|
+
readonly list_space_access: {
|
|
78
|
+
readonly register: typeof registerListSpaceAccess;
|
|
79
|
+
};
|
|
80
|
+
readonly resolve_effective_access: {
|
|
81
|
+
readonly register: typeof registerResolveEffectiveAccess;
|
|
82
|
+
};
|
|
83
|
+
readonly list_content: {
|
|
84
|
+
readonly register: typeof registerListContent;
|
|
85
|
+
};
|
|
86
|
+
readonly get_dashboard_meta: {
|
|
87
|
+
readonly register: typeof registerGetDashboardMeta;
|
|
88
|
+
};
|
|
89
|
+
readonly list_validation_results: {
|
|
90
|
+
readonly register: typeof registerListValidationResults;
|
|
91
|
+
};
|
|
92
|
+
readonly get_project_user_activity: {
|
|
93
|
+
readonly register: typeof registerGetProjectUserActivity;
|
|
94
|
+
};
|
|
95
|
+
readonly list_project_schedulers: {
|
|
96
|
+
readonly register: typeof registerListProjectSchedulers;
|
|
97
|
+
};
|
|
98
|
+
readonly get_scheduler: {
|
|
99
|
+
readonly register: typeof registerGetScheduler;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export type ToolId = keyof typeof toolRegistry;
|
|
103
|
+
/** Register a subset of tools by id (persona allowlist). */
|
|
104
|
+
export declare function registerToolsByIds(server: McpServer, contextProvider: McpContextProvider, ids: readonly ToolId[]): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared MCP tool registry: short id → register(server, ctx).
|
|
4
|
+
* Wire names are always `lightdash_` + id via registerToolSafe.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.toolRegistry = void 0;
|
|
8
|
+
exports.registerToolsByIds = registerToolsByIds;
|
|
9
|
+
const inventory_js_1 = require("./organization/inventory.js");
|
|
10
|
+
const roles_js_1 = require("./organization/roles.js");
|
|
11
|
+
const content_js_1 = require("./project/content.js");
|
|
12
|
+
const projects_js_1 = require("./project/projects.js");
|
|
13
|
+
const schedulers_js_1 = require("./project/schedulers.js");
|
|
14
|
+
const explores_js_1 = require("./semantic/explores.js");
|
|
15
|
+
const metrics_js_1 = require("./semantic/metrics.js");
|
|
16
|
+
const query_js_1 = require("./semantic/query.js");
|
|
17
|
+
const access_js_1 = require("./space/access.js");
|
|
18
|
+
exports.toolRegistry = {
|
|
19
|
+
// semantic-layer
|
|
20
|
+
compile_query: { register: query_js_1.registerCompileQuery },
|
|
21
|
+
get_explore: { register: explores_js_1.registerGetExplore },
|
|
22
|
+
get_field_lineage: { register: explores_js_1.registerGetFieldLineage },
|
|
23
|
+
get_metric: { register: metrics_js_1.registerGetMetric },
|
|
24
|
+
get_project: { register: projects_js_1.registerGetProject },
|
|
25
|
+
list_dimensions: { register: explores_js_1.registerListDimensions },
|
|
26
|
+
list_explores: { register: explores_js_1.registerListExplores },
|
|
27
|
+
list_metrics: { register: metrics_js_1.registerListMetrics },
|
|
28
|
+
list_projects: { register: projects_js_1.registerListProjects },
|
|
29
|
+
// organization inventory / access / content / delivery (shared; persona allowlists select)
|
|
30
|
+
get_org_profile: { register: inventory_js_1.registerGetOrgProfile },
|
|
31
|
+
list_org_members: { register: inventory_js_1.registerListOrgMembers },
|
|
32
|
+
get_org_member: { register: inventory_js_1.registerGetOrgMember },
|
|
33
|
+
list_org_groups: { register: inventory_js_1.registerListOrgGroups },
|
|
34
|
+
list_org_projects: { register: inventory_js_1.registerListOrgProjects },
|
|
35
|
+
list_org_role_assignments: { register: roles_js_1.registerListOrgRoleAssignments },
|
|
36
|
+
list_custom_roles: { register: roles_js_1.registerListCustomRoles },
|
|
37
|
+
get_custom_role: { register: roles_js_1.registerGetCustomRole },
|
|
38
|
+
list_project_roles: { register: roles_js_1.registerListProjectRoles },
|
|
39
|
+
list_project_direct_access: { register: roles_js_1.registerListProjectDirectAccess },
|
|
40
|
+
list_space_access: { register: access_js_1.registerListSpaceAccess },
|
|
41
|
+
resolve_effective_access: { register: access_js_1.registerResolveEffectiveAccess },
|
|
42
|
+
list_content: { register: content_js_1.registerListContent },
|
|
43
|
+
get_dashboard_meta: { register: content_js_1.registerGetDashboardMeta },
|
|
44
|
+
list_validation_results: { register: content_js_1.registerListValidationResults },
|
|
45
|
+
get_project_user_activity: { register: content_js_1.registerGetProjectUserActivity },
|
|
46
|
+
list_project_schedulers: { register: schedulers_js_1.registerListProjectSchedulers },
|
|
47
|
+
get_scheduler: { register: schedulers_js_1.registerGetScheduler },
|
|
48
|
+
};
|
|
49
|
+
/** Register a subset of tools by id (persona allowlist). */
|
|
50
|
+
function registerToolsByIds(server, contextProvider, ids) {
|
|
51
|
+
for (const id of ids) {
|
|
52
|
+
// eslint-disable-next-line security/detect-object-injection -- ToolId union keys only
|
|
53
|
+
const entry = exports.toolRegistry[id];
|
|
54
|
+
if (!entry) {
|
|
55
|
+
throw new Error(`Unknown MCP tool id: ${String(id)}`);
|
|
56
|
+
}
|
|
57
|
+
entry.register(server, contextProvider);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side helpers for explore tool responses (summary / filter / fieldId).
|
|
3
|
+
*/
|
|
4
|
+
import type { ApiExploreResults, ApiExploresResults } from '@lightdash-tools/common';
|
|
5
|
+
export type ExploreSummary = {
|
|
6
|
+
name: string;
|
|
7
|
+
label: string;
|
|
8
|
+
tags?: string[];
|
|
9
|
+
databaseName?: string;
|
|
10
|
+
schemaName?: string;
|
|
11
|
+
errors?: unknown[];
|
|
12
|
+
warnings?: unknown[];
|
|
13
|
+
};
|
|
14
|
+
export type DimensionSummary = {
|
|
15
|
+
name: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
table: string;
|
|
18
|
+
type?: string;
|
|
19
|
+
fieldId: string;
|
|
20
|
+
};
|
|
21
|
+
type DimensionLike = {
|
|
22
|
+
name: string;
|
|
23
|
+
table: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
};
|
|
27
|
+
/** Map a summary explore to a compact MCP payload (drops fat explore fields). */
|
|
28
|
+
export declare function toExploreSummary(explore: ApiExploresResults[number]): ExploreSummary;
|
|
29
|
+
/**
|
|
30
|
+
* Summarize, filter, and limit explores.
|
|
31
|
+
* Default limit: 50 when search is set, otherwise 100.
|
|
32
|
+
*/
|
|
33
|
+
export declare function summarizeExplores(explores: ApiExploresResults, options?: {
|
|
34
|
+
search?: string;
|
|
35
|
+
limit?: number;
|
|
36
|
+
}): ExploreSummary[];
|
|
37
|
+
/**
|
|
38
|
+
* Flatten all dimensions from an explore and return the authoritative base table name.
|
|
39
|
+
* Prefer `explore.baseTable` over `explore.name` / exploreId — they can differ.
|
|
40
|
+
*/
|
|
41
|
+
export declare function flattenExploreDimensions(explore: ApiExploreResults): {
|
|
42
|
+
baseTable: string;
|
|
43
|
+
dimensions: DimensionLike[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Compact dimensions with compile_query fieldId `{table}_{name}`.
|
|
47
|
+
* When `baseTable` is set, keep only rows whose `table` equals that id (joined tables dropped).
|
|
48
|
+
*/
|
|
49
|
+
export declare function summarizeDimensions(dimensions: readonly DimensionLike[], options?: {
|
|
50
|
+
baseTable?: string;
|
|
51
|
+
}): DimensionSummary[];
|
|
52
|
+
/** True when compiled SQL has an empty projection (SELECT … FROM with no columns). */
|
|
53
|
+
export declare function isEmptySelectSql(sql: string): boolean;
|
|
54
|
+
/** Extract SQL text from a compile_query API payload. */
|
|
55
|
+
export declare function extractCompiledSql(result: unknown): string | undefined;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Client-side helpers for explore tool responses (summary / filter / fieldId).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toExploreSummary = toExploreSummary;
|
|
7
|
+
exports.summarizeExplores = summarizeExplores;
|
|
8
|
+
exports.flattenExploreDimensions = flattenExploreDimensions;
|
|
9
|
+
exports.summarizeDimensions = summarizeDimensions;
|
|
10
|
+
exports.isEmptySelectSql = isEmptySelectSql;
|
|
11
|
+
exports.extractCompiledSql = extractCompiledSql;
|
|
12
|
+
/** Map a summary explore to a compact MCP payload (drops fat explore fields). */
|
|
13
|
+
function toExploreSummary(explore) {
|
|
14
|
+
const summary = {
|
|
15
|
+
name: explore.name,
|
|
16
|
+
label: explore.label,
|
|
17
|
+
};
|
|
18
|
+
if (Array.isArray(explore.tags)) {
|
|
19
|
+
summary.tags = explore.tags;
|
|
20
|
+
}
|
|
21
|
+
if ('databaseName' in explore && typeof explore.databaseName === 'string') {
|
|
22
|
+
summary.databaseName = explore.databaseName;
|
|
23
|
+
}
|
|
24
|
+
if ('schemaName' in explore && typeof explore.schemaName === 'string') {
|
|
25
|
+
summary.schemaName = explore.schemaName;
|
|
26
|
+
}
|
|
27
|
+
if ('errors' in explore && Array.isArray(explore.errors)) {
|
|
28
|
+
summary.errors = explore.errors;
|
|
29
|
+
}
|
|
30
|
+
if ('warnings' in explore && Array.isArray(explore.warnings)) {
|
|
31
|
+
summary.warnings = explore.warnings;
|
|
32
|
+
}
|
|
33
|
+
return summary;
|
|
34
|
+
}
|
|
35
|
+
function matchesSearch(summary, query) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
if (summary.name.toLowerCase().includes(query))
|
|
38
|
+
return true;
|
|
39
|
+
if (summary.label.toLowerCase().includes(query))
|
|
40
|
+
return true;
|
|
41
|
+
if ((_a = summary.databaseName) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(query))
|
|
42
|
+
return true;
|
|
43
|
+
if ((_b = summary.schemaName) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(query))
|
|
44
|
+
return true;
|
|
45
|
+
return ((_c = summary.tags) !== null && _c !== void 0 ? _c : []).some((tag) => tag.toLowerCase().includes(query));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Summarize, filter, and limit explores.
|
|
49
|
+
* Default limit: 50 when search is set, otherwise 100.
|
|
50
|
+
*/
|
|
51
|
+
function summarizeExplores(explores, options) {
|
|
52
|
+
var _a, _b, _c;
|
|
53
|
+
const query = (_b = (_a = options === null || options === void 0 ? void 0 : options.search) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase()) !== null && _b !== void 0 ? _b : '';
|
|
54
|
+
const defaultLimit = query.length > 0 ? 50 : 100;
|
|
55
|
+
const limit = Math.max(0, (_c = options === null || options === void 0 ? void 0 : options.limit) !== null && _c !== void 0 ? _c : defaultLimit);
|
|
56
|
+
const summaries = [];
|
|
57
|
+
for (const explore of explores) {
|
|
58
|
+
if (summaries.length >= limit)
|
|
59
|
+
break;
|
|
60
|
+
const summary = toExploreSummary(explore);
|
|
61
|
+
if (query && !matchesSearch(summary, query))
|
|
62
|
+
continue;
|
|
63
|
+
summaries.push(summary);
|
|
64
|
+
}
|
|
65
|
+
return summaries;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Flatten all dimensions from an explore and return the authoritative base table name.
|
|
69
|
+
* Prefer `explore.baseTable` over `explore.name` / exploreId — they can differ.
|
|
70
|
+
*/
|
|
71
|
+
function flattenExploreDimensions(explore) {
|
|
72
|
+
const dimensions = Object.values(explore.tables).flatMap((table) => Object.values(table.dimensions));
|
|
73
|
+
return { baseTable: explore.baseTable, dimensions };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Compact dimensions with compile_query fieldId `{table}_{name}`.
|
|
77
|
+
* When `baseTable` is set, keep only rows whose `table` equals that id (joined tables dropped).
|
|
78
|
+
*/
|
|
79
|
+
function summarizeDimensions(dimensions, options) {
|
|
80
|
+
const baseTable = options === null || options === void 0 ? void 0 : options.baseTable;
|
|
81
|
+
const summaries = [];
|
|
82
|
+
for (const dim of dimensions) {
|
|
83
|
+
if (baseTable !== undefined && dim.table !== baseTable)
|
|
84
|
+
continue;
|
|
85
|
+
const summary = {
|
|
86
|
+
name: dim.name,
|
|
87
|
+
table: dim.table,
|
|
88
|
+
fieldId: `${dim.table}_${dim.name}`,
|
|
89
|
+
};
|
|
90
|
+
if (typeof dim.label === 'string')
|
|
91
|
+
summary.label = dim.label;
|
|
92
|
+
if (typeof dim.type === 'string')
|
|
93
|
+
summary.type = dim.type;
|
|
94
|
+
summaries.push(summary);
|
|
95
|
+
}
|
|
96
|
+
return summaries;
|
|
97
|
+
}
|
|
98
|
+
/** True when compiled SQL has an empty projection (SELECT … FROM with no columns). */
|
|
99
|
+
function isEmptySelectSql(sql) {
|
|
100
|
+
const normalized = sql.replace(/\s+/g, ' ').trim();
|
|
101
|
+
return /SELECT FROM\b/i.test(normalized);
|
|
102
|
+
}
|
|
103
|
+
/** Extract SQL text from a compile_query API payload. */
|
|
104
|
+
function extractCompiledSql(result) {
|
|
105
|
+
if (typeof result === 'string')
|
|
106
|
+
return result;
|
|
107
|
+
if (result && typeof result === 'object') {
|
|
108
|
+
const record = result;
|
|
109
|
+
if (typeof record.query === 'string')
|
|
110
|
+
return record.query;
|
|
111
|
+
if (typeof record.compiledQuery === 'string')
|
|
112
|
+
return record.compiledQuery;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|