@lightdash-tools/common 0.8.0 → 0.11.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 (49) hide show
  1. package/dist/audit.d.ts +29 -8
  2. package/dist/audit.js +53 -9
  3. package/dist/audit.test.js +51 -24
  4. package/dist/env.d.ts +1 -1
  5. package/dist/env.js +2 -2
  6. package/dist/operations/ai-agents.js +108 -40
  7. package/dist/operations/cli-content.js +6 -8
  8. package/dist/operations/client-coverage.d.ts +7 -0
  9. package/dist/operations/client-coverage.js +13 -4
  10. package/dist/operations/content-developer.js +19 -5
  11. package/dist/operations/content-governance.js +1 -1
  12. package/dist/operations/content-reader.js +19 -4
  13. package/dist/operations/data-analyst.d.ts +5 -0
  14. package/dist/operations/data-analyst.js +23 -0
  15. package/dist/operations/index.d.ts +2 -1
  16. package/dist/operations/index.js +4 -1
  17. package/dist/operations/organization-audit.js +1 -1
  18. package/dist/operations/registry.d.ts +5 -5
  19. package/dist/operations/registry.js +35 -9
  20. package/dist/operations/registry.test.js +23 -45
  21. package/dist/operations/semantic-layer.js +8 -7
  22. package/dist/operations/types.d.ts +10 -6
  23. package/dist/operations/types.js +23 -14
  24. package/dist/operations/types.test.js +14 -5
  25. package/dist/operations/users.js +3 -5
  26. package/dist/safety.d.ts +3 -2
  27. package/dist/safety.js +11 -3
  28. package/dist/safety.test.js +29 -6
  29. package/package.json +1 -1
  30. package/src/audit.test.ts +70 -30
  31. package/src/audit.ts +78 -11
  32. package/src/env.ts +1 -1
  33. package/src/operations/ai-agents.ts +113 -41
  34. package/src/operations/cli-content.ts +7 -10
  35. package/src/operations/client-coverage.ts +14 -5
  36. package/src/operations/content-developer.ts +23 -7
  37. package/src/operations/content-governance.ts +3 -3
  38. package/src/operations/content-reader.ts +23 -7
  39. package/src/operations/data-analyst.ts +27 -0
  40. package/src/operations/index.ts +3 -1
  41. package/src/operations/organization-audit.ts +2 -2
  42. package/src/operations/registry.test.ts +31 -52
  43. package/src/operations/registry.ts +42 -12
  44. package/src/operations/semantic-layer.ts +9 -8
  45. package/src/operations/types.test.ts +34 -6
  46. package/src/operations/types.ts +41 -31
  47. package/src/operations/users.ts +4 -7
  48. package/src/safety.test.ts +32 -6
  49. package/src/safety.ts +15 -4
@@ -3,20 +3,20 @@
3
3
  * Hybrid authoring surface: chart as-code upsert, dashboard REST create/update,
4
4
  * MCP-composed tile layout, and bulk content move into existing spaces.
5
5
  * Space create/update are client-only (spaces managed out-of-band, e.g. Terraform).
6
- * Preview -> validate -> apply is enforced by the persona policy layer, not here.
6
+ * Preview -> validate -> apply is enforced by the profile policy layer, not here.
7
7
  */
8
8
  import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT, WRITE_NONDESTRUCTIVE } from '../safety';
9
9
 
10
10
  import { defineOperation } from './types';
11
11
 
12
- import type { CapabilityProfile, OperationDescriptor, SafetyImpact } from './types';
12
+ import type { ProfileId, OperationDescriptor, SafetyImpact } from './types';
13
13
 
14
- const PROFILE_CONTENT_DEVELOPER: CapabilityProfile = 'content-developer';
14
+ const PROFILE_CONTENT_DEVELOPER: ProfileId = 'content-developer';
15
15
  const API_V1 = '/api/v1';
16
16
  const API_V2 = '/api/v2';
17
17
  const WRITE_NONDESTRUCTIVE_IMPACT: SafetyImpact = 'write-nondestructive';
18
18
  const PREVIEW_DIFF_SUMMARY =
19
- 'Compute an in-memory diff and issue a single-use previewId (no upstream preview API)';
19
+ 'Compute an in-memory diff and issue an HMAC-signed previewToken (no upstream preview API)';
20
20
  const TILE_READ_SUMMARY = 'Read the current tile array (no per-tile REST route exists)';
21
21
 
22
22
  const op_preview_chart_changes = defineOperation({
@@ -77,7 +77,7 @@ const op_preview_dashboard_changes = defineOperation({
77
77
  const op_preview_content_move = defineOperation({
78
78
  id: 'content-developer.preview.content-move',
79
79
  summary:
80
- 'Preview a bulk content move into an existing space (MCP ledger only; issues a single-use previewId)',
80
+ 'Preview a bulk content move into an existing space (issues an HMAC-signed previewToken)',
81
81
  http: { method: 'GET', path: `${API_V2}/content` },
82
82
  authorization: { safetyImpact: 'read' },
83
83
  sensitivity: 'none',
@@ -96,6 +96,21 @@ const op_preview_content_move = defineOperation({
96
96
  profiles: [PROFILE_CONTENT_DEVELOPER],
97
97
  });
98
98
 
99
+ const op_get_chart_as_code = defineOperation({
100
+ id: 'content-developer.charts.get-as-code',
101
+ summary:
102
+ 'Get a chart in as-code (upsert) shape for cloning chartConfig/metricQuery before dashboard-scoped create',
103
+ http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/code/charts` },
104
+ authorization: { safetyImpact: 'read' },
105
+ sensitivity: 'none',
106
+ mcp: {
107
+ toolName: 'get_chart_as_code',
108
+ annotations: READ_ONLY_DEFAULT,
109
+ taskSupport: { exposed: true, taskEligible: false },
110
+ },
111
+ profiles: [PROFILE_CONTENT_DEVELOPER],
112
+ });
113
+
99
114
  const op_validate_chart = defineOperation({
100
115
  id: 'content-developer.charts.validate',
101
116
  summary: "Validate a saved chart's fields against its underlying explore",
@@ -431,7 +446,7 @@ const op_create_space = defineOperation({
431
446
  sensitivity: 'none',
432
447
  agentExposure: 'client-only',
433
448
  bannedMcpToolName: 'create_space',
434
- profiles: [PROFILE_CONTENT_DEVELOPER],
449
+ profiles: [],
435
450
  });
436
451
 
437
452
  const op_update_space = defineOperation({
@@ -443,7 +458,7 @@ const op_update_space = defineOperation({
443
458
  sensitivity: 'none',
444
459
  agentExposure: 'client-only',
445
460
  bannedMcpToolName: 'update_space',
446
- profiles: [PROFILE_CONTENT_DEVELOPER],
461
+ profiles: [],
447
462
  });
448
463
 
449
464
  const op_move_content = defineOperation({
@@ -464,6 +479,7 @@ export const CONTENT_DEVELOPER_OPERATIONS: readonly OperationDescriptor[] = [
464
479
  op_preview_chart_changes,
465
480
  op_preview_dashboard_changes,
466
481
  op_preview_content_move,
482
+ op_get_chart_as_code,
467
483
  op_validate_chart,
468
484
  op_validate_dashboard,
469
485
  op_confirm_preview,
@@ -8,11 +8,11 @@ import { READ_ONLY_DEFAULT, WRITE_DESTRUCTIVE } from '../safety';
8
8
 
9
9
  import { defineOperation } from './types';
10
10
 
11
- import type { CapabilityProfile, OperationDescriptor, SafetyImpact } from './types';
11
+ import type { ProfileId, OperationDescriptor, SafetyImpact } from './types';
12
12
 
13
13
  const IMPACT_READ: SafetyImpact = 'read';
14
14
  const IMPACT_WRITE_DESTRUCTIVE: SafetyImpact = 'write-destructive';
15
- const PROFILE_CONTENT_GOVERNANCE: CapabilityProfile = 'content-governance';
15
+ const PROFILE_CONTENT_GOVERNANCE: ProfileId = 'content-governance';
16
16
 
17
17
  const API_V1 = '/api/v1';
18
18
  const API_V2 = '/api/v2';
@@ -98,7 +98,7 @@ const op_permanent_purge = defineOperation({
98
98
  sensitivity: 'none',
99
99
  agentExposure: 'client-only',
100
100
  bannedMcpToolName: 'permanent_delete_content',
101
- profiles: [PROFILE_CONTENT_GOVERNANCE],
101
+ profiles: [],
102
102
  });
103
103
 
104
104
  export const CONTENT_GOVERNANCE_OPERATIONS: readonly OperationDescriptor[] = [
@@ -5,10 +5,11 @@ import { READ_ONLY_DEFAULT, READ_ONLY_TRANSIENT } from '../safety';
5
5
 
6
6
  import { defineOperation } from './types';
7
7
 
8
- import type { CapabilityProfile, OperationDescriptor } from './types';
8
+ import type { ProfileId, OperationDescriptor } from './types';
9
9
 
10
- const PROFILE_CONTENT_READER: CapabilityProfile = 'content-reader';
11
- const PROFILE_CONTENT_DEVELOPER: CapabilityProfile = 'content-developer';
10
+ const PROFILE_CONTENT_READER: ProfileId = 'content-reader';
11
+ const PROFILE_CONTENT_DEVELOPER: ProfileId = 'content-developer';
12
+ const PROFILE_DATA_ANALYST: ProfileId = 'data-analyst';
12
13
 
13
14
  const op_search_content = defineOperation({
14
15
  id: 'content-reader.content.search',
@@ -139,6 +140,20 @@ const op_run_chart = defineOperation({
139
140
  profiles: [PROFILE_CONTENT_READER],
140
141
  });
141
142
 
143
+ const op_export_chart_image = defineOperation({
144
+ id: 'content-reader.charts.export-image',
145
+ summary: 'Export a saved chart as a PNG image snapshot',
146
+ http: { method: 'POST', path: '/api/v1/saved/{chartUuid}/export' },
147
+ authorization: { safetyImpact: 'read' },
148
+ sensitivity: 'none',
149
+ mcp: {
150
+ toolName: 'export_chart_image',
151
+ annotations: READ_ONLY_TRANSIENT,
152
+ taskSupport: { exposed: true, taskEligible: false },
153
+ },
154
+ profiles: [PROFILE_CONTENT_READER],
155
+ });
156
+
142
157
  const op_run_dashboard_tile = defineOperation({
143
158
  id: 'content-reader.dashboards.run-tile',
144
159
  summary: 'Execute a dashboard tile with bounded results',
@@ -155,7 +170,7 @@ const op_run_dashboard_tile = defineOperation({
155
170
 
156
171
  const op_get_query_result = defineOperation({
157
172
  id: 'content-reader.query.result.get',
158
- summary: 'Get or poll a session-owned query result',
173
+ summary: 'Get or poll a query result by queryUuid',
159
174
  http: { method: 'GET', path: '/api/v2/projects/{projectUuid}/query/{queryUuid}' },
160
175
  authorization: { safetyImpact: 'read' },
161
176
  sensitivity: 'none',
@@ -164,12 +179,12 @@ const op_get_query_result = defineOperation({
164
179
  annotations: READ_ONLY_DEFAULT,
165
180
  taskSupport: { exposed: true, taskEligible: false },
166
181
  },
167
- profiles: [PROFILE_CONTENT_READER],
182
+ profiles: [PROFILE_CONTENT_READER, PROFILE_DATA_ANALYST],
168
183
  });
169
184
 
170
185
  const op_cancel_query = defineOperation({
171
186
  id: 'content-reader.query.cancel',
172
- summary: 'Cancel a running session-owned query',
187
+ summary: 'Cancel a running query by queryUuid',
173
188
  http: { method: 'POST', path: '/api/v2/projects/{projectUuid}/query/{queryUuid}/cancel' },
174
189
  authorization: { safetyImpact: 'read' },
175
190
  sensitivity: 'none',
@@ -178,7 +193,7 @@ const op_cancel_query = defineOperation({
178
193
  annotations: READ_ONLY_TRANSIENT,
179
194
  taskSupport: { exposed: true, taskEligible: false },
180
195
  },
181
- profiles: [PROFILE_CONTENT_READER],
196
+ profiles: [PROFILE_CONTENT_READER, PROFILE_DATA_ANALYST],
182
197
  });
183
198
 
184
199
  export const CONTENT_READER_OPERATIONS: readonly OperationDescriptor[] = [
@@ -191,6 +206,7 @@ export const CONTENT_READER_OPERATIONS: readonly OperationDescriptor[] = [
191
206
  op_get_project_parameters,
192
207
  op_explain_content,
193
208
  op_run_chart,
209
+ op_export_chart_image,
194
210
  op_run_dashboard_tile,
195
211
  op_get_query_result,
196
212
  op_cancel_query,
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Data-analyst operations in the shared operation catalog (ADR-0020).
3
+ */
4
+
5
+ import { READ_ONLY_TRANSIENT } from '../safety';
6
+
7
+ import { defineOperation } from './types';
8
+
9
+ import type { ProfileId, OperationDescriptor } from './types';
10
+
11
+ const PROFILE_DATA_ANALYST: ProfileId = 'data-analyst';
12
+
13
+ const op_run_metric_query = defineOperation({
14
+ id: 'data-analyst.query.metric-query.run',
15
+ summary: 'Execute an ad-hoc explore metric query with bounded async results',
16
+ http: { method: 'POST', path: '/api/v2/projects/{projectUuid}/query/metric-query' },
17
+ authorization: { safetyImpact: 'read' },
18
+ sensitivity: 'none',
19
+ mcp: {
20
+ toolName: 'run_metric_query',
21
+ annotations: READ_ONLY_TRANSIENT,
22
+ taskSupport: { exposed: true, taskEligible: false },
23
+ },
24
+ profiles: [PROFILE_DATA_ANALYST],
25
+ });
26
+
27
+ export const DATA_ANALYST_OPERATIONS: readonly OperationDescriptor[] = [op_run_metric_query];
@@ -1,7 +1,8 @@
1
1
  export {
2
2
  defineOperation,
3
+ PROFILE_IDS,
3
4
  type AgentExposure,
4
- type CapabilityProfile,
5
+ type ProfileId,
5
6
  type HttpMethod,
6
7
  type McpTaskSupport,
7
8
  type OperationAuthorization,
@@ -20,6 +21,7 @@ export { CLI_CONTENT_OPERATIONS } from './cli-content';
20
21
  export { CONTENT_DEVELOPER_OPERATIONS } from './content-developer';
21
22
  export { CONTENT_GOVERNANCE_OPERATIONS } from './content-governance';
22
23
  export { CONTENT_READER_OPERATIONS } from './content-reader';
24
+ export { DATA_ANALYST_OPERATIONS } from './data-analyst';
23
25
  export { ORGANIZATION_AUDIT_OPERATIONS } from './organization-audit';
24
26
  export { SEMANTIC_LAYER_OPERATIONS } from './semantic-layer';
25
27
  export { USER_OPERATIONS } from './users';
@@ -5,9 +5,9 @@ import { READ_ONLY_DEFAULT } from '../safety';
5
5
 
6
6
  import { defineOperation } from './types';
7
7
 
8
- import type { CapabilityProfile, OperationDescriptor } from './types';
8
+ import type { ProfileId, OperationDescriptor } from './types';
9
9
 
10
- const PROFILE_ORG_AUDIT: CapabilityProfile = 'org-audit-readonly';
10
+ const PROFILE_ORG_AUDIT: ProfileId = 'organization-audit';
11
11
 
12
12
  const op_get_org_profile = defineOperation({
13
13
  id: 'org-audit.org.profile.get',
@@ -5,13 +5,19 @@ import { CLI_CONTENT_OPERATIONS } from './cli-content';
5
5
  import { CONTENT_DEVELOPER_OPERATIONS } from './content-developer';
6
6
  import { CONTENT_GOVERNANCE_OPERATIONS } from './content-governance';
7
7
  import { CONTENT_READER_OPERATIONS } from './content-reader';
8
+ import { DATA_ANALYST_OPERATIONS } from './data-analyst';
8
9
  import { ORGANIZATION_AUDIT_OPERATIONS } from './organization-audit';
9
- import { getOperation, getOperationsByProfile, listOperations } from './registry';
10
+ import {
11
+ getOperation,
12
+ getOperationsByProfile,
13
+ listMcpToolNamesByProfile,
14
+ listOperations,
15
+ } from './registry';
10
16
  import { SEMANTIC_LAYER_OPERATIONS } from './semantic-layer';
11
- import { defineOperation } from './types';
17
+ import { defineOperation, PROFILE_IDS } from './types';
12
18
  import { USER_OPERATIONS } from './users';
13
19
 
14
- import type { CapabilityProfile, OperationDescriptor } from './types';
20
+ import type { OperationDescriptor, ProfileId } from './types';
15
21
 
16
22
  const P0_OPERATION_IDS = [
17
23
  'ai-agents.admin.agents.list',
@@ -34,12 +40,7 @@ const P0_OPERATION_IDS = [
34
40
  'ai-agents.project.evaluations.runs.list',
35
41
  ] as const;
36
42
 
37
- const ALL_PROFILES: CapabilityProfile[] = [
38
- 'core-lifecycle',
39
- 'evaluations',
40
- 'conversations',
41
- 'discovery-readonly',
42
- ];
43
+ const ALL_PROFILES: ProfileId[] = [...PROFILE_IDS];
43
44
 
44
45
  function requiredFields(operation: OperationDescriptor): string[] {
45
46
  const agentExposure = operation.agentExposure ?? 'agent';
@@ -84,6 +85,7 @@ describe('operation registry', () => {
84
85
  CONTENT_READER_OPERATIONS.length +
85
86
  CONTENT_DEVELOPER_OPERATIONS.length +
86
87
  CONTENT_GOVERNANCE_OPERATIONS.length +
88
+ DATA_ANALYST_OPERATIONS.length +
87
89
  CLI_CONTENT_OPERATIONS.length,
88
90
  );
89
91
  });
@@ -96,7 +98,12 @@ describe('operation registry', () => {
96
98
  if (operation.agentExposure === 'agent') {
97
99
  expect(operation.mcp !== undefined || operation.cli !== undefined).toBe(true);
98
100
  }
99
- expect(operation.profiles.length).toBeGreaterThan(0);
101
+ const mcpExposed = operation.mcp?.taskSupport.exposed === true;
102
+ if (mcpExposed) {
103
+ expect(operation.profiles.length).toBeGreaterThan(0);
104
+ } else {
105
+ expect(operation.profiles).toEqual([]);
106
+ }
100
107
  expect(
101
108
  operation.http.path.startsWith('/api/v1/') || operation.http.path.startsWith('/api/v2/'),
102
109
  ).toBe(true);
@@ -119,7 +126,7 @@ describe('operation registry', () => {
119
126
  }
120
127
  });
121
128
 
122
- it('exposes profile filters for all capability profiles', () => {
129
+ it('exposes profile filters for all serving profiles', () => {
123
130
  for (const profile of ALL_PROFILES) {
124
131
  const operations = getOperationsByProfile(profile);
125
132
  expect(operations.length).toBeGreaterThan(0);
@@ -129,23 +136,20 @@ describe('operation registry', () => {
129
136
  }
130
137
  });
131
138
 
132
- it('maps agent CRUD to core-lifecycle profile', () => {
133
- const crudIds = [
134
- 'ai-agents.project.agents.list',
135
- 'ai-agents.project.agents.get',
136
- 'ai-agents.project.agents.create',
137
- 'ai-agents.project.agents.update',
138
- 'ai-agents.project.agents.delete',
139
- ];
140
- for (const id of crudIds) {
141
- const operation = getOperation(id);
142
- expect(operation?.profiles).toContain('core-lifecycle');
139
+ it('listMcpToolNamesByProfile matches exposed ops per profile', () => {
140
+ for (const profile of ALL_PROFILES) {
141
+ const toolNames = listMcpToolNamesByProfile(profile);
142
+ const exposedOps = getOperationsByProfile(profile).filter(
143
+ (operation) => operation.mcp?.taskSupport.exposed === true,
144
+ );
145
+ expect(toolNames).toHaveLength(exposedOps.length);
146
+ expect(new Set(toolNames).size).toBe(toolNames.length);
143
147
  }
144
148
  });
145
149
 
146
- it('maps thread start and continue to conversations profile', () => {
147
- expect(getOperation('ai-agents.project.threads.start')?.profiles).toContain('conversations');
148
- expect(getOperation('ai-agents.project.threads.continue')?.profiles).toContain('conversations');
150
+ it('maps exposed ai-agent-ops tools to ai-agent-ops profile only', () => {
151
+ expect(getOperation('ai-agents.project.agents.list')?.profiles).toEqual(['ai-agent-ops']);
152
+ expect(getOperation('ai-agents.project.agents.create')?.profiles).toEqual([]);
149
153
  });
150
154
 
151
155
  it('documents multi-step workflow for thread start', () => {
@@ -166,27 +170,10 @@ describe('operation registry', () => {
166
170
  expect(operation?.workflow?.[1]?.path).toContain('/generate');
167
171
  });
168
172
 
169
- it('maps evaluation lifecycle operations to evaluations profile', () => {
170
- const evalIds = [
171
- 'ai-agents.project.evaluations.create',
172
- 'ai-agents.project.evaluations.append',
173
- 'ai-agents.project.evaluations.run',
174
- 'ai-agents.project.evaluations.runs.list',
175
- ];
176
- for (const id of evalIds) {
177
- expect(getOperation(id)?.profiles).toContain('evaluations');
178
- }
179
- });
180
-
181
173
  it('returns undefined for unknown operation id', () => {
182
174
  expect(getOperation('ai-agents.unknown.operation')).toBeUndefined();
183
175
  });
184
176
 
185
- it('filters operations by profile with empty result for unknown profile usage', () => {
186
- const ops = getOperationsByProfile('core-lifecycle');
187
- expect(ops.every((op) => op.profiles.includes('core-lifecycle'))).toBe(true);
188
- });
189
-
190
177
  it('registers users.members.delete as client-only', () => {
191
178
  const operation = getOperation('users.members.delete');
192
179
  expect(operation?.agentExposure).toBe('client-only');
@@ -194,6 +181,7 @@ describe('operation registry', () => {
194
181
  expect(operation?.cli).toBeUndefined();
195
182
  expect(operation?.bannedMcpToolName).toBe('delete_member');
196
183
  expect(operation?.http.path).toBe('/api/v1/org/user/{userUuid}');
184
+ expect(operation?.profiles).toEqual([]);
197
185
  });
198
186
 
199
187
  it('excludes client-only operations from profile discovery catalogs', () => {
@@ -203,15 +191,6 @@ describe('operation registry', () => {
203
191
  }
204
192
  }
205
193
  expect(getOperation('users.members.delete')).toBeDefined();
206
- expect(
207
- getOperationsByProfile('discovery-readonly').some((op) => op.id === 'users.members.delete'),
208
- ).toBe(false);
209
- });
210
-
211
- it('keeps discovery-readonly profile operations read-only', () => {
212
- for (const operation of getOperationsByProfile('discovery-readonly')) {
213
- expect(operation.authorization.safetyImpact).toBe('read');
214
- }
215
194
  });
216
195
 
217
196
  it('never exposes client-only operations on MCP', () => {
@@ -243,7 +222,7 @@ describe('operation registry', () => {
243
222
  },
244
223
  cli: { commandPath: 'test' },
245
224
  agentExposure: 'agent',
246
- profiles: ['discovery-readonly'],
225
+ profiles: ['semantic-layer'],
247
226
  }),
248
227
  ).toThrow(/authorization\.safetyImpact/);
249
228
  });
@@ -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');