@lightdash-tools/common 0.9.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/audit.d.ts +3 -2
  2. package/dist/audit.js +1 -1
  3. package/dist/audit.test.js +4 -4
  4. package/dist/operations/ai-agents.js +26 -30
  5. package/dist/operations/cli-content.js +6 -8
  6. package/dist/operations/client-coverage.d.ts +1 -0
  7. package/dist/operations/client-coverage.js +2 -0
  8. package/dist/operations/content-developer.js +3 -3
  9. package/dist/operations/content-governance.js +1 -1
  10. package/dist/operations/content-reader.js +3 -2
  11. package/dist/operations/data-analyst.d.ts +5 -0
  12. package/dist/operations/data-analyst.js +23 -0
  13. package/dist/operations/index.d.ts +2 -1
  14. package/dist/operations/index.js +4 -1
  15. package/dist/operations/organization-audit.js +1 -1
  16. package/dist/operations/registry.d.ts +5 -5
  17. package/dist/operations/registry.js +35 -9
  18. package/dist/operations/registry.test.js +23 -46
  19. package/dist/operations/semantic-layer.js +8 -7
  20. package/dist/operations/types.d.ts +10 -6
  21. package/dist/operations/types.js +22 -14
  22. package/dist/operations/types.test.js +14 -5
  23. package/dist/operations/users.js +3 -5
  24. package/package.json +1 -1
  25. package/src/audit.test.ts +4 -4
  26. package/src/audit.ts +5 -3
  27. package/src/operations/ai-agents.ts +28 -32
  28. package/src/operations/cli-content.ts +7 -10
  29. package/src/operations/client-coverage.ts +3 -0
  30. package/src/operations/content-developer.ts +5 -5
  31. package/src/operations/content-governance.ts +3 -3
  32. package/src/operations/content-reader.ts +6 -5
  33. package/src/operations/data-analyst.ts +27 -0
  34. package/src/operations/index.ts +3 -1
  35. package/src/operations/organization-audit.ts +2 -2
  36. package/src/operations/registry.test.ts +31 -53
  37. package/src/operations/registry.ts +42 -12
  38. package/src/operations/semantic-layer.ts +9 -8
  39. package/src/operations/types.test.ts +34 -6
  40. package/src/operations/types.ts +41 -33
  41. package/src/operations/users.ts +4 -7
@@ -7,11 +7,13 @@ import { CLI_CONTENT_OPERATIONS } from './cli-content';
7
7
  import { CONTENT_DEVELOPER_OPERATIONS } from './content-developer';
8
8
  import { CONTENT_GOVERNANCE_OPERATIONS } from './content-governance';
9
9
  import { CONTENT_READER_OPERATIONS } from './content-reader';
10
+ import { DATA_ANALYST_OPERATIONS } from './data-analyst';
10
11
  import { ORGANIZATION_AUDIT_OPERATIONS } from './organization-audit';
11
12
  import { SEMANTIC_LAYER_OPERATIONS } from './semantic-layer';
13
+ import { PROFILE_IDS } from './types';
12
14
  import { USER_OPERATIONS } from './users';
13
15
 
14
- import type { CapabilityProfile, OperationDescriptor } from './types';
16
+ import type { OperationDescriptor, ProfileId } from './types';
15
17
 
16
18
  const AGENT_EXPOSURE_CLIENT_ONLY = 'client-only' as const;
17
19
 
@@ -23,6 +25,7 @@ const ALL_OPERATIONS: readonly OperationDescriptor[] = [
23
25
  ...CONTENT_READER_OPERATIONS,
24
26
  ...CONTENT_DEVELOPER_OPERATIONS,
25
27
  ...CONTENT_GOVERNANCE_OPERATIONS,
28
+ ...DATA_ANALYST_OPERATIONS,
26
29
  ...CLI_CONTENT_OPERATIONS,
27
30
  ];
28
31
 
@@ -83,6 +86,35 @@ const BANNED_MCP_TOOL_NAMES: readonly string[] = ALL_OPERATIONS.filter(
83
86
  }
84
87
  return banned;
85
88
  });
89
+
90
+ /** Precomputed tool names per serving profile (ADR-0006 registration source). */
91
+ const MCP_TOOL_NAMES_BY_PROFILE: ReadonlyMap<ProfileId, readonly string[]> = (() => {
92
+ const map = new Map<ProfileId, string[]>(PROFILE_IDS.map((id) => [id, []]));
93
+ for (const operation of ALL_OPERATIONS) {
94
+ if (operation.agentExposure === AGENT_EXPOSURE_CLIENT_ONLY) {
95
+ continue;
96
+ }
97
+ const mcp = operation.mcp;
98
+ if (mcp === undefined || mcp.taskSupport.exposed !== true) {
99
+ continue;
100
+ }
101
+ for (const profile of operation.profiles) {
102
+ const names = map.get(profile);
103
+ if (names === undefined) {
104
+ throw new Error(
105
+ `Unknown profile '${profile}' on operation '${operation.id}' while indexing MCP tools`,
106
+ );
107
+ }
108
+ names.push(mcp.toolName);
109
+ }
110
+ }
111
+ for (const [id, names] of map) {
112
+ Object.freeze(names);
113
+ map.set(id, names);
114
+ }
115
+ return map;
116
+ })();
117
+
86
118
  /** Returns a registered operation by id, or undefined when not found. */
87
119
  export function getOperation(id: string): OperationDescriptor | undefined {
88
120
  return operationsById.get(id);
@@ -98,8 +130,8 @@ export function listOperations(): readonly OperationDescriptor[] {
98
130
  return ALL_OPERATIONS;
99
131
  }
100
132
 
101
- /** Returns agent-surface operations that include the given capability profile. */
102
- export function getOperationsByProfile(profile: CapabilityProfile): readonly OperationDescriptor[] {
133
+ /** Returns agent-surface operations that include the given MCP serving profile. */
134
+ export function getOperationsByProfile(profile: ProfileId): readonly OperationDescriptor[] {
103
135
  return ALL_OPERATIONS.filter(
104
136
  (operation) =>
105
137
  operation.agentExposure !== 'client-only' && operation.profiles.includes(profile),
@@ -116,13 +148,11 @@ export function listBannedMcpToolNames(): readonly string[] {
116
148
  return BANNED_MCP_TOOL_NAMES;
117
149
  }
118
150
 
119
- /** Exposed MCP tool names for a capability profile (persona allowlist source). */
120
- export function listMcpToolNamesByProfile(profile: CapabilityProfile): readonly string[] {
121
- return getOperationsByProfile(profile).flatMap((operation) => {
122
- const mcp = operation.mcp;
123
- if (mcp === undefined || mcp.taskSupport.exposed !== true) {
124
- return [];
125
- }
126
- return [mcp.toolName];
127
- });
151
+ /** Exposed MCP tool names for a serving profile (registration source, ADR-0006). */
152
+ export function listMcpToolNamesByProfile(profile: ProfileId): readonly string[] {
153
+ const names = MCP_TOOL_NAMES_BY_PROFILE.get(profile);
154
+ if (names === undefined) {
155
+ throw new Error(`Unknown profile id: ${profile}`);
156
+ }
157
+ return names;
128
158
  }
@@ -6,9 +6,10 @@ import { READ_ONLY_DEFAULT } from '../safety';
6
6
 
7
7
  import { defineOperation } from './types';
8
8
 
9
- import type { CapabilityProfile, OperationDescriptor } from './types';
9
+ import type { ProfileId, OperationDescriptor } from './types';
10
10
 
11
- const PROFILE_SEMANTIC: CapabilityProfile = 'semantic-discovery';
11
+ const PROFILE_SEMANTIC: ProfileId = 'semantic-layer';
12
+ const PROFILE_DATA_ANALYST: ProfileId = 'data-analyst';
12
13
  const API_V1 = '/api/v1';
13
14
 
14
15
  const listProjects = defineOperation({
@@ -38,7 +39,7 @@ const getProject = defineOperation({
38
39
  taskSupport: { exposed: true, taskEligible: false },
39
40
  },
40
41
  cli: { commandPath: 'projects get' },
41
- profiles: [PROFILE_SEMANTIC, 'content-reader', 'content-developer'],
42
+ profiles: [PROFILE_SEMANTIC, 'content-reader', 'content-developer', PROFILE_DATA_ANALYST],
42
43
  });
43
44
 
44
45
  const listExplores = defineOperation({
@@ -53,7 +54,7 @@ const listExplores = defineOperation({
53
54
  taskSupport: { exposed: true, taskEligible: false },
54
55
  },
55
56
  cli: { commandPath: 'projects explores list' },
56
- profiles: [PROFILE_SEMANTIC],
57
+ profiles: [PROFILE_SEMANTIC, PROFILE_DATA_ANALYST],
57
58
  });
58
59
 
59
60
  const getExplore = defineOperation({
@@ -68,7 +69,7 @@ const getExplore = defineOperation({
68
69
  taskSupport: { exposed: true, taskEligible: false },
69
70
  },
70
71
  cli: { commandPath: 'projects explores get' },
71
- profiles: [PROFILE_SEMANTIC],
72
+ profiles: [PROFILE_SEMANTIC, PROFILE_DATA_ANALYST],
72
73
  });
73
74
 
74
75
  const listDimensions = defineOperation({
@@ -83,7 +84,7 @@ const listDimensions = defineOperation({
83
84
  taskSupport: { exposed: true, taskEligible: false },
84
85
  },
85
86
  cli: { commandPath: 'projects explores dimensions' },
86
- profiles: [PROFILE_SEMANTIC],
87
+ profiles: [PROFILE_SEMANTIC, PROFILE_DATA_ANALYST],
87
88
  });
88
89
 
89
90
  const getFieldLineage = defineOperation({
@@ -113,7 +114,7 @@ const listMetrics = defineOperation({
113
114
  taskSupport: { exposed: true, taskEligible: false },
114
115
  },
115
116
  cli: { commandPath: 'metrics list' },
116
- profiles: [PROFILE_SEMANTIC],
117
+ profiles: [PROFILE_SEMANTIC, PROFILE_DATA_ANALYST],
117
118
  });
118
119
 
119
120
  const getMetric = defineOperation({
@@ -149,7 +150,7 @@ const compileQuery = defineOperation({
149
150
  taskSupport: { exposed: true, taskEligible: false },
150
151
  },
151
152
  cli: { commandPath: 'query compile' },
152
- profiles: [PROFILE_SEMANTIC],
153
+ profiles: [PROFILE_SEMANTIC, PROFILE_DATA_ANALYST],
153
154
  });
154
155
 
155
156
  /** Semantic-layer operations registered in the shared operation catalog. */
@@ -20,7 +20,7 @@ const baseDescriptor = {
20
20
  },
21
21
  cli: { commandPath: 'test op' },
22
22
  agentExposure: 'agent' as const,
23
- profiles: ['discovery-readonly' as const],
23
+ profiles: ['semantic-layer' as const],
24
24
  };
25
25
 
26
26
  describe('defineOperation', () => {
@@ -50,14 +50,14 @@ describe('defineOperation', () => {
50
50
  it('allows agent ops with cli only', () => {
51
51
  const { mcp: _mcp, ...rest } = baseDescriptor;
52
52
  void _mcp;
53
- expect(defineOperation(rest).mcp).toBeUndefined();
53
+ expect(defineOperation({ ...rest, profiles: [] }).mcp).toBeUndefined();
54
54
  });
55
55
 
56
56
  it('rejects agent ops with neither mcp nor cli', () => {
57
57
  const { mcp: _mcp, cli: _cli, ...rest } = baseDescriptor;
58
58
  void _mcp;
59
59
  void _cli;
60
- expect(() => defineOperation(rest)).toThrow(/require mcp and\/or cli/);
60
+ expect(() => defineOperation({ ...rest, profiles: [] })).toThrow(/require mcp and\/or cli/);
61
61
  });
62
62
 
63
63
  it('rejects empty id', () => {
@@ -68,9 +68,37 @@ describe('defineOperation', () => {
68
68
  expect(() =>
69
69
  defineOperation({
70
70
  ...baseDescriptor,
71
- profiles: ['unknown-profile' as 'discovery-readonly'],
71
+ profiles: ['unknown-profile' as 'semantic-layer'],
72
72
  }),
73
- ).toThrow(/unknown capability profile/);
73
+ ).toThrow(/unknown profile/);
74
+ });
75
+
76
+ it('rejects empty profiles when MCP-exposed', () => {
77
+ expect(() => defineOperation({ ...baseDescriptor, profiles: [] })).toThrow(
78
+ /at least one profile/,
79
+ );
80
+ });
81
+
82
+ it('rejects duplicate profiles', () => {
83
+ expect(() =>
84
+ defineOperation({
85
+ ...baseDescriptor,
86
+ profiles: ['semantic-layer', 'semantic-layer'],
87
+ }),
88
+ ).toThrow(/duplicate profiles/);
89
+ });
90
+
91
+ it('rejects non-empty profiles when not MCP-exposed', () => {
92
+ expect(() =>
93
+ defineOperation({
94
+ ...baseDescriptor,
95
+ mcp: {
96
+ ...baseDescriptor.mcp,
97
+ taskSupport: { exposed: false, taskEligible: false },
98
+ },
99
+ profiles: ['semantic-layer'],
100
+ }),
101
+ ).toThrow(/empty profiles/);
74
102
  });
75
103
 
76
104
  it('allows read operation with idempotentHint false (transient execution)', () => {
@@ -101,7 +129,7 @@ describe('defineOperation', () => {
101
129
  authorization: { safetyImpact: 'write-destructive' },
102
130
  agentExposure: 'client-only',
103
131
  bannedMcpToolName: 'delete_test',
104
- profiles: ['discovery-readonly'],
132
+ profiles: [],
105
133
  });
106
134
  expect(op.agentExposure).toBe('client-only');
107
135
  expect(op.bannedMcpToolName).toBe('delete_test');
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Shared typed operation catalog (ADR-0013).
2
+ * Shared typed operation catalog (ADR-0013 / ADR-0006).
3
3
  * Single source of truth for HTTP, CLI, and MCP exposure of Lightdash API operations.
4
4
  */
5
5
 
@@ -13,20 +13,19 @@ export type AgentExposure = 'agent' | 'client-only';
13
13
  /** HTTP verbs supported by registered operations. */
14
14
  export type HttpMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
15
15
 
16
- /**
17
- * Capability profiles group operations for selective exposure (CLI profiles, MCP subsets).
18
- */
19
- export type CapabilityProfile =
20
- | 'ai-agent-ops'
21
- | 'content-developer'
22
- | 'content-governance'
23
- | 'content-reader'
24
- | 'conversations'
25
- | 'core-lifecycle'
26
- | 'discovery-readonly'
27
- | 'evaluations'
28
- | 'org-audit-readonly'
29
- | 'semantic-discovery';
16
+ /** Runtime list of every MCP serving profile id (ADR-0006; fixed mounts / stdio). */
17
+ export const PROFILE_IDS = [
18
+ 'ai-agent-ops',
19
+ 'content-developer',
20
+ 'content-governance',
21
+ 'content-reader',
22
+ 'data-analyst',
23
+ 'organization-audit',
24
+ 'semantic-layer',
25
+ ] as const;
26
+
27
+ /** MCP serving profile ids aligned to fixed HTTP mounts / stdio subcommands (ADR-0006). */
28
+ export type ProfileId = (typeof PROFILE_IDS)[number];
30
29
 
31
30
  /**
32
31
  * MCP response sensitivity class (ADR-0011).
@@ -85,7 +84,11 @@ export type OperationDescriptor = {
85
84
  * Defaults to `none` when omitted from `defineOperation` input.
86
85
  */
87
86
  sensitivity: SensitivityClass;
88
- profiles: readonly CapabilityProfile[];
87
+ /**
88
+ * MCP mounts that expose this op when `mcp.taskSupport.exposed` is true (ADR-0006).
89
+ * Empty when the op is not MCP-exposed (CLI-only / reserved / client-only).
90
+ */
91
+ profiles: readonly ProfileId[];
89
92
  /** `agent` (default) = may appear on MCP and/or CLI; `client-only` = typed client only. */
90
93
  agentExposure: AgentExposure;
91
94
  /** Present when the operation is registered (or reserved) as an MCP tool. */
@@ -107,18 +110,7 @@ export type OperationDefinitionInput = Omit<
107
110
  sensitivity?: SensitivityClass;
108
111
  };
109
112
 
110
- const VALID_PROFILES = new Set<CapabilityProfile>([
111
- 'ai-agent-ops',
112
- 'content-developer',
113
- 'content-governance',
114
- 'content-reader',
115
- 'conversations',
116
- 'core-lifecycle',
117
- 'discovery-readonly',
118
- 'evaluations',
119
- 'org-audit-readonly',
120
- 'semantic-discovery',
121
- ]);
113
+ const VALID_PROFILES = new Set<ProfileId>(PROFILE_IDS);
122
114
 
123
115
  const VALID_SENSITIVITY = new Set<SensitivityClass>([
124
116
  'none',
@@ -158,15 +150,31 @@ function validateIdempotentHint(
158
150
  }
159
151
  }
160
152
 
161
- function validateProfiles(id: string, profiles: readonly CapabilityProfile[]): void {
162
- if (profiles.length === 0) {
163
- throw new Error(`Operation '${id}' must declare at least one capability profile`);
153
+ function validateProfiles(input: OperationDefinitionInput): void {
154
+ const { id, profiles, mcp } = input;
155
+ const mcpExposed = mcp?.taskSupport.exposed === true;
156
+
157
+ if (mcpExposed && profiles.length === 0) {
158
+ throw new Error(
159
+ `Operation '${id}' must declare at least one profile when mcp.taskSupport.exposed is true`,
160
+ );
161
+ }
162
+
163
+ if (new Set(profiles).size !== profiles.length) {
164
+ throw new Error(`Operation '${id}' has duplicate profiles: ${profiles.join(', ')}`);
164
165
  }
166
+
165
167
  for (const profile of profiles) {
166
168
  if (!VALID_PROFILES.has(profile)) {
167
- throw new Error(`Operation '${id}' has unknown capability profile '${profile}'`);
169
+ throw new Error(`Operation '${id}' has unknown profile '${profile}'`);
168
170
  }
169
171
  }
172
+
173
+ if (!mcpExposed && profiles.length > 0) {
174
+ throw new Error(
175
+ `Operation '${id}' must use empty profiles when not MCP-exposed (got ${profiles.join(', ')})`,
176
+ );
177
+ }
170
178
  }
171
179
 
172
180
  function validateClientOnlyOperation(input: OperationDefinitionInput): OperationDescriptor {
@@ -213,7 +221,7 @@ export function defineOperation(input: OperationDefinitionInput): OperationDescr
213
221
  throw new Error(`Operation '${input.id}' has unknown sensitivity '${String(sensitivity)}'`);
214
222
  }
215
223
 
216
- validateProfiles(input.id, input.profiles);
224
+ validateProfiles(input);
217
225
 
218
226
  const agentExposure = input.agentExposure ?? 'agent';
219
227
  if (agentExposure === 'client-only') {
@@ -6,10 +6,7 @@ import { READ_ONLY_DEFAULT } from '../safety';
6
6
 
7
7
  import { defineOperation } from './types';
8
8
 
9
- import type { CapabilityProfile, OperationDescriptor } from './types';
10
-
11
- const PROFILE_DISCOVERY: CapabilityProfile = 'discovery-readonly';
12
- const PROFILE_CORE_LIFECYCLE: CapabilityProfile = 'core-lifecycle';
9
+ import type { OperationDescriptor } from './types';
13
10
 
14
11
  const API_V1 = '/api/v1';
15
12
  const MEMBERS_PATH = `${API_V1}/org/users`;
@@ -28,7 +25,7 @@ const membersList = defineOperation({
28
25
  taskSupport: { exposed: false, taskEligible: false },
29
26
  },
30
27
  cli: { commandPath: 'users list' },
31
- profiles: [PROFILE_DISCOVERY],
28
+ profiles: [],
32
29
  });
33
30
 
34
31
  const membersGet = defineOperation({
@@ -43,7 +40,7 @@ const membersGet = defineOperation({
43
40
  taskSupport: { exposed: false, taskEligible: false },
44
41
  },
45
42
  cli: { commandPath: 'users get' },
46
- profiles: [PROFILE_DISCOVERY],
43
+ profiles: [],
47
44
  });
48
45
 
49
46
  const membersDelete = defineOperation({
@@ -54,7 +51,7 @@ const membersDelete = defineOperation({
54
51
  sensitivity: 'none',
55
52
  agentExposure: 'client-only',
56
53
  bannedMcpToolName: 'delete_member',
57
- profiles: [PROFILE_CORE_LIFECYCLE],
54
+ profiles: [],
58
55
  });
59
56
 
60
57
  /** Organization member operations registered in the shared operation catalog. */