@lightdash-tools/common 0.7.0 → 0.8.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/dist/argument-validation.js +20 -2
- package/dist/argument-validation.test.js +22 -0
- package/dist/audit.d.ts +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +6 -8
- package/dist/operations/agent-safe.d.ts +1 -3
- package/dist/operations/agent-safe.js +2 -9
- package/dist/operations/ai-agents.js +45 -29
- package/dist/operations/cli-content.d.ts +5 -0
- package/dist/operations/cli-content.js +71 -0
- package/dist/operations/client-coverage.d.ts +113 -0
- package/dist/operations/client-coverage.js +130 -0
- package/dist/operations/client-coverage.test.d.ts +1 -0
- package/dist/operations/client-coverage.test.js +22 -0
- package/dist/operations/content-developer.d.ts +2 -0
- package/dist/operations/content-developer.js +457 -0
- package/dist/operations/content-governance.d.ts +7 -0
- package/dist/operations/content-governance.js +98 -0
- package/dist/operations/content-reader.d.ts +2 -0
- package/dist/operations/content-reader.js +183 -0
- package/dist/operations/index.d.ts +10 -3
- package/dist/operations/index.js +20 -2
- package/dist/operations/organization-audit.d.ts +2 -0
- package/dist/operations/organization-audit.js +273 -0
- package/dist/operations/parity.test.js +12 -11
- package/dist/operations/registry.d.ts +9 -1
- package/dist/operations/registry.js +77 -2
- package/dist/operations/registry.test.js +38 -11
- package/dist/operations/semantic-layer.d.ts +6 -0
- package/dist/operations/semantic-layer.js +154 -0
- package/dist/operations/types.d.ts +29 -12
- package/dist/operations/types.js +63 -29
- package/dist/operations/types.test.js +33 -45
- package/dist/operations/users.d.ts +2 -2
- package/dist/operations/users.js +8 -10
- package/dist/safety.d.ts +5 -0
- package/dist/safety.js +11 -1
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +29 -0
- package/package.json +2 -1
- package/src/argument-validation.test.ts +31 -0
- package/src/argument-validation.ts +20 -2
- package/src/audit.ts +12 -1
- package/src/index.ts +5 -9
- package/src/operations/agent-safe.ts +2 -12
- package/src/operations/ai-agents.ts +46 -30
- package/src/operations/cli-content.ts +79 -0
- package/src/operations/client-coverage.test.ts +23 -0
- package/src/operations/client-coverage.ts +147 -0
- package/src/operations/content-developer.ts +485 -0
- package/src/operations/content-governance.ts +110 -0
- package/src/operations/content-reader.ts +197 -0
- package/src/operations/index.ts +25 -2
- package/src/operations/organization-audit.ts +293 -0
- package/src/operations/parity.test.ts +12 -14
- package/src/operations/registry.test.ts +40 -9
- package/src/operations/registry.ts +86 -2
- package/src/operations/semantic-layer.ts +166 -0
- package/src/operations/types.test.ts +38 -76
- package/src/operations/types.ts +110 -47
- package/src/operations/users.ts +9 -11
- package/src/safety.ts +11 -0
- package/src/types/index.ts +13 -0
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Central operation
|
|
2
|
+
* Central operation catalog — aggregates domain modules and exposes lookup helpers.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { AI_AGENT_OPERATIONS } from './ai-agents';
|
|
6
|
+
import { CLI_CONTENT_OPERATIONS } from './cli-content';
|
|
7
|
+
import { CONTENT_DEVELOPER_OPERATIONS } from './content-developer';
|
|
8
|
+
import { CONTENT_GOVERNANCE_OPERATIONS } from './content-governance';
|
|
9
|
+
import { CONTENT_READER_OPERATIONS } from './content-reader';
|
|
10
|
+
import { ORGANIZATION_AUDIT_OPERATIONS } from './organization-audit';
|
|
11
|
+
import { SEMANTIC_LAYER_OPERATIONS } from './semantic-layer';
|
|
6
12
|
import { USER_OPERATIONS } from './users';
|
|
7
13
|
|
|
8
14
|
import type { CapabilityProfile, OperationDescriptor } from './types';
|
|
9
15
|
|
|
10
|
-
const
|
|
16
|
+
const AGENT_EXPOSURE_CLIENT_ONLY = 'client-only' as const;
|
|
17
|
+
|
|
18
|
+
const ALL_OPERATIONS: readonly OperationDescriptor[] = [
|
|
19
|
+
...AI_AGENT_OPERATIONS,
|
|
20
|
+
...USER_OPERATIONS,
|
|
21
|
+
...SEMANTIC_LAYER_OPERATIONS,
|
|
22
|
+
...ORGANIZATION_AUDIT_OPERATIONS,
|
|
23
|
+
...CONTENT_READER_OPERATIONS,
|
|
24
|
+
...CONTENT_DEVELOPER_OPERATIONS,
|
|
25
|
+
...CONTENT_GOVERNANCE_OPERATIONS,
|
|
26
|
+
...CLI_CONTENT_OPERATIONS,
|
|
27
|
+
];
|
|
11
28
|
|
|
12
29
|
const operationsById = new Map<string, OperationDescriptor>(
|
|
13
30
|
ALL_OPERATIONS.map((operation) => [operation.id, operation]),
|
|
@@ -25,11 +42,57 @@ if (operationsById.size !== ALL_OPERATIONS.length) {
|
|
|
25
42
|
throw new Error(`Duplicate operation ids in registry: ${duplicates.join(', ')}`);
|
|
26
43
|
}
|
|
27
44
|
|
|
45
|
+
const operationsByMcpToolName = new Map<string, OperationDescriptor>();
|
|
46
|
+
for (const operation of ALL_OPERATIONS) {
|
|
47
|
+
if (operation.agentExposure === AGENT_EXPOSURE_CLIENT_ONLY || operation.mcp === undefined) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// Index only exposed tools so lookups match registerToolsByIds / schema honesty.
|
|
51
|
+
if (!operation.mcp.taskSupport.exposed) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const toolName = operation.mcp.toolName;
|
|
55
|
+
if (operationsByMcpToolName.has(toolName)) {
|
|
56
|
+
throw new Error(`Duplicate MCP toolName in operation catalog: ${toolName}`);
|
|
57
|
+
}
|
|
58
|
+
operationsByMcpToolName.set(toolName, operation);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const EXPOSED_MCP_TOOL_NAMES: readonly string[] = ALL_OPERATIONS.filter(
|
|
62
|
+
(operation) =>
|
|
63
|
+
operation.agentExposure === 'agent' &&
|
|
64
|
+
operation.mcp !== undefined &&
|
|
65
|
+
operation.mcp.taskSupport.exposed,
|
|
66
|
+
).map((operation) => {
|
|
67
|
+
const mcp = operation.mcp;
|
|
68
|
+
if (mcp === undefined) {
|
|
69
|
+
throw new Error(`Invariant: exposed filter retained operation without mcp (${operation.id})`);
|
|
70
|
+
}
|
|
71
|
+
return mcp.toolName;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const BANNED_MCP_TOOL_NAMES: readonly string[] = ALL_OPERATIONS.filter(
|
|
75
|
+
(operation) =>
|
|
76
|
+
operation.agentExposure === AGENT_EXPOSURE_CLIENT_ONLY &&
|
|
77
|
+
typeof operation.bannedMcpToolName === 'string' &&
|
|
78
|
+
operation.bannedMcpToolName.trim().length > 0,
|
|
79
|
+
).map((operation) => {
|
|
80
|
+
const banned = operation.bannedMcpToolName;
|
|
81
|
+
if (banned === undefined) {
|
|
82
|
+
throw new Error(`Invariant: banned filter retained operation without name (${operation.id})`);
|
|
83
|
+
}
|
|
84
|
+
return banned;
|
|
85
|
+
});
|
|
28
86
|
/** Returns a registered operation by id, or undefined when not found. */
|
|
29
87
|
export function getOperation(id: string): OperationDescriptor | undefined {
|
|
30
88
|
return operationsById.get(id);
|
|
31
89
|
}
|
|
32
90
|
|
|
91
|
+
/** Returns the agent operation registered for an MCP tool name (sans prefix), if any. */
|
|
92
|
+
export function getOperationByMcpToolName(toolName: string): OperationDescriptor | undefined {
|
|
93
|
+
return operationsByMcpToolName.get(toolName);
|
|
94
|
+
}
|
|
95
|
+
|
|
33
96
|
/** Returns every registered operation descriptor. */
|
|
34
97
|
export function listOperations(): readonly OperationDescriptor[] {
|
|
35
98
|
return ALL_OPERATIONS;
|
|
@@ -42,3 +105,24 @@ export function getOperationsByProfile(profile: CapabilityProfile): readonly Ope
|
|
|
42
105
|
operation.agentExposure !== 'client-only' && operation.profiles.includes(profile),
|
|
43
106
|
);
|
|
44
107
|
}
|
|
108
|
+
|
|
109
|
+
/** MCP tool names (sans prefix) with `mcp.taskSupport.exposed === true`. */
|
|
110
|
+
export function listExposedMcpToolNames(): readonly string[] {
|
|
111
|
+
return EXPOSED_MCP_TOOL_NAMES;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** MCP tool names that must never be registered (client-only denylist). */
|
|
115
|
+
export function listBannedMcpToolNames(): readonly string[] {
|
|
116
|
+
return BANNED_MCP_TOOL_NAMES;
|
|
117
|
+
}
|
|
118
|
+
|
|
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
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic-layer MCP/CLI operations in the shared operation catalog (ADR-0013).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { READ_ONLY_DEFAULT } from '../safety';
|
|
6
|
+
|
|
7
|
+
import { defineOperation } from './types';
|
|
8
|
+
|
|
9
|
+
import type { CapabilityProfile, OperationDescriptor } from './types';
|
|
10
|
+
|
|
11
|
+
const PROFILE_SEMANTIC: CapabilityProfile = 'semantic-discovery';
|
|
12
|
+
const API_V1 = '/api/v1';
|
|
13
|
+
|
|
14
|
+
const listProjects = defineOperation({
|
|
15
|
+
id: 'semantic.projects.list',
|
|
16
|
+
summary: 'List organization projects (or pinned project when HTTP pin is set)',
|
|
17
|
+
http: { method: 'GET', path: `${API_V1}/org/projects` },
|
|
18
|
+
authorization: { safetyImpact: 'read' },
|
|
19
|
+
sensitivity: 'secret.connection',
|
|
20
|
+
mcp: {
|
|
21
|
+
toolName: 'list_projects',
|
|
22
|
+
annotations: READ_ONLY_DEFAULT,
|
|
23
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
24
|
+
},
|
|
25
|
+
cli: { commandPath: 'projects list' },
|
|
26
|
+
profiles: [PROFILE_SEMANTIC],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const getProject = defineOperation({
|
|
30
|
+
id: 'semantic.projects.get',
|
|
31
|
+
summary: 'Get a project by UUID (connection secrets omitted on MCP)',
|
|
32
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}` },
|
|
33
|
+
authorization: { safetyImpact: 'read' },
|
|
34
|
+
sensitivity: 'secret.connection',
|
|
35
|
+
mcp: {
|
|
36
|
+
toolName: 'get_project',
|
|
37
|
+
annotations: READ_ONLY_DEFAULT,
|
|
38
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
39
|
+
},
|
|
40
|
+
cli: { commandPath: 'projects get' },
|
|
41
|
+
profiles: [PROFILE_SEMANTIC, 'content-reader', 'content-developer'],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const listExplores = defineOperation({
|
|
45
|
+
id: 'semantic.explores.list',
|
|
46
|
+
summary: 'List explores in a project',
|
|
47
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores` },
|
|
48
|
+
authorization: { safetyImpact: 'read' },
|
|
49
|
+
sensitivity: 'none',
|
|
50
|
+
mcp: {
|
|
51
|
+
toolName: 'list_explores',
|
|
52
|
+
annotations: READ_ONLY_DEFAULT,
|
|
53
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
54
|
+
},
|
|
55
|
+
cli: { commandPath: 'projects explores list' },
|
|
56
|
+
profiles: [PROFILE_SEMANTIC],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const getExplore = defineOperation({
|
|
60
|
+
id: 'semantic.explores.get',
|
|
61
|
+
summary: 'Get a full explore definition',
|
|
62
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
|
|
63
|
+
authorization: { safetyImpact: 'read' },
|
|
64
|
+
sensitivity: 'none',
|
|
65
|
+
mcp: {
|
|
66
|
+
toolName: 'get_explore',
|
|
67
|
+
annotations: READ_ONLY_DEFAULT,
|
|
68
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
69
|
+
},
|
|
70
|
+
cli: { commandPath: 'projects explores get' },
|
|
71
|
+
profiles: [PROFILE_SEMANTIC],
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const listDimensions = defineOperation({
|
|
75
|
+
id: 'semantic.explores.list_dimensions',
|
|
76
|
+
summary: 'List dimensions for an explore (derived from get explore)',
|
|
77
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
|
|
78
|
+
authorization: { safetyImpact: 'read' },
|
|
79
|
+
sensitivity: 'none',
|
|
80
|
+
mcp: {
|
|
81
|
+
toolName: 'list_dimensions',
|
|
82
|
+
annotations: READ_ONLY_DEFAULT,
|
|
83
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
84
|
+
},
|
|
85
|
+
cli: { commandPath: 'projects explores dimensions' },
|
|
86
|
+
profiles: [PROFILE_SEMANTIC],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const getFieldLineage = defineOperation({
|
|
90
|
+
id: 'semantic.explores.get_field_lineage',
|
|
91
|
+
summary: 'Get field lineage for an explore field (derived from get explore)',
|
|
92
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}` },
|
|
93
|
+
authorization: { safetyImpact: 'read' },
|
|
94
|
+
sensitivity: 'none',
|
|
95
|
+
mcp: {
|
|
96
|
+
toolName: 'get_field_lineage',
|
|
97
|
+
annotations: READ_ONLY_DEFAULT,
|
|
98
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
99
|
+
},
|
|
100
|
+
cli: { commandPath: 'projects explores lineage' },
|
|
101
|
+
profiles: [PROFILE_SEMANTIC],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const listMetrics = defineOperation({
|
|
105
|
+
id: 'semantic.metrics.list',
|
|
106
|
+
summary: 'List metrics in the project data catalog',
|
|
107
|
+
http: { method: 'GET', path: `${API_V1}/projects/{projectUuid}/dataCatalog/metrics` },
|
|
108
|
+
authorization: { safetyImpact: 'read' },
|
|
109
|
+
sensitivity: 'none',
|
|
110
|
+
mcp: {
|
|
111
|
+
toolName: 'list_metrics',
|
|
112
|
+
annotations: READ_ONLY_DEFAULT,
|
|
113
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
114
|
+
},
|
|
115
|
+
cli: { commandPath: 'metrics list' },
|
|
116
|
+
profiles: [PROFILE_SEMANTIC],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const getMetric = defineOperation({
|
|
120
|
+
id: 'semantic.metrics.get',
|
|
121
|
+
summary: 'Get a metric from the project data catalog',
|
|
122
|
+
http: {
|
|
123
|
+
method: 'GET',
|
|
124
|
+
path: `${API_V1}/projects/{projectUuid}/dataCatalog/metrics/{tableName}/{metricName}`,
|
|
125
|
+
},
|
|
126
|
+
authorization: { safetyImpact: 'read' },
|
|
127
|
+
sensitivity: 'none',
|
|
128
|
+
mcp: {
|
|
129
|
+
toolName: 'get_metric',
|
|
130
|
+
annotations: READ_ONLY_DEFAULT,
|
|
131
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
132
|
+
},
|
|
133
|
+
cli: { commandPath: 'metrics get' },
|
|
134
|
+
profiles: [PROFILE_SEMANTIC],
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const compileQuery = defineOperation({
|
|
138
|
+
id: 'semantic.query.compile',
|
|
139
|
+
summary: 'Compile a metric query to SQL without executing warehouse rows',
|
|
140
|
+
http: {
|
|
141
|
+
method: 'POST',
|
|
142
|
+
path: `${API_V1}/projects/{projectUuid}/explores/{exploreId}/compileQuery`,
|
|
143
|
+
},
|
|
144
|
+
authorization: { safetyImpact: 'read' },
|
|
145
|
+
sensitivity: 'none',
|
|
146
|
+
mcp: {
|
|
147
|
+
toolName: 'compile_query',
|
|
148
|
+
annotations: READ_ONLY_DEFAULT,
|
|
149
|
+
taskSupport: { exposed: true, taskEligible: false },
|
|
150
|
+
},
|
|
151
|
+
cli: { commandPath: 'query compile' },
|
|
152
|
+
profiles: [PROFILE_SEMANTIC],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/** Semantic-layer operations registered in the shared operation catalog. */
|
|
156
|
+
export const SEMANTIC_LAYER_OPERATIONS: readonly OperationDescriptor[] = [
|
|
157
|
+
listProjects,
|
|
158
|
+
getProject,
|
|
159
|
+
listExplores,
|
|
160
|
+
getExplore,
|
|
161
|
+
listDimensions,
|
|
162
|
+
getFieldLineage,
|
|
163
|
+
listMetrics,
|
|
164
|
+
getMetric,
|
|
165
|
+
compileQuery,
|
|
166
|
+
];
|
|
@@ -7,6 +7,7 @@ const baseDescriptor = {
|
|
|
7
7
|
summary: 'Test operation',
|
|
8
8
|
http: { method: 'GET' as const, path: '/api/v1/test' },
|
|
9
9
|
authorization: { safetyImpact: 'read' as const },
|
|
10
|
+
sensitivity: 'none' as const,
|
|
10
11
|
mcp: {
|
|
11
12
|
toolName: 'test_op',
|
|
12
13
|
annotations: {
|
|
@@ -27,31 +28,40 @@ describe('defineOperation', () => {
|
|
|
27
28
|
expect(defineOperation(baseDescriptor)).toEqual({
|
|
28
29
|
...baseDescriptor,
|
|
29
30
|
agentExposure: 'agent',
|
|
31
|
+
sensitivity: 'none',
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
34
|
|
|
33
|
-
it('defaults agentExposure to agent', () => {
|
|
34
|
-
const { agentExposure, ...
|
|
35
|
+
it('defaults agentExposure to agent and sensitivity to none', () => {
|
|
36
|
+
const { agentExposure, sensitivity, ...withoutDefaults } = baseDescriptor;
|
|
35
37
|
void agentExposure;
|
|
36
|
-
|
|
38
|
+
void sensitivity;
|
|
39
|
+
const op = defineOperation(withoutDefaults);
|
|
40
|
+
expect(op.agentExposure).toBe('agent');
|
|
41
|
+
expect(op.sensitivity).toBe('none');
|
|
37
42
|
});
|
|
38
43
|
|
|
39
|
-
it('
|
|
40
|
-
|
|
44
|
+
it('allows agent ops with mcp only', () => {
|
|
45
|
+
const { cli: _cli, ...rest } = baseDescriptor;
|
|
46
|
+
void _cli;
|
|
47
|
+
expect(defineOperation(rest).cli).toBeUndefined();
|
|
41
48
|
});
|
|
42
49
|
|
|
43
|
-
it('
|
|
44
|
-
|
|
50
|
+
it('allows agent ops with cli only', () => {
|
|
51
|
+
const { mcp: _mcp, ...rest } = baseDescriptor;
|
|
52
|
+
void _mcp;
|
|
53
|
+
expect(defineOperation(rest).mcp).toBeUndefined();
|
|
45
54
|
});
|
|
46
55
|
|
|
47
|
-
it('rejects
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
it('rejects agent ops with neither mcp nor cli', () => {
|
|
57
|
+
const { mcp: _mcp, cli: _cli, ...rest } = baseDescriptor;
|
|
58
|
+
void _mcp;
|
|
59
|
+
void _cli;
|
|
60
|
+
expect(() => defineOperation(rest)).toThrow(/require mcp and\/or cli/);
|
|
51
61
|
});
|
|
52
62
|
|
|
53
|
-
it('rejects empty
|
|
54
|
-
expect(() => defineOperation({ ...baseDescriptor,
|
|
63
|
+
it('rejects empty id', () => {
|
|
64
|
+
expect(() => defineOperation({ ...baseDescriptor, id: ' ' })).toThrow(/id/);
|
|
55
65
|
});
|
|
56
66
|
|
|
57
67
|
it('rejects unknown profile', () => {
|
|
@@ -63,86 +73,38 @@ describe('defineOperation', () => {
|
|
|
63
73
|
).toThrow(/unknown capability profile/);
|
|
64
74
|
});
|
|
65
75
|
|
|
66
|
-
it('
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
mcp
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
).toThrow(/idempotentHint/);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('rejects destructive operation with idempotentHint true', () => {
|
|
79
|
-
expect(() =>
|
|
80
|
-
defineOperation({
|
|
81
|
-
...baseDescriptor,
|
|
82
|
-
authorization: { safetyImpact: 'write-destructive' },
|
|
83
|
-
mcp: {
|
|
84
|
-
...baseDescriptor.mcp,
|
|
85
|
-
annotations: {
|
|
86
|
-
readOnlyHint: false,
|
|
87
|
-
destructiveHint: true,
|
|
88
|
-
idempotentHint: true,
|
|
89
|
-
openWorldHint: false,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
}),
|
|
93
|
-
).toThrow(/destructive operations/);
|
|
76
|
+
it('allows read operation with idempotentHint false (transient execution)', () => {
|
|
77
|
+
const op = defineOperation({
|
|
78
|
+
...baseDescriptor,
|
|
79
|
+
mcp: {
|
|
80
|
+
...baseDescriptor.mcp,
|
|
81
|
+
annotations: { ...baseDescriptor.mcp.annotations, idempotentHint: false },
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
expect(op.mcp?.annotations.idempotentHint).toBe(false);
|
|
94
85
|
});
|
|
95
86
|
|
|
96
|
-
it('rejects client-only operation
|
|
87
|
+
it('rejects client-only operation that still has mcp', () => {
|
|
97
88
|
expect(() =>
|
|
98
89
|
defineOperation({
|
|
99
90
|
...baseDescriptor,
|
|
100
91
|
agentExposure: 'client-only',
|
|
101
|
-
mcp: {
|
|
102
|
-
...baseDescriptor.mcp,
|
|
103
|
-
taskSupport: { exposed: true, taskEligible: false },
|
|
104
|
-
},
|
|
105
92
|
}),
|
|
106
|
-
).toThrow(/
|
|
93
|
+
).toThrow(/must omit mcp and cli/);
|
|
107
94
|
});
|
|
108
95
|
|
|
109
|
-
it('allows client-only operation
|
|
96
|
+
it('allows client-only operation with bannedMcpToolName and no mcp/cli', () => {
|
|
110
97
|
const op = defineOperation({
|
|
111
98
|
id: 'test.client-only',
|
|
112
99
|
summary: 'Client only delete',
|
|
113
100
|
http: { method: 'DELETE', path: '/api/v1/test/{id}' },
|
|
114
101
|
authorization: { safetyImpact: 'write-destructive' },
|
|
115
|
-
mcp: {
|
|
116
|
-
toolName: '',
|
|
117
|
-
annotations: {
|
|
118
|
-
readOnlyHint: false,
|
|
119
|
-
destructiveHint: true,
|
|
120
|
-
idempotentHint: false,
|
|
121
|
-
openWorldHint: false,
|
|
122
|
-
},
|
|
123
|
-
taskSupport: { exposed: false, taskEligible: false },
|
|
124
|
-
},
|
|
125
|
-
cli: { commandPath: '' },
|
|
126
102
|
agentExposure: 'client-only',
|
|
103
|
+
bannedMcpToolName: 'delete_test',
|
|
127
104
|
profiles: ['discovery-readonly'],
|
|
128
105
|
});
|
|
129
106
|
expect(op.agentExposure).toBe('client-only');
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
it('maps openWorldHint to external-side-effect impact', () => {
|
|
133
|
-
const op = defineOperation({
|
|
134
|
-
...baseDescriptor,
|
|
135
|
-
authorization: { safetyImpact: 'external-side-effect' },
|
|
136
|
-
mcp: {
|
|
137
|
-
...baseDescriptor.mcp,
|
|
138
|
-
annotations: {
|
|
139
|
-
readOnlyHint: false,
|
|
140
|
-
destructiveHint: false,
|
|
141
|
-
idempotentHint: false,
|
|
142
|
-
openWorldHint: true,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
expect(op.authorization.safetyImpact).toBe('external-side-effect');
|
|
107
|
+
expect(op.bannedMcpToolName).toBe('delete_test');
|
|
108
|
+
expect(op.sensitivity).toBe('none');
|
|
147
109
|
});
|
|
148
110
|
});
|
package/src/operations/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared typed operation
|
|
2
|
+
* Shared typed operation catalog (ADR-0013).
|
|
3
3
|
* Single source of truth for HTTP, CLI, and MCP exposure of Lightdash API operations.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -17,7 +17,21 @@ export type HttpMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
|
|
|
17
17
|
* Capability profiles group operations for selective exposure (CLI profiles, MCP subsets).
|
|
18
18
|
*/
|
|
19
19
|
export type CapabilityProfile =
|
|
20
|
-
|
|
20
|
+
| 'content-developer'
|
|
21
|
+
| 'content-governance'
|
|
22
|
+
| 'content-reader'
|
|
23
|
+
| 'conversations'
|
|
24
|
+
| 'core-lifecycle'
|
|
25
|
+
| 'discovery-readonly'
|
|
26
|
+
| 'evaluations'
|
|
27
|
+
| 'org-audit-readonly'
|
|
28
|
+
| 'semantic-discovery';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* MCP response sensitivity class (ADR-0011).
|
|
32
|
+
* Documents which redaction class handlers must apply; does not auto-redact.
|
|
33
|
+
*/
|
|
34
|
+
export type SensitivityClass = 'none' | 'pii.email' | 'secret.connection' | 'secret.destination';
|
|
21
35
|
|
|
22
36
|
/** MCP task semantics for an operation. */
|
|
23
37
|
export type McpTaskSupport = {
|
|
@@ -36,7 +50,7 @@ export type OperationAuthorization = {
|
|
|
36
50
|
|
|
37
51
|
export type OperationHttp = {
|
|
38
52
|
method: HttpMethod;
|
|
39
|
-
/** OpenAPI-style path template (includes `/api/v1` prefix). */
|
|
53
|
+
/** OpenAPI-style path template (includes `/api/v1` or `/api/v2` prefix). */
|
|
40
54
|
path: string;
|
|
41
55
|
};
|
|
42
56
|
|
|
@@ -65,20 +79,50 @@ export type OperationDescriptor = {
|
|
|
65
79
|
summary: string;
|
|
66
80
|
http: OperationHttp;
|
|
67
81
|
authorization: OperationAuthorization;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Response sensitivity class for agent surfaces (ADR-0011).
|
|
84
|
+
* Defaults to `none` when omitted from `defineOperation` input.
|
|
85
|
+
*/
|
|
86
|
+
sensitivity: SensitivityClass;
|
|
72
87
|
profiles: readonly CapabilityProfile[];
|
|
88
|
+
/** `agent` (default) = may appear on MCP and/or CLI; `client-only` = typed client only. */
|
|
89
|
+
agentExposure: AgentExposure;
|
|
90
|
+
/** Present when the operation is registered (or reserved) as an MCP tool. */
|
|
91
|
+
mcp?: OperationMcp;
|
|
92
|
+
/** Present when a real CLI command exists (`commandPath` must match Commander). */
|
|
93
|
+
cli?: OperationCli;
|
|
94
|
+
/** Irrecoverable denylist name for client-only ops (sans `lightdash_` prefix). */
|
|
95
|
+
bannedMcpToolName?: string;
|
|
73
96
|
/** When set, documents the ordered client-side HTTP steps behind this operation. */
|
|
74
97
|
workflow?: readonly OperationWorkflowStep[];
|
|
75
98
|
};
|
|
76
99
|
|
|
100
|
+
/** Input to `defineOperation` before defaults are applied. */
|
|
101
|
+
export type OperationDefinitionInput = Omit<
|
|
102
|
+
OperationDescriptor,
|
|
103
|
+
'agentExposure' | 'sensitivity'
|
|
104
|
+
> & {
|
|
105
|
+
agentExposure?: AgentExposure;
|
|
106
|
+
sensitivity?: SensitivityClass;
|
|
107
|
+
};
|
|
108
|
+
|
|
77
109
|
const VALID_PROFILES = new Set<CapabilityProfile>([
|
|
110
|
+
'content-developer',
|
|
111
|
+
'content-governance',
|
|
112
|
+
'content-reader',
|
|
78
113
|
'conversations',
|
|
79
114
|
'core-lifecycle',
|
|
80
115
|
'discovery-readonly',
|
|
81
116
|
'evaluations',
|
|
117
|
+
'org-audit-readonly',
|
|
118
|
+
'semantic-discovery',
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
const VALID_SENSITIVITY = new Set<SensitivityClass>([
|
|
122
|
+
'none',
|
|
123
|
+
'pii.email',
|
|
124
|
+
'secret.connection',
|
|
125
|
+
'secret.destination',
|
|
82
126
|
]);
|
|
83
127
|
|
|
84
128
|
function assertNonEmpty(value: string, field: string): void {
|
|
@@ -105,11 +149,6 @@ function validateIdempotentHint(
|
|
|
105
149
|
impact: SafetyImpact,
|
|
106
150
|
id: string,
|
|
107
151
|
): void {
|
|
108
|
-
if (impact === 'read' && annotations.idempotentHint !== true) {
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Operation '${id}': read operations must set mcp.annotations.idempotentHint = true`,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
152
|
if (impact === 'write-destructive' && annotations.idempotentHint === true) {
|
|
114
153
|
throw new Error(
|
|
115
154
|
`Operation '${id}': destructive operations must not set mcp.annotations.idempotentHint = true`,
|
|
@@ -117,52 +156,76 @@ function validateIdempotentHint(
|
|
|
117
156
|
}
|
|
118
157
|
}
|
|
119
158
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
assertNonEmpty(descriptor.summary, 'summary');
|
|
129
|
-
assertNonEmpty(descriptor.http.path, 'http.path');
|
|
130
|
-
|
|
131
|
-
const agentExposure = descriptor.agentExposure ?? 'agent';
|
|
132
|
-
|
|
133
|
-
if (agentExposure === 'agent') {
|
|
134
|
-
assertNonEmpty(descriptor.mcp.toolName, 'mcp.toolName');
|
|
135
|
-
assertNonEmpty(descriptor.cli.commandPath, 'cli.commandPath');
|
|
159
|
+
function validateProfiles(id: string, profiles: readonly CapabilityProfile[]): void {
|
|
160
|
+
if (profiles.length === 0) {
|
|
161
|
+
throw new Error(`Operation '${id}' must declare at least one capability profile`);
|
|
162
|
+
}
|
|
163
|
+
for (const profile of profiles) {
|
|
164
|
+
if (!VALID_PROFILES.has(profile)) {
|
|
165
|
+
throw new Error(`Operation '${id}' has unknown capability profile '${profile}'`);
|
|
166
|
+
}
|
|
136
167
|
}
|
|
168
|
+
}
|
|
137
169
|
|
|
138
|
-
|
|
170
|
+
function validateClientOnlyOperation(input: OperationDefinitionInput): OperationDescriptor {
|
|
171
|
+
if (input.mcp !== undefined || input.cli !== undefined) {
|
|
139
172
|
throw new Error(
|
|
140
|
-
`Operation '${
|
|
173
|
+
`Operation '${input.id}': client-only operations must omit mcp and cli metadata`,
|
|
141
174
|
);
|
|
142
175
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
throw new Error(`Operation '${descriptor.id}' must declare at least one capability profile`);
|
|
176
|
+
if (input.bannedMcpToolName !== undefined && input.bannedMcpToolName.trim().length === 0) {
|
|
177
|
+
throw new Error(`Operation '${input.id}': bannedMcpToolName must be non-empty when set`);
|
|
146
178
|
}
|
|
179
|
+
return {
|
|
180
|
+
...input,
|
|
181
|
+
agentExposure: 'client-only',
|
|
182
|
+
sensitivity: input.sensitivity ?? 'none',
|
|
183
|
+
};
|
|
184
|
+
}
|
|
147
185
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
186
|
+
function validateAgentMcp(input: OperationDefinitionInput): void {
|
|
187
|
+
if (input.mcp === undefined) {
|
|
188
|
+
return;
|
|
152
189
|
}
|
|
153
|
-
|
|
154
|
-
const expectedImpact = expectedImpactFromAnnotations(
|
|
155
|
-
if (
|
|
190
|
+
assertNonEmpty(input.mcp.toolName, 'mcp.toolName');
|
|
191
|
+
const expectedImpact = expectedImpactFromAnnotations(input.mcp.annotations);
|
|
192
|
+
if (input.authorization.safetyImpact !== expectedImpact) {
|
|
156
193
|
throw new Error(
|
|
157
|
-
`Operation '${
|
|
194
|
+
`Operation '${input.id}': authorization.safetyImpact is '${input.authorization.safetyImpact}' but MCP annotations imply '${expectedImpact}'`,
|
|
158
195
|
);
|
|
159
196
|
}
|
|
197
|
+
validateIdempotentHint(input.mcp.annotations, input.authorization.safetyImpact, input.id);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Defines a typed operation descriptor with catalog consistency checks (ADR-0013).
|
|
202
|
+
* Agent ops require at least one of `mcp` or `cli`. Client-only ops omit both.
|
|
203
|
+
*/
|
|
204
|
+
export function defineOperation(input: OperationDefinitionInput): OperationDescriptor {
|
|
205
|
+
assertNonEmpty(input.id, 'id');
|
|
206
|
+
assertNonEmpty(input.summary, 'summary');
|
|
207
|
+
assertNonEmpty(input.http.path, 'http.path');
|
|
208
|
+
|
|
209
|
+
const sensitivity = input.sensitivity ?? 'none';
|
|
210
|
+
if (!VALID_SENSITIVITY.has(sensitivity)) {
|
|
211
|
+
throw new Error(`Operation '${input.id}' has unknown sensitivity '${String(sensitivity)}'`);
|
|
212
|
+
}
|
|
160
213
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
214
|
+
validateProfiles(input.id, input.profiles);
|
|
215
|
+
|
|
216
|
+
const agentExposure = input.agentExposure ?? 'agent';
|
|
217
|
+
if (agentExposure === 'client-only') {
|
|
218
|
+
return validateClientOnlyOperation({ ...input, sensitivity });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (input.mcp === undefined && input.cli === undefined) {
|
|
222
|
+
throw new Error(`Operation '${input.id}': agent operations require mcp and/or cli metadata`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
validateAgentMcp(input);
|
|
226
|
+
if (input.cli !== undefined) {
|
|
227
|
+
assertNonEmpty(input.cli.commandPath, 'cli.commandPath');
|
|
228
|
+
}
|
|
166
229
|
|
|
167
|
-
return { ...
|
|
230
|
+
return { ...input, agentExposure: 'agent', sensitivity };
|
|
168
231
|
}
|