@lightdash-tools/mcp 0.20.0 → 0.22.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 +5 -5
- package/dist/auth/request-state-key.d.ts +2 -2
- package/dist/auth/request-state-key.js +2 -2
- package/dist/config/enabled-profiles.d.ts +1 -1
- package/dist/config/enabled-profiles.js +3 -2
- package/dist/config/enabled-profiles.test.js +1 -0
- package/dist/policy/create-agent-preview.d.ts +65 -0
- package/dist/policy/create-agent-preview.js +126 -0
- package/dist/policy/create-agent-preview.test.d.ts +4 -0
- package/dist/policy/create-agent-preview.test.js +162 -0
- package/dist/profiles/ai-agent-ops/v1/index.js +10 -0
- package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +6 -3
- package/dist/profiles/ai-agent-ops/v1/invariants.js +6 -2
- package/dist/profiles/ai-agent-ops/v1/prompts.js +24 -3
- package/dist/profiles/ai-agent-ops/v1/prompts.test.js +10 -1
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/core.md +34 -2
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +9 -4
- package/dist/profiles/index.test.js +7 -2
- package/dist/server/server.js +16 -4
- package/dist/tools/ai-agents/agents.d.ts +8 -0
- package/dist/tools/ai-agents/agents.js +283 -1
- package/dist/tools/ai-agents/agents.test.js +25 -0
- package/dist/tools/ai-agents/create-elicitation.d.ts +52 -0
- package/dist/tools/ai-agents/create-elicitation.js +206 -0
- package/dist/tools/ai-agents/create-elicitation.test.d.ts +4 -0
- package/dist/tools/ai-agents/create-elicitation.test.js +363 -0
- package/dist/tools/ai-agents/create-request-state.d.ts +18 -0
- package/dist/tools/ai-agents/create-request-state.js +43 -0
- package/dist/tools/ai-agents/documents.d.ts +15 -0
- package/dist/tools/ai-agents/documents.js +212 -0
- package/dist/tools/ai-agents/documents.test.d.ts +1 -0
- package/dist/tools/ai-agents/documents.test.js +129 -0
- package/dist/tools/ai-agents/gate-create-project-agent.d.ts +28 -0
- package/dist/tools/ai-agents/gate-create-project-agent.js +71 -0
- package/dist/tools/ai-agents/helpers.d.ts +11 -0
- package/dist/tools/ai-agents/helpers.js +29 -1
- package/dist/tools/ai-agents/knowledge-warnings.d.ts +11 -0
- package/dist/tools/ai-agents/knowledge-warnings.js +21 -0
- package/dist/tools/ai-agents/space-warnings.d.ts +36 -0
- package/dist/tools/ai-agents/space-warnings.js +101 -0
- package/dist/tools/ai-agents/space-warnings.test.d.ts +1 -0
- package/dist/tools/ai-agents/space-warnings.test.js +78 -0
- package/dist/tools/ai-agents/tag-warnings.d.ts +31 -0
- package/dist/tools/ai-agents/tag-warnings.js +70 -0
- package/dist/tools/ai-agents/test-support.d.ts +4 -1
- package/dist/tools/ai-agents/test-support.js +7 -2
- package/package.json +3 -3
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Form elicitation gate for create_project_agent (ADR-0033 / ADR-0015 pattern).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CREATE_AGENT_CONFIRM_FORM_SCHEMA = exports.CONFIRM_CREATE_AGENT_INPUT_KEY = exports.previewExploreCountForTags = exports.digestCreateAgentPayload = void 0;
|
|
7
|
+
exports.buildCreateAgentConfirmationMessage = buildCreateAgentConfirmationMessage;
|
|
8
|
+
exports.gateCreateProjectAgentElicitation = gateCreateProjectAgentElicitation;
|
|
9
|
+
const common_1 = require("@lightdash-tools/common");
|
|
10
|
+
Object.defineProperty(exports, "digestCreateAgentPayload", { enumerable: true, get: function () { return common_1.digestCreateAgentPayload; } });
|
|
11
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
12
|
+
const shared_js_1 = require("../shared.js");
|
|
13
|
+
const create_request_state_js_1 = require("./create-request-state.js");
|
|
14
|
+
const space_warnings_js_1 = require("./space-warnings.js");
|
|
15
|
+
const tag_warnings_js_1 = require("./tag-warnings.js");
|
|
16
|
+
Object.defineProperty(exports, "previewExploreCountForTags", { enumerable: true, get: function () { return tag_warnings_js_1.previewExploreCountForTags; } });
|
|
17
|
+
exports.CONFIRM_CREATE_AGENT_INPUT_KEY = 'confirm_create_agent';
|
|
18
|
+
exports.CREATE_AGENT_CONFIRM_FORM_SCHEMA = {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
decision: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
title: 'Create AI agent?',
|
|
24
|
+
description: 'Creates a new Lightdash AI agent in this project (not idempotent).',
|
|
25
|
+
enum: ['confirm_create', 'do_not_create'],
|
|
26
|
+
enumNames: ['Create agent', 'Do not create'],
|
|
27
|
+
default: 'do_not_create',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ['decision'],
|
|
31
|
+
};
|
|
32
|
+
function appendTagPreviewLines(lines, tags, exploreCount) {
|
|
33
|
+
const effective = (0, tag_warnings_js_1.effectiveAgentTags)(tags);
|
|
34
|
+
if (effective === undefined) {
|
|
35
|
+
lines.push('Tags: (none — agent can access all project explores)');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
lines.push(`Tags: ${effective.join(', ')}`);
|
|
39
|
+
if (exploreCount === null) {
|
|
40
|
+
lines.push('Explore access preview: unavailable (summary call failed)');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (exploreCount === 0) {
|
|
44
|
+
lines.push('Explore access preview: 0 explores — agent will see no data model with these tags.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
lines.push(`Explore access preview: ${exploreCount} explore(s) match these tags`);
|
|
48
|
+
}
|
|
49
|
+
function buildCreateAgentConfirmationMessage(input) {
|
|
50
|
+
const lines = [
|
|
51
|
+
'Confirm creation of a new Lightdash AI agent.',
|
|
52
|
+
`Name: ${input.name}`,
|
|
53
|
+
'Permissions:',
|
|
54
|
+
...(0, common_1.formatAgentPermissionSummary)(input.payload, {
|
|
55
|
+
groupAccess: input.payload.groupAccess,
|
|
56
|
+
userAccess: input.payload.userAccess,
|
|
57
|
+
}),
|
|
58
|
+
];
|
|
59
|
+
lines.push((0, space_warnings_js_1.formatSpaceAccessPreviewLine)(input.payload.spaceAccess, input.spaceAccessValidation));
|
|
60
|
+
appendTagPreviewLines(lines, input.tags, input.exploreCount);
|
|
61
|
+
lines.push('Choose Create agent to proceed, or Do not create to cancel.');
|
|
62
|
+
return lines.join('\n');
|
|
63
|
+
}
|
|
64
|
+
function elicitationRequiredResult(message) {
|
|
65
|
+
return (0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
66
|
+
status: 'blocked',
|
|
67
|
+
code: 'ELICITATION_REQUIRED',
|
|
68
|
+
message,
|
|
69
|
+
created: false,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
function confirmationInvalidResult(message) {
|
|
73
|
+
return (0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
74
|
+
status: 'blocked',
|
|
75
|
+
code: 'CONFIRMATION_INVALID',
|
|
76
|
+
message,
|
|
77
|
+
created: false,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
function declinedCreateResult(projectUuid) {
|
|
81
|
+
return (0, shared_js_1.withAuditStatus)((0, shared_js_1.jsonToolResult)({
|
|
82
|
+
status: 'declined',
|
|
83
|
+
created: false,
|
|
84
|
+
operation: create_request_state_js_1.CREATE_PROJECT_AGENT_OPERATION_ID,
|
|
85
|
+
projectUuid,
|
|
86
|
+
}), 'confirmation_declined');
|
|
87
|
+
}
|
|
88
|
+
function cancelledCreateResult(projectUuid) {
|
|
89
|
+
return (0, shared_js_1.withAuditStatus)((0, shared_js_1.jsonToolResult)({
|
|
90
|
+
status: 'cancelled',
|
|
91
|
+
created: false,
|
|
92
|
+
operation: create_request_state_js_1.CREATE_PROJECT_AGENT_OPERATION_ID,
|
|
93
|
+
projectUuid,
|
|
94
|
+
}), 'confirmation_cancelled');
|
|
95
|
+
}
|
|
96
|
+
function requireElicitationServerContext(serverContext) {
|
|
97
|
+
if (!serverContext) {
|
|
98
|
+
return elicitationRequiredResult('Missing MCP ServerContext required for elicitation.');
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
async function readBoundCreateRequestState(serverContext) {
|
|
103
|
+
const mcpReq = serverContext.mcpReq;
|
|
104
|
+
const raw = typeof mcpReq.requestState === 'function' ? mcpReq.requestState() : mcpReq.requestState;
|
|
105
|
+
if (typeof raw === 'string') {
|
|
106
|
+
return (0, create_request_state_js_1.verifyCreateAgentRequestState)(raw, serverContext);
|
|
107
|
+
}
|
|
108
|
+
if (raw &&
|
|
109
|
+
typeof raw === 'object' &&
|
|
110
|
+
'payloadDigest' in raw &&
|
|
111
|
+
'operationId' in raw &&
|
|
112
|
+
raw.operationId === create_request_state_js_1.CREATE_PROJECT_AGENT_OPERATION_ID) {
|
|
113
|
+
return raw;
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
function bindingMatchesCreate(boundState, projectUuid, subject, payloadDigest) {
|
|
118
|
+
return (boundState.operationId === create_request_state_js_1.CREATE_PROJECT_AGENT_OPERATION_ID &&
|
|
119
|
+
boundState.projectUuid === projectUuid &&
|
|
120
|
+
boundState.subject === subject &&
|
|
121
|
+
boundState.payloadDigest === payloadDigest);
|
|
122
|
+
}
|
|
123
|
+
function resolveAcceptedCreateDecision(accepted, projectUuid) {
|
|
124
|
+
if (accepted.decision === 'do_not_create') {
|
|
125
|
+
return { proceed: false, result: declinedCreateResult(projectUuid) };
|
|
126
|
+
}
|
|
127
|
+
if (accepted.decision !== 'confirm_create') {
|
|
128
|
+
return {
|
|
129
|
+
proceed: false,
|
|
130
|
+
result: confirmationInvalidResult('Confirmation was not accepted for create_project_agent.'),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return { proceed: true };
|
|
134
|
+
}
|
|
135
|
+
async function mintCreateInputRequired(input) {
|
|
136
|
+
const [exploreCount, spaceAccessValidation] = await Promise.all([
|
|
137
|
+
(0, tag_warnings_js_1.previewExploreCountForTags)(input.exploreAccessClient, input.projectUuid, input.payload.tags),
|
|
138
|
+
(0, space_warnings_js_1.fetchSpaceAccessValidation)(input.spacesClient, input.projectUuid, input.payload.spaceAccess),
|
|
139
|
+
]);
|
|
140
|
+
const stateToken = await (0, create_request_state_js_1.mintCreateAgentRequestState)({
|
|
141
|
+
operationId: create_request_state_js_1.CREATE_PROJECT_AGENT_OPERATION_ID,
|
|
142
|
+
projectUuid: input.projectUuid,
|
|
143
|
+
payloadDigest: input.payloadDigest,
|
|
144
|
+
subject: input.subject,
|
|
145
|
+
}, input.serverContext);
|
|
146
|
+
return (0, server_1.inputRequired)({
|
|
147
|
+
requestState: stateToken,
|
|
148
|
+
inputRequests: {
|
|
149
|
+
[exports.CONFIRM_CREATE_AGENT_INPUT_KEY]: server_1.inputRequired.elicit({
|
|
150
|
+
mode: 'form',
|
|
151
|
+
message: buildCreateAgentConfirmationMessage({
|
|
152
|
+
name: input.payload.name,
|
|
153
|
+
payload: input.payload,
|
|
154
|
+
tags: input.payload.tags,
|
|
155
|
+
exploreCount,
|
|
156
|
+
spaceAccessValidation,
|
|
157
|
+
}),
|
|
158
|
+
requestedSchema: exports.CREATE_AGENT_CONFIRM_FORM_SCHEMA,
|
|
159
|
+
}),
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Run the create elicitation gate. Returns:
|
|
165
|
+
* - ToolResult to return immediately (blocked / input required / declined), or
|
|
166
|
+
* - `{ proceed: true }` when the human accepted and the digest matches.
|
|
167
|
+
*/
|
|
168
|
+
async function gateCreateProjectAgentElicitation(input) {
|
|
169
|
+
const { ctx, projectUuid, payload, exploreAccessClient, spacesClient } = input;
|
|
170
|
+
const elicitationError = requireElicitationServerContext(ctx.serverContext);
|
|
171
|
+
if (elicitationError) {
|
|
172
|
+
return { proceed: false, result: elicitationError };
|
|
173
|
+
}
|
|
174
|
+
const serverContext = ctx.serverContext;
|
|
175
|
+
const responseView = (0, server_1.inputResponse)(serverContext.mcpReq.inputResponses, exports.CONFIRM_CREATE_AGENT_INPUT_KEY);
|
|
176
|
+
if (responseView.kind === 'elicit' && responseView.action === 'decline') {
|
|
177
|
+
return { proceed: false, result: declinedCreateResult(projectUuid) };
|
|
178
|
+
}
|
|
179
|
+
if (responseView.kind === 'elicit' && responseView.action === 'cancel') {
|
|
180
|
+
return { proceed: false, result: cancelledCreateResult(projectUuid) };
|
|
181
|
+
}
|
|
182
|
+
const payloadDigest = (0, common_1.digestCreateAgentPayload)(payload);
|
|
183
|
+
const accepted = (0, server_1.acceptedContent)(serverContext.mcpReq.inputResponses, exports.CONFIRM_CREATE_AGENT_INPUT_KEY);
|
|
184
|
+
const boundState = await readBoundCreateRequestState(serverContext);
|
|
185
|
+
if (accepted && boundState) {
|
|
186
|
+
if (!bindingMatchesCreate(boundState, projectUuid, ctx.subject, payloadDigest)) {
|
|
187
|
+
return {
|
|
188
|
+
proceed: false,
|
|
189
|
+
result: confirmationInvalidResult('Confirmation binding does not match this create_project_agent request.'),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return resolveAcceptedCreateDecision(accepted, projectUuid);
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
proceed: false,
|
|
196
|
+
result: await mintCreateInputRequired({
|
|
197
|
+
serverContext,
|
|
198
|
+
projectUuid,
|
|
199
|
+
payload,
|
|
200
|
+
payloadDigest,
|
|
201
|
+
subject: ctx.subject,
|
|
202
|
+
exploreAccessClient,
|
|
203
|
+
spacesClient,
|
|
204
|
+
}),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unit tests for agent tag soft warnings and create_project_agent elicitation.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const create_agent_preview_js_1 = require("../../policy/create-agent-preview.js");
|
|
9
|
+
const agents_js_1 = require("./agents.js");
|
|
10
|
+
const create_elicitation_js_1 = require("./create-elicitation.js");
|
|
11
|
+
const create_request_state_js_1 = require("./create-request-state.js");
|
|
12
|
+
const tag_warnings_js_1 = require("./tag-warnings.js");
|
|
13
|
+
const test_support_js_1 = require("./test-support.js");
|
|
14
|
+
const PROJECT = '11111111-1111-1111-1111-111111111111';
|
|
15
|
+
const AGENT = '22222222-2222-2222-2222-222222222222';
|
|
16
|
+
function formCapsServerContext(overrides = {}) {
|
|
17
|
+
return {
|
|
18
|
+
mcpReq: {
|
|
19
|
+
envelope: {
|
|
20
|
+
[server_1.CLIENT_CAPABILITIES_META_KEY]: { elicitation: { form: {} } },
|
|
21
|
+
},
|
|
22
|
+
inputResponses: overrides.inputResponses,
|
|
23
|
+
requestState: overrides.requestState === undefined
|
|
24
|
+
? () => undefined
|
|
25
|
+
: typeof overrides.requestState === 'function'
|
|
26
|
+
? overrides.requestState
|
|
27
|
+
: () => overrides.requestState,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
(0, vitest_1.describe)('warningsForAgentTags', () => {
|
|
32
|
+
(0, vitest_1.it)('skips when tags are null or empty', async () => {
|
|
33
|
+
const getExploreAccessSummary = vitest_1.vi.fn();
|
|
34
|
+
(0, vitest_1.expect)(await (0, tag_warnings_js_1.warningsForAgentTags)({ getExploreAccessSummary }, PROJECT, null)).toEqual([]);
|
|
35
|
+
(0, vitest_1.expect)(await (0, tag_warnings_js_1.warningsForAgentTags)({ getExploreAccessSummary }, PROJECT, [])).toEqual([]);
|
|
36
|
+
(0, vitest_1.expect)(getExploreAccessSummary).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.it)('returns TAGS_MATCH_NO_EXPLORES when summary is empty', async () => {
|
|
39
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([]);
|
|
40
|
+
const warnings = await (0, tag_warnings_js_1.warningsForAgentTags)({ getExploreAccessSummary }, PROJECT, [
|
|
41
|
+
'no-such-tag',
|
|
42
|
+
]);
|
|
43
|
+
(0, vitest_1.expect)(warnings).toEqual([vitest_1.expect.objectContaining({ code: 'TAGS_MATCH_NO_EXPLORES' })]);
|
|
44
|
+
(0, vitest_1.expect)(getExploreAccessSummary).toHaveBeenCalledWith(PROJECT, { tags: ['no-such-tag'] });
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)('returns no warning when explores match', async () => {
|
|
47
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([{ exploreName: 'orders' }]);
|
|
48
|
+
const warnings = await (0, tag_warnings_js_1.warningsForAgentTags)({ getExploreAccessSummary }, PROJECT, ['ai']);
|
|
49
|
+
(0, vitest_1.expect)(warnings).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
(0, vitest_1.it)('returns EXPLORE_ACCESS_SUMMARY_UNAVAILABLE when summary throws', async () => {
|
|
52
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockRejectedValue(new Error('upstream down'));
|
|
53
|
+
const warnings = await (0, tag_warnings_js_1.warningsForAgentTags)({ getExploreAccessSummary }, PROJECT, ['ai']);
|
|
54
|
+
(0, vitest_1.expect)(warnings).toEqual([
|
|
55
|
+
vitest_1.expect.objectContaining({
|
|
56
|
+
code: 'EXPLORE_ACCESS_SUMMARY_UNAVAILABLE',
|
|
57
|
+
message: vitest_1.expect.stringContaining('upstream down'),
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.describe)('create elicitation helpers', () => {
|
|
63
|
+
(0, vitest_1.it)('digests are stable under tag reordering', () => {
|
|
64
|
+
const a = (0, create_elicitation_js_1.digestCreateAgentPayload)({ name: 'A', tags: ['b', 'a'], enableDataAccess: true });
|
|
65
|
+
const b = (0, create_elicitation_js_1.digestCreateAgentPayload)({ name: 'A', tags: ['a', 'b'], enableDataAccess: true });
|
|
66
|
+
(0, vitest_1.expect)(a).toBe(b);
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.it)('normalizes empty tags to the same digest as omitted tags', () => {
|
|
69
|
+
const omitted = (0, create_elicitation_js_1.digestCreateAgentPayload)({ name: 'A' });
|
|
70
|
+
const empty = (0, create_elicitation_js_1.digestCreateAgentPayload)({ name: 'A', tags: [] });
|
|
71
|
+
(0, vitest_1.expect)(empty).toBe(omitted);
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.it)('buildCreateAgentConfirmationMessage flags zero explores and shows permissions', () => {
|
|
74
|
+
const payload = { name: 'Analyst', enableDataAccess: true, tags: ['missing'] };
|
|
75
|
+
const msg = (0, create_elicitation_js_1.buildCreateAgentConfirmationMessage)({
|
|
76
|
+
name: 'Analyst',
|
|
77
|
+
payload,
|
|
78
|
+
tags: ['missing'],
|
|
79
|
+
exploreCount: 0,
|
|
80
|
+
spaceAccessValidation: { skipped: true },
|
|
81
|
+
});
|
|
82
|
+
(0, vitest_1.expect)(msg).toMatch(/0 explores/);
|
|
83
|
+
(0, vitest_1.expect)(msg).toMatch(/Analyst/);
|
|
84
|
+
(0, vitest_1.expect)(msg).toMatch(/Permissions:/);
|
|
85
|
+
(0, vitest_1.expect)(msg).toMatch(/Read rows behind chart: on/);
|
|
86
|
+
(0, vitest_1.expect)(msg).toMatch(/all project spaces/);
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.it)('buildCreateAgentConfirmationMessage shows resolved space names', () => {
|
|
89
|
+
const spaceUuid = '00000000-0000-4000-8000-000000000040';
|
|
90
|
+
const payload = { name: 'Analyst', spaceAccess: [spaceUuid] };
|
|
91
|
+
const msg = (0, create_elicitation_js_1.buildCreateAgentConfirmationMessage)({
|
|
92
|
+
name: 'Analyst',
|
|
93
|
+
payload,
|
|
94
|
+
tags: null,
|
|
95
|
+
exploreCount: null,
|
|
96
|
+
spaceAccessValidation: {
|
|
97
|
+
resolved: [{ uuid: spaceUuid, name: 'Finance' }],
|
|
98
|
+
unknownUuids: [],
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
(0, vitest_1.expect)(msg).toMatch(/Finance/);
|
|
102
|
+
(0, vitest_1.expect)(msg).toMatch(/1 space\(s\)/);
|
|
103
|
+
});
|
|
104
|
+
(0, vitest_1.it)('minimal payload digest uses secure defaults', () => {
|
|
105
|
+
const minimal = (0, create_elicitation_js_1.digestCreateAgentPayload)({ name: 'Smoke' });
|
|
106
|
+
const explicit = (0, create_elicitation_js_1.digestCreateAgentPayload)({
|
|
107
|
+
name: 'Smoke',
|
|
108
|
+
enableDataAccess: false,
|
|
109
|
+
enableContentTools: false,
|
|
110
|
+
enableSqlMode: false,
|
|
111
|
+
enableUserContext: false,
|
|
112
|
+
adminOnly: true,
|
|
113
|
+
enableSelfImprovement: false,
|
|
114
|
+
});
|
|
115
|
+
(0, vitest_1.expect)(minimal).toBe(explicit);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
(0, vitest_1.describe)('create_project_agent elicitation', () => {
|
|
119
|
+
(0, vitest_1.afterEach)(() => {
|
|
120
|
+
vitest_1.vi.unstubAllEnvs();
|
|
121
|
+
vitest_1.vi.restoreAllMocks();
|
|
122
|
+
(0, create_request_state_js_1.resetCreateAgentRequestStateCodecForTests)();
|
|
123
|
+
(0, create_agent_preview_js_1.resetCreateAgentPreviewCodecForTests)();
|
|
124
|
+
});
|
|
125
|
+
(0, vitest_1.it)('blocks with PREVIEW_REQUIRED when form elicitation is missing', async () => {
|
|
126
|
+
const createAgent = vitest_1.vi.fn();
|
|
127
|
+
const getExploreAccessSummary = vitest_1.vi.fn();
|
|
128
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'create_project_agent', {
|
|
129
|
+
registerTool: vitest_1.vi.fn(),
|
|
130
|
+
server: { getClientCapabilities: () => ({}) },
|
|
131
|
+
});
|
|
132
|
+
const result = await handler({ projectUuid: PROJECT, name: 'Analyst', enableDataAccess: true }, { mcpReq: { envelope: {}, inputResponses: undefined, requestState: () => undefined } });
|
|
133
|
+
(0, vitest_1.expect)(createAgent).not.toHaveBeenCalled();
|
|
134
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(result);
|
|
135
|
+
(0, vitest_1.expect)(body.code).toBe('PREVIEW_REQUIRED');
|
|
136
|
+
(0, vitest_1.expect)(body.created).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
(0, vitest_1.it)('creates via preview-token path when createConfirmToken is validated', async () => {
|
|
139
|
+
(0, create_agent_preview_js_1.resetCreateAgentPreviewCodecForTests)();
|
|
140
|
+
process.env.NODE_ENV = 'test';
|
|
141
|
+
const createAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: AGENT, name: 'Analyst' });
|
|
142
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([{ exploreName: 'orders' }]);
|
|
143
|
+
const { handler: previewHandler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerPreviewCreateAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'preview_create_agent', { registerTool: vitest_1.vi.fn(), server: { getClientCapabilities: () => ({}) } });
|
|
144
|
+
const { handler: confirmHandler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerConfirmCreateAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'confirm_create_agent', { registerTool: vitest_1.vi.fn(), server: { getClientCapabilities: () => ({}) } });
|
|
145
|
+
const { handler: createHandler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'create_project_agent', { registerTool: vitest_1.vi.fn(), server: { getClientCapabilities: () => ({}) } });
|
|
146
|
+
const args = { projectUuid: PROJECT, name: 'Analyst', enableDataAccess: true };
|
|
147
|
+
const preview = (0, test_support_js_1.parseAiAgentToolBody)(await previewHandler(args, { mcpReq: { envelope: {} } }));
|
|
148
|
+
(0, vitest_1.expect)(preview.data.createPreviewToken).toEqual(vitest_1.expect.any(String));
|
|
149
|
+
const confirm = (0, test_support_js_1.parseAiAgentToolBody)(await confirmHandler({
|
|
150
|
+
projectUuid: PROJECT,
|
|
151
|
+
name: 'Analyst',
|
|
152
|
+
createPreviewToken: preview.data.createPreviewToken,
|
|
153
|
+
}, { mcpReq: { envelope: {} } }));
|
|
154
|
+
(0, vitest_1.expect)(confirm.data.createConfirmToken).toEqual(vitest_1.expect.any(String));
|
|
155
|
+
const created = (0, test_support_js_1.parseAiAgentToolBody)(await createHandler(Object.assign(Object.assign({}, args), { createConfirmToken: confirm.data.createConfirmToken }), { mcpReq: { envelope: {} } }));
|
|
156
|
+
(0, vitest_1.expect)(createAgent).toHaveBeenCalledTimes(1);
|
|
157
|
+
(0, vitest_1.expect)(created.data).toEqual({ uuid: AGENT, name: 'Analyst' });
|
|
158
|
+
(0, vitest_1.expect)(created.warnings).toEqual(vitest_1.expect.arrayContaining([vitest_1.expect.objectContaining({ code: 'ELEVATED_DATA_ACCESS' })]));
|
|
159
|
+
});
|
|
160
|
+
(0, vitest_1.it)('preview_create_agent lists spaces once when spaceAccess is set', async () => {
|
|
161
|
+
const spaceUuid = '00000000-0000-4000-8000-000000000040';
|
|
162
|
+
const listSpacesInProject = vitest_1.vi.fn().mockResolvedValue([{ uuid: spaceUuid, name: 'Finance' }]);
|
|
163
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerPreviewCreateAgent, (0, test_support_js_1.mockAiAgentsContext)({ getExploreAccessSummary: vitest_1.vi.fn().mockResolvedValue([]) }, { listSpacesInProject }), 'preview_create_agent', { registerTool: vitest_1.vi.fn(), server: { getClientCapabilities: () => ({}) } });
|
|
164
|
+
const result = (0, test_support_js_1.parseAiAgentToolBody)(await handler({ projectUuid: PROJECT, name: 'Analyst', spaceAccess: [spaceUuid] }, { mcpReq: { envelope: {} } }));
|
|
165
|
+
(0, vitest_1.expect)(listSpacesInProject).toHaveBeenCalledTimes(1);
|
|
166
|
+
(0, vitest_1.expect)(result.warnings).toEqual([]);
|
|
167
|
+
});
|
|
168
|
+
(0, vitest_1.it)('returns InputRequiredResult on first call when form elicitation is present', async () => {
|
|
169
|
+
var _a;
|
|
170
|
+
const createAgent = vitest_1.vi.fn();
|
|
171
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([]);
|
|
172
|
+
const captureServer = {
|
|
173
|
+
registerTool: vitest_1.vi.fn(),
|
|
174
|
+
server: { getClientCapabilities: () => ({ elicitation: { form: {} } }) },
|
|
175
|
+
};
|
|
176
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'create_project_agent', captureServer);
|
|
177
|
+
const result = await handler({
|
|
178
|
+
projectUuid: PROJECT,
|
|
179
|
+
name: 'Analyst',
|
|
180
|
+
enableDataAccess: true,
|
|
181
|
+
tags: ['nope'],
|
|
182
|
+
}, formCapsServerContext());
|
|
183
|
+
(0, vitest_1.expect)((0, server_1.isInputRequiredResult)(result)).toBe(true);
|
|
184
|
+
if (!(0, server_1.isInputRequiredResult)(result)) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
(0, vitest_1.expect)(result.requestState).toEqual(vitest_1.expect.any(String));
|
|
188
|
+
(0, vitest_1.expect)((_a = result.inputRequests) === null || _a === void 0 ? void 0 : _a[create_elicitation_js_1.CONFIRM_CREATE_AGENT_INPUT_KEY]).toBeDefined();
|
|
189
|
+
(0, vitest_1.expect)(createAgent).not.toHaveBeenCalled();
|
|
190
|
+
(0, vitest_1.expect)(getExploreAccessSummary).toHaveBeenCalled();
|
|
191
|
+
});
|
|
192
|
+
(0, vitest_1.it)('creates after accept and warns when tags match no explores', async () => {
|
|
193
|
+
(0, create_request_state_js_1.resetCreateAgentRequestStateCodecForTests)();
|
|
194
|
+
process.env.NODE_ENV = 'test';
|
|
195
|
+
const createAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: AGENT, name: 'Analyst' });
|
|
196
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([]);
|
|
197
|
+
const captureServer = {
|
|
198
|
+
registerTool: vitest_1.vi.fn(),
|
|
199
|
+
server: { getClientCapabilities: () => ({ elicitation: { form: {} } }) },
|
|
200
|
+
};
|
|
201
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'create_project_agent', captureServer);
|
|
202
|
+
const args = {
|
|
203
|
+
projectUuid: PROJECT,
|
|
204
|
+
name: 'Analyst',
|
|
205
|
+
enableDataAccess: true,
|
|
206
|
+
tags: ['nope'],
|
|
207
|
+
};
|
|
208
|
+
const first = await handler(args, formCapsServerContext());
|
|
209
|
+
(0, vitest_1.expect)((0, server_1.isInputRequiredResult)(first)).toBe(true);
|
|
210
|
+
if (!(0, server_1.isInputRequiredResult)(first)) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const codec = (0, create_request_state_js_1.getCreateAgentRequestStateCodec)();
|
|
214
|
+
const serverContext = formCapsServerContext({
|
|
215
|
+
requestState: first.requestState,
|
|
216
|
+
inputResponses: {
|
|
217
|
+
[create_elicitation_js_1.CONFIRM_CREATE_AGENT_INPUT_KEY]: {
|
|
218
|
+
kind: 'elicit',
|
|
219
|
+
action: 'accept',
|
|
220
|
+
content: { decision: 'confirm_create' },
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
// Ensure codec can verify the minted token in the same test process
|
|
225
|
+
await codec.verify(String(first.requestState), serverContext);
|
|
226
|
+
const second = await handler(args, serverContext);
|
|
227
|
+
(0, vitest_1.expect)((0, server_1.isInputRequiredResult)(second)).toBe(false);
|
|
228
|
+
(0, vitest_1.expect)(createAgent).toHaveBeenCalledTimes(1);
|
|
229
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(second);
|
|
230
|
+
(0, vitest_1.expect)(body.data).toEqual({ uuid: AGENT, name: 'Analyst' });
|
|
231
|
+
(0, vitest_1.expect)(body.warnings).toEqual(vitest_1.expect.arrayContaining([
|
|
232
|
+
vitest_1.expect.objectContaining({ code: 'TAGS_MATCH_NO_EXPLORES' }),
|
|
233
|
+
vitest_1.expect.objectContaining({ code: 'ELEVATED_DATA_ACCESS' }),
|
|
234
|
+
]));
|
|
235
|
+
});
|
|
236
|
+
(0, vitest_1.it)('does not create when decision is do_not_create', async () => {
|
|
237
|
+
(0, create_request_state_js_1.resetCreateAgentRequestStateCodecForTests)();
|
|
238
|
+
process.env.NODE_ENV = 'test';
|
|
239
|
+
const createAgent = vitest_1.vi.fn();
|
|
240
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([{ exploreName: 'orders' }]);
|
|
241
|
+
const captureServer = {
|
|
242
|
+
registerTool: vitest_1.vi.fn(),
|
|
243
|
+
server: { getClientCapabilities: () => ({ elicitation: { form: {} } }) },
|
|
244
|
+
};
|
|
245
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'create_project_agent', captureServer);
|
|
246
|
+
const args = { projectUuid: PROJECT, name: 'Analyst', enableDataAccess: true };
|
|
247
|
+
const first = await handler(args, formCapsServerContext());
|
|
248
|
+
(0, vitest_1.expect)((0, server_1.isInputRequiredResult)(first)).toBe(true);
|
|
249
|
+
if (!(0, server_1.isInputRequiredResult)(first)) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const second = await handler(args, formCapsServerContext({
|
|
253
|
+
requestState: first.requestState,
|
|
254
|
+
inputResponses: {
|
|
255
|
+
[create_elicitation_js_1.CONFIRM_CREATE_AGENT_INPUT_KEY]: {
|
|
256
|
+
kind: 'elicit',
|
|
257
|
+
action: 'accept',
|
|
258
|
+
content: { decision: 'do_not_create' },
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
}));
|
|
262
|
+
(0, vitest_1.expect)(createAgent).not.toHaveBeenCalled();
|
|
263
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(second);
|
|
264
|
+
(0, vitest_1.expect)(body.status).toBe('declined');
|
|
265
|
+
(0, vitest_1.expect)(body.created).toBe(false);
|
|
266
|
+
});
|
|
267
|
+
(0, vitest_1.it)('blocks when payload changes after confirmation was minted', async () => {
|
|
268
|
+
(0, create_request_state_js_1.resetCreateAgentRequestStateCodecForTests)();
|
|
269
|
+
process.env.NODE_ENV = 'test';
|
|
270
|
+
const createAgent = vitest_1.vi.fn();
|
|
271
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([]);
|
|
272
|
+
const captureServer = {
|
|
273
|
+
registerTool: vitest_1.vi.fn(),
|
|
274
|
+
server: { getClientCapabilities: () => ({ elicitation: { form: {} } }) },
|
|
275
|
+
};
|
|
276
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'create_project_agent', captureServer);
|
|
277
|
+
const first = await handler({ projectUuid: PROJECT, name: 'Analyst', enableDataAccess: true }, formCapsServerContext());
|
|
278
|
+
(0, vitest_1.expect)((0, server_1.isInputRequiredResult)(first)).toBe(true);
|
|
279
|
+
if (!(0, server_1.isInputRequiredResult)(first)) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const second = await handler({ projectUuid: PROJECT, name: 'Analyst RENAMED', enableDataAccess: true }, formCapsServerContext({
|
|
283
|
+
requestState: first.requestState,
|
|
284
|
+
inputResponses: {
|
|
285
|
+
[create_elicitation_js_1.CONFIRM_CREATE_AGENT_INPUT_KEY]: {
|
|
286
|
+
kind: 'elicit',
|
|
287
|
+
action: 'accept',
|
|
288
|
+
content: { decision: 'confirm_create' },
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
}));
|
|
292
|
+
(0, vitest_1.expect)(createAgent).not.toHaveBeenCalled();
|
|
293
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(second);
|
|
294
|
+
(0, vitest_1.expect)(body.code).toBe('CONFIRMATION_INVALID');
|
|
295
|
+
});
|
|
296
|
+
(0, vitest_1.it)('decline action does not create', async () => {
|
|
297
|
+
(0, create_request_state_js_1.resetCreateAgentRequestStateCodecForTests)();
|
|
298
|
+
process.env.NODE_ENV = 'test';
|
|
299
|
+
const createAgent = vitest_1.vi.fn();
|
|
300
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([]);
|
|
301
|
+
const captureServer = {
|
|
302
|
+
registerTool: vitest_1.vi.fn(),
|
|
303
|
+
server: { getClientCapabilities: () => ({ elicitation: { form: {} } }) },
|
|
304
|
+
};
|
|
305
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent, getExploreAccessSummary }), 'create_project_agent', captureServer);
|
|
306
|
+
const token = await (0, create_request_state_js_1.mintCreateAgentRequestState)({
|
|
307
|
+
operationId: 'create_project_agent',
|
|
308
|
+
projectUuid: PROJECT,
|
|
309
|
+
payloadDigest: (0, create_elicitation_js_1.digestCreateAgentPayload)({ name: 'Analyst', enableDataAccess: true }),
|
|
310
|
+
subject: 'anonymous',
|
|
311
|
+
}, formCapsServerContext());
|
|
312
|
+
const result = await handler({ projectUuid: PROJECT, name: 'Analyst', enableDataAccess: true }, formCapsServerContext({
|
|
313
|
+
requestState: token,
|
|
314
|
+
inputResponses: {
|
|
315
|
+
[create_elicitation_js_1.CONFIRM_CREATE_AGENT_INPUT_KEY]: { kind: 'elicit', action: 'decline' },
|
|
316
|
+
},
|
|
317
|
+
}));
|
|
318
|
+
(0, vitest_1.expect)(createAgent).not.toHaveBeenCalled();
|
|
319
|
+
(0, vitest_1.expect)((0, test_support_js_1.parseAiAgentToolBody)(result).status).toBe('declined');
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
(0, vitest_1.describe)('update_project_agent tag warnings', () => {
|
|
323
|
+
(0, vitest_1.afterEach)(() => {
|
|
324
|
+
vitest_1.vi.restoreAllMocks();
|
|
325
|
+
});
|
|
326
|
+
(0, vitest_1.it)('warns when patch tags match no explores', async () => {
|
|
327
|
+
const updateAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: AGENT, tags: ['x'] });
|
|
328
|
+
const getExploreAccessSummary = vitest_1.vi.fn().mockResolvedValue([]);
|
|
329
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerUpdateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ updateAgent, getExploreAccessSummary }), 'update_project_agent');
|
|
330
|
+
const result = await handler({
|
|
331
|
+
projectUuid: PROJECT,
|
|
332
|
+
agentUuid: AGENT,
|
|
333
|
+
tags: ['x'],
|
|
334
|
+
});
|
|
335
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(result);
|
|
336
|
+
(0, vitest_1.expect)(updateAgent).toHaveBeenCalled();
|
|
337
|
+
(0, vitest_1.expect)(body.warnings).toEqual([vitest_1.expect.objectContaining({ code: 'TAGS_MATCH_NO_EXPLORES' })]);
|
|
338
|
+
});
|
|
339
|
+
(0, vitest_1.it)('skips explore summary when tags are omitted from the patch', async () => {
|
|
340
|
+
const updateAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: AGENT, instruction: 'Updated' });
|
|
341
|
+
const getExploreAccessSummary = vitest_1.vi.fn();
|
|
342
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerUpdateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ updateAgent, getExploreAccessSummary }), 'update_project_agent');
|
|
343
|
+
const result = await handler({
|
|
344
|
+
projectUuid: PROJECT,
|
|
345
|
+
agentUuid: AGENT,
|
|
346
|
+
instruction: 'Updated',
|
|
347
|
+
});
|
|
348
|
+
(0, vitest_1.expect)(getExploreAccessSummary).not.toHaveBeenCalled();
|
|
349
|
+
(0, vitest_1.expect)((0, test_support_js_1.parseAiAgentToolBody)(result).warnings).toEqual([]);
|
|
350
|
+
});
|
|
351
|
+
(0, vitest_1.it)('warns when patch elevates data access', async () => {
|
|
352
|
+
const updateAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: AGENT, enableDataAccess: true });
|
|
353
|
+
const getExploreAccessSummary = vitest_1.vi.fn();
|
|
354
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerUpdateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ updateAgent, getExploreAccessSummary }), 'update_project_agent');
|
|
355
|
+
const result = await handler({
|
|
356
|
+
projectUuid: PROJECT,
|
|
357
|
+
agentUuid: AGENT,
|
|
358
|
+
enableDataAccess: true,
|
|
359
|
+
});
|
|
360
|
+
const body = (0, test_support_js_1.parseAiAgentToolBody)(result);
|
|
361
|
+
(0, vitest_1.expect)(body.warnings).toEqual([vitest_1.expect.objectContaining({ code: 'ELEVATED_DATA_ACCESS' })]);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMAC-signed requestState for create_project_agent elicitation (ADR-0033 / ADR-0015 pattern).
|
|
3
|
+
*/
|
|
4
|
+
import type { RequestStateCodec, ServerContext } from '@modelcontextprotocol/server';
|
|
5
|
+
export declare const CREATE_AGENT_REQUEST_STATE_KEY_PURPOSE = "ai-agent-ops create_project_agent elicitation is enabled";
|
|
6
|
+
export declare const CREATE_PROJECT_AGENT_OPERATION_ID: "create_project_agent";
|
|
7
|
+
export type CreateAgentRequestState = {
|
|
8
|
+
operationId: typeof CREATE_PROJECT_AGENT_OPERATION_ID;
|
|
9
|
+
projectUuid: string;
|
|
10
|
+
payloadDigest: string;
|
|
11
|
+
subject: string;
|
|
12
|
+
};
|
|
13
|
+
declare function getCreateAgentRequestStateCodec(): RequestStateCodec<CreateAgentRequestState>;
|
|
14
|
+
/** Reset codec (tests only). */
|
|
15
|
+
export declare function resetCreateAgentRequestStateCodecForTests(): void;
|
|
16
|
+
export declare function mintCreateAgentRequestState(state: CreateAgentRequestState, serverContext: ServerContext): Promise<string>;
|
|
17
|
+
export declare function verifyCreateAgentRequestState(token: string | undefined, serverContext: ServerContext): Promise<CreateAgentRequestState | undefined>;
|
|
18
|
+
export { getCreateAgentRequestStateCodec };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HMAC-signed requestState for create_project_agent elicitation (ADR-0033 / ADR-0015 pattern).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CREATE_PROJECT_AGENT_OPERATION_ID = exports.CREATE_AGENT_REQUEST_STATE_KEY_PURPOSE = void 0;
|
|
7
|
+
exports.resetCreateAgentRequestStateCodecForTests = resetCreateAgentRequestStateCodecForTests;
|
|
8
|
+
exports.mintCreateAgentRequestState = mintCreateAgentRequestState;
|
|
9
|
+
exports.verifyCreateAgentRequestState = verifyCreateAgentRequestState;
|
|
10
|
+
exports.getCreateAgentRequestStateCodec = getCreateAgentRequestStateCodec;
|
|
11
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
12
|
+
const request_state_key_js_1 = require("../../auth/request-state-key.js");
|
|
13
|
+
exports.CREATE_AGENT_REQUEST_STATE_KEY_PURPOSE = 'ai-agent-ops create_project_agent elicitation is enabled';
|
|
14
|
+
exports.CREATE_PROJECT_AGENT_OPERATION_ID = 'create_project_agent';
|
|
15
|
+
const TTL_SECONDS = 10 * 60;
|
|
16
|
+
let codec;
|
|
17
|
+
function getCreateAgentRequestStateCodec() {
|
|
18
|
+
if (!codec) {
|
|
19
|
+
codec = (0, server_1.createRequestStateCodec)({
|
|
20
|
+
key: (0, request_state_key_js_1.resolveRequestStateKey)(exports.CREATE_AGENT_REQUEST_STATE_KEY_PURPOSE),
|
|
21
|
+
ttlSeconds: TTL_SECONDS,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return codec;
|
|
25
|
+
}
|
|
26
|
+
/** Reset codec (tests only). */
|
|
27
|
+
function resetCreateAgentRequestStateCodecForTests() {
|
|
28
|
+
codec = undefined;
|
|
29
|
+
}
|
|
30
|
+
async function mintCreateAgentRequestState(state, serverContext) {
|
|
31
|
+
return getCreateAgentRequestStateCodec().mint(state, serverContext);
|
|
32
|
+
}
|
|
33
|
+
async function verifyCreateAgentRequestState(token, serverContext) {
|
|
34
|
+
if (token === undefined || token.length === 0) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
return await getCreateAgentRequestStateCodec().verify(token, serverContext);
|
|
39
|
+
}
|
|
40
|
+
catch (_a) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI agent knowledge document tools (ai-agent-ops profile).
|
|
3
|
+
*/
|
|
4
|
+
import type { McpContextProvider } from '../../server/request-context.js';
|
|
5
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
+
export declare function registerListAgentDocuments(server: McpServer, contextProvider: McpContextProvider): void;
|
|
7
|
+
export declare function registerGetAgentDocument(server: McpServer, contextProvider: McpContextProvider): void;
|
|
8
|
+
export declare function registerCreateAgentDocument(server: McpServer, contextProvider: McpContextProvider): void;
|
|
9
|
+
export declare function registerUpdateAgentDocument(server: McpServer, contextProvider: McpContextProvider): void;
|
|
10
|
+
export declare function registerDeleteAgentDocument(server: McpServer, contextProvider: McpContextProvider): void;
|
|
11
|
+
export declare const listAgentDocumentsTool: import("../types.js").ToolModule;
|
|
12
|
+
export declare const getAgentDocumentTool: import("../types.js").ToolModule;
|
|
13
|
+
export declare const createAgentDocumentTool: import("../types.js").ToolModule;
|
|
14
|
+
export declare const updateAgentDocumentTool: import("../types.js").ToolModule;
|
|
15
|
+
export declare const deleteAgentDocumentTool: import("../types.js").ToolModule;
|