@jupiterone/jupiterone-mcp 0.2.2 → 0.3.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/server/mcp-server.d.ts +14 -7
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +71 -1656
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/tools/account.d.ts +3 -0
- package/dist/server/tools/account.d.ts.map +1 -0
- package/dist/server/tools/account.js +29 -0
- package/dist/server/tools/account.js.map +1 -0
- package/dist/server/tools/alerts.d.ts +3 -0
- package/dist/server/tools/alerts.d.ts.map +1 -0
- package/dist/server/tools/alerts.js +60 -0
- package/dist/server/tools/alerts.js.map +1 -0
- package/dist/server/tools/dashboards.d.ts +3 -0
- package/dist/server/tools/dashboards.d.ts.map +1 -0
- package/dist/server/tools/dashboards.js +224 -0
- package/dist/server/tools/dashboards.js.map +1 -0
- package/dist/server/tools/errors.d.ts +23 -0
- package/dist/server/tools/errors.d.ts.map +1 -0
- package/dist/server/tools/errors.js +64 -0
- package/dist/server/tools/errors.js.map +1 -0
- package/dist/server/tools/index.d.ts +4 -0
- package/dist/server/tools/index.d.ts.map +1 -0
- package/dist/server/tools/index.js +19 -0
- package/dist/server/tools/index.js.map +1 -0
- package/dist/server/tools/integrations.d.ts +3 -0
- package/dist/server/tools/integrations.d.ts.map +1 -0
- package/dist/server/tools/integrations.js +244 -0
- package/dist/server/tools/integrations.js.map +1 -0
- package/dist/server/tools/j1ql.d.ts +3 -0
- package/dist/server/tools/j1ql.d.ts.map +1 -0
- package/dist/server/tools/j1ql.js +69 -0
- package/dist/server/tools/j1ql.js.map +1 -0
- package/dist/server/tools/rules.d.ts +3 -0
- package/dist/server/tools/rules.d.ts.map +1 -0
- package/dist/server/tools/rules.js +536 -0
- package/dist/server/tools/rules.js.map +1 -0
- package/dist/server/tools/telemetry.d.ts +18 -0
- package/dist/server/tools/telemetry.d.ts.map +1 -0
- package/dist/server/tools/telemetry.js +12 -0
- package/dist/server/tools/telemetry.js.map +1 -0
- package/dist/server/tools/types.d.ts +42 -0
- package/dist/server/tools/types.d.ts.map +1 -0
- package/dist/server/tools/types.js +16 -0
- package/dist/server/tools/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -6,14 +6,17 @@ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
7
|
const jupiterone_client_js_1 = require("../client/jupiterone-client.js");
|
|
8
8
|
const package_json_1 = require("../../package.json");
|
|
9
|
-
const load_description_js_1 = require("../utils/load-description.js");
|
|
10
9
|
const j1ql_validator_js_1 = require("../utils/j1ql-validator.js");
|
|
10
|
+
const index_js_1 = require("./tools/index.js");
|
|
11
|
+
const errors_js_1 = require("./tools/errors.js");
|
|
12
|
+
const telemetry_js_1 = require("./tools/telemetry.js");
|
|
11
13
|
class JupiterOneMcpServer {
|
|
12
14
|
server;
|
|
13
15
|
client;
|
|
14
16
|
validator;
|
|
15
17
|
hasEnvironmentAccount;
|
|
16
|
-
|
|
18
|
+
telemetry;
|
|
19
|
+
constructor(config, options = {}) {
|
|
17
20
|
this.client = new jupiterone_client_js_1.JupiterOneClient(config);
|
|
18
21
|
this.validator = new j1ql_validator_js_1.J1QLValidator(this.client.j1qlService);
|
|
19
22
|
this.server = new mcp_js_1.McpServer({
|
|
@@ -21,1670 +24,82 @@ class JupiterOneMcpServer {
|
|
|
21
24
|
version: package_json_1.version,
|
|
22
25
|
});
|
|
23
26
|
this.hasEnvironmentAccount = !config.accountId;
|
|
24
|
-
this.
|
|
27
|
+
this.telemetry = options.telemetry ?? telemetry_js_1.stderrTelemetry;
|
|
28
|
+
for (const tool of index_js_1.allTools) {
|
|
29
|
+
this.register(tool);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Single registration chokepoint: injects the per-request `accountId` parameter when no env
|
|
34
|
+
* account is configured, then wraps every handler with account-scoped client cloning, sanitized
|
|
35
|
+
* error formatting (C2), and per-call telemetry (O1).
|
|
36
|
+
*/
|
|
37
|
+
register(tool) {
|
|
38
|
+
let inputSchema = tool.inputSchema;
|
|
29
39
|
if (this.hasEnvironmentAccount) {
|
|
30
|
-
|
|
31
|
-
...
|
|
40
|
+
inputSchema = {
|
|
41
|
+
...tool.inputSchema,
|
|
32
42
|
accountId: zod_1.z
|
|
33
43
|
.string()
|
|
34
44
|
.describe('JupiterOne Account ID for this request. This should be explicitly asked for with the first tool call.'),
|
|
35
45
|
};
|
|
36
46
|
}
|
|
37
|
-
this.server.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!accountId) {
|
|
45
|
-
return {
|
|
46
|
-
content: [
|
|
47
|
-
{
|
|
48
|
-
type: 'text',
|
|
49
|
-
text: 'Error: accountId is required for this operation because no default JUPITERONE_ACCOUNT_ID is configured.',
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
isError: true,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
client = this.client.cloneWithAccountId(accountId);
|
|
56
|
-
validator = new j1ql_validator_js_1.J1QLValidator(client.j1qlService);
|
|
57
|
-
toolParams = otherParams;
|
|
58
|
-
}
|
|
59
|
-
return handler(toolParams, client, validator);
|
|
60
|
-
});
|
|
47
|
+
const registerTool = this.server.registerTool.bind(this.server);
|
|
48
|
+
registerTool(tool.name, {
|
|
49
|
+
title: tool.title,
|
|
50
|
+
description: tool.description,
|
|
51
|
+
inputSchema,
|
|
52
|
+
annotations: tool.annotations,
|
|
53
|
+
}, (params) => this.invoke(tool, params));
|
|
61
54
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
text: JSON.stringify({
|
|
80
|
-
returned: instances.length,
|
|
81
|
-
rules: instances.map((instance) => ({
|
|
82
|
-
id: instance.id,
|
|
83
|
-
name: instance.name,
|
|
84
|
-
description: instance.description,
|
|
85
|
-
version: instance.version,
|
|
86
|
-
pollingInterval: instance.pollingInterval,
|
|
87
|
-
lastEvaluationStartOn: instance.lastEvaluationStartOn,
|
|
88
|
-
lastEvaluationEndOn: instance.lastEvaluationEndOn,
|
|
89
|
-
latestAlertId: instance.latestAlertId,
|
|
90
|
-
latestAlertIsActive: instance.latestAlertIsActive,
|
|
91
|
-
type: instance.type,
|
|
92
|
-
tags: instance.tags,
|
|
93
|
-
outputs: instance.outputs,
|
|
94
|
-
})),
|
|
95
|
-
pageInfo: response.pageInfo,
|
|
96
|
-
}),
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
return {
|
|
103
|
-
content: [
|
|
104
|
-
{
|
|
105
|
-
type: 'text',
|
|
106
|
-
text: `Error listing rules: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
isError: true,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
// Tool: Get rule details
|
|
115
|
-
this.registerTool({
|
|
116
|
-
name: 'get-rule-details',
|
|
117
|
-
description: (0, load_description_js_1.loadDescription)('get-rule-details.md'),
|
|
118
|
-
schema: {
|
|
119
|
-
ruleId: zod_1.z.string(),
|
|
120
|
-
},
|
|
121
|
-
handler: async ({ ruleId }, client) => {
|
|
122
|
-
try {
|
|
123
|
-
const instances = await client.getAllRuleInstances();
|
|
124
|
-
const rule = instances.find((instance) => instance.id === ruleId);
|
|
125
|
-
if (!rule) {
|
|
126
|
-
return {
|
|
127
|
-
content: [
|
|
128
|
-
{
|
|
129
|
-
type: 'text',
|
|
130
|
-
text: `Rule with ID ${ruleId} not found`,
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
isError: true,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
content: [
|
|
138
|
-
{
|
|
139
|
-
type: 'text',
|
|
140
|
-
text: JSON.stringify({
|
|
141
|
-
id: rule.id,
|
|
142
|
-
resourceGroupId: rule.resourceGroupId,
|
|
143
|
-
accountId: rule.accountId,
|
|
144
|
-
name: rule.name,
|
|
145
|
-
description: rule.description,
|
|
146
|
-
version: rule.version,
|
|
147
|
-
lastEvaluationStartOn: rule.lastEvaluationStartOn,
|
|
148
|
-
lastEvaluationEndOn: rule.lastEvaluationEndOn,
|
|
149
|
-
evaluationStep: rule.evaluationStep,
|
|
150
|
-
specVersion: rule.specVersion,
|
|
151
|
-
notifyOnFailure: rule.notifyOnFailure,
|
|
152
|
-
triggerActionsOnNewEntitiesOnly: rule.triggerActionsOnNewEntitiesOnly,
|
|
153
|
-
ignorePreviousResults: rule.ignorePreviousResults,
|
|
154
|
-
pollingInterval: rule.pollingInterval,
|
|
155
|
-
templates: rule.templates,
|
|
156
|
-
outputs: rule.outputs,
|
|
157
|
-
labels: rule.labels?.map((label) => ({
|
|
158
|
-
labelName: label.labelName,
|
|
159
|
-
labelValue: label.labelValue,
|
|
160
|
-
})) || [],
|
|
161
|
-
question: rule.question
|
|
162
|
-
? {
|
|
163
|
-
queries: rule.question.queries?.map((query) => ({
|
|
164
|
-
query: query.query,
|
|
165
|
-
name: query.name,
|
|
166
|
-
includeDeleted: query.includeDeleted,
|
|
167
|
-
})) || [],
|
|
168
|
-
}
|
|
169
|
-
: null,
|
|
170
|
-
questionId: rule.questionId,
|
|
171
|
-
latest: rule.latest,
|
|
172
|
-
deleted: rule.deleted,
|
|
173
|
-
type: rule.type,
|
|
174
|
-
operations: rule.operations?.map((op) => ({
|
|
175
|
-
when: op.when,
|
|
176
|
-
actions: op.actions,
|
|
177
|
-
})) || [],
|
|
178
|
-
latestAlertId: rule.latestAlertId,
|
|
179
|
-
latestAlertIsActive: rule.latestAlertIsActive,
|
|
180
|
-
state: rule.state
|
|
181
|
-
? {
|
|
182
|
-
actions: rule.state.actions,
|
|
183
|
-
}
|
|
184
|
-
: null,
|
|
185
|
-
tags: rule.tags,
|
|
186
|
-
remediationSteps: rule.remediationSteps,
|
|
187
|
-
}),
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
catch (error) {
|
|
193
|
-
return {
|
|
194
|
-
content: [
|
|
195
|
-
{
|
|
196
|
-
type: 'text',
|
|
197
|
-
text: `Error getting rule details: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
isError: true,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
// Tool: Test connection
|
|
206
|
-
this.registerTool({
|
|
207
|
-
name: 'test-connection',
|
|
208
|
-
description: (0, load_description_js_1.loadDescription)('test-connection.md'),
|
|
209
|
-
schema: {},
|
|
210
|
-
handler: async (_, client) => {
|
|
211
|
-
try {
|
|
212
|
-
const isConnected = await client.testConnection();
|
|
213
|
-
const accountInfo = isConnected ? await client.getAccountInfo() : null;
|
|
214
|
-
return {
|
|
215
|
-
content: [
|
|
216
|
-
{
|
|
217
|
-
type: 'text',
|
|
218
|
-
text: JSON.stringify({
|
|
219
|
-
connected: isConnected,
|
|
220
|
-
account: accountInfo,
|
|
221
|
-
version: package_json_1.version,
|
|
222
|
-
}),
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
catch (error) {
|
|
228
|
-
return {
|
|
229
|
-
content: [
|
|
230
|
-
{
|
|
231
|
-
type: 'text',
|
|
232
|
-
text: `Connection test failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
isError: true,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
// Tool: Evaluate rule
|
|
241
|
-
this.registerTool({
|
|
242
|
-
name: 'evaluate-rule',
|
|
243
|
-
description: (0, load_description_js_1.loadDescription)('evaluate-rule.md'),
|
|
244
|
-
schema: {
|
|
245
|
-
ruleId: zod_1.z.string(),
|
|
246
|
-
},
|
|
247
|
-
handler: async ({ ruleId }, client) => {
|
|
248
|
-
try {
|
|
249
|
-
const result = await client.evaluateRuleInstance(ruleId);
|
|
250
|
-
return {
|
|
251
|
-
content: [
|
|
252
|
-
{
|
|
253
|
-
type: 'text',
|
|
254
|
-
text: JSON.stringify({
|
|
255
|
-
ruleId,
|
|
256
|
-
id: result.id,
|
|
257
|
-
__typename: result.__typename,
|
|
258
|
-
}),
|
|
259
|
-
},
|
|
260
|
-
],
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
return {
|
|
265
|
-
content: [
|
|
266
|
-
{
|
|
267
|
-
type: 'text',
|
|
268
|
-
text: `Error evaluating rule: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
269
|
-
},
|
|
270
|
-
],
|
|
271
|
-
isError: true,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
});
|
|
276
|
-
// Tool: Get active alerts
|
|
277
|
-
this.registerTool({
|
|
278
|
-
name: 'get-active-alerts',
|
|
279
|
-
description: (0, load_description_js_1.loadDescription)('list-alerts.md'),
|
|
280
|
-
schema: {
|
|
281
|
-
limit: zod_1.z.number().min(1).max(1000).optional(),
|
|
282
|
-
},
|
|
283
|
-
handler: async ({ limit }, client) => {
|
|
284
|
-
try {
|
|
285
|
-
const instances = await client.getAllAlertInstances('ACTIVE');
|
|
286
|
-
if (!instances || !Array.isArray(instances)) {
|
|
287
|
-
throw new Error('Invalid response from JupiterOne API: instances is not an array');
|
|
288
|
-
}
|
|
289
|
-
const limitedInstances = limit ? instances.slice(0, limit) : instances;
|
|
290
|
-
return {
|
|
291
|
-
content: [
|
|
292
|
-
{
|
|
293
|
-
type: 'text',
|
|
294
|
-
text: JSON.stringify({
|
|
295
|
-
total: instances.length,
|
|
296
|
-
returned: limitedInstances.length,
|
|
297
|
-
activeAlerts: limitedInstances.map((instance) => ({
|
|
298
|
-
id: instance.id,
|
|
299
|
-
name: instance.questionRuleInstance?.name ||
|
|
300
|
-
instance.reportRuleInstance?.name ||
|
|
301
|
-
'Unknown',
|
|
302
|
-
description: instance.questionRuleInstance?.description ||
|
|
303
|
-
instance.reportRuleInstance?.description,
|
|
304
|
-
level: instance.level,
|
|
305
|
-
status: instance.status,
|
|
306
|
-
createdOn: instance.createdOn,
|
|
307
|
-
lastUpdatedOn: instance.lastUpdatedOn,
|
|
308
|
-
lastEvaluationBeginOn: instance.lastEvaluationBeginOn,
|
|
309
|
-
lastEvaluationEndOn: instance.lastEvaluationEndOn,
|
|
310
|
-
recordCount: instance.lastEvaluationResult?.rawDataDescriptors?.[0]?.recordCount || 0,
|
|
311
|
-
tags: instance.questionRuleInstance?.tags || [],
|
|
312
|
-
labels: instance.questionRuleInstance?.labels || [],
|
|
313
|
-
outputs: instance.lastEvaluationResult?.outputs || [],
|
|
314
|
-
users: instance.users,
|
|
315
|
-
ruleId: instance.ruleId,
|
|
316
|
-
ruleVersion: instance.ruleVersion,
|
|
317
|
-
endReason: instance.endReason,
|
|
318
|
-
dismissedOn: instance.dismissedOn,
|
|
319
|
-
})),
|
|
320
|
-
}),
|
|
321
|
-
},
|
|
322
|
-
],
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
catch (error) {
|
|
326
|
-
console.error('Error in get-active-alerts:', error);
|
|
327
|
-
return {
|
|
328
|
-
content: [
|
|
329
|
-
{
|
|
330
|
-
type: 'text',
|
|
331
|
-
text: `Error getting active alerts: ${error instanceof Error ? error.message : 'Unknown error'}. Please check your JupiterOne API credentials and connection.`,
|
|
332
|
-
},
|
|
333
|
-
],
|
|
334
|
-
isError: true,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
},
|
|
338
|
-
});
|
|
339
|
-
// Tool: Get dashboards
|
|
340
|
-
this.registerTool({
|
|
341
|
-
name: 'get-dashboards',
|
|
342
|
-
description: (0, load_description_js_1.loadDescription)('get-dashboards.md'),
|
|
343
|
-
schema: {},
|
|
344
|
-
handler: async (_, client) => {
|
|
345
|
-
try {
|
|
346
|
-
const dashboards = await client.getDashboards();
|
|
347
|
-
return {
|
|
348
|
-
content: [
|
|
349
|
-
{
|
|
350
|
-
type: 'text',
|
|
351
|
-
text: JSON.stringify({
|
|
352
|
-
total: dashboards.length,
|
|
353
|
-
dashboards: dashboards.map((dashboard) => ({
|
|
354
|
-
id: dashboard.id,
|
|
355
|
-
name: dashboard.name,
|
|
356
|
-
category: dashboard.category,
|
|
357
|
-
supportedUseCase: dashboard.supportedUseCase,
|
|
358
|
-
isJ1ManagedBoard: dashboard.isJ1ManagedBoard,
|
|
359
|
-
resourceGroupId: dashboard.resourceGroupId,
|
|
360
|
-
starred: dashboard.starred,
|
|
361
|
-
lastUpdated: dashboard._timeUpdated,
|
|
362
|
-
createdAt: dashboard._createdAt,
|
|
363
|
-
prerequisites: dashboard.prerequisites
|
|
364
|
-
? {
|
|
365
|
-
prerequisitesMet: dashboard.prerequisites.prerequisitesMet,
|
|
366
|
-
preRequisitesGroupsFulfilled: dashboard.prerequisites.preRequisitesGroupsFulfilled,
|
|
367
|
-
preRequisitesGroupsRequired: dashboard.prerequisites.preRequisitesGroupsRequired,
|
|
368
|
-
}
|
|
369
|
-
: null,
|
|
370
|
-
})),
|
|
371
|
-
}),
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
catch (error) {
|
|
377
|
-
return {
|
|
378
|
-
content: [
|
|
379
|
-
{
|
|
380
|
-
type: 'text',
|
|
381
|
-
text: `Error getting dashboards: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
382
|
-
},
|
|
383
|
-
],
|
|
384
|
-
isError: true,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
});
|
|
389
|
-
// Tool: Create dashboard
|
|
390
|
-
this.registerTool({
|
|
391
|
-
name: 'create-dashboard',
|
|
392
|
-
description: (0, load_description_js_1.loadDescription)('create-dashboard.md'),
|
|
393
|
-
schema: {
|
|
394
|
-
name: zod_1.z.string(),
|
|
395
|
-
type: zod_1.z.string(),
|
|
396
|
-
},
|
|
397
|
-
handler: async ({ name, type }, client) => {
|
|
398
|
-
try {
|
|
399
|
-
const result = await client.createDashboard({ name, type });
|
|
400
|
-
// Get account info to construct the URL
|
|
401
|
-
const accountInfo = await client.getAccountInfo();
|
|
402
|
-
const dashboardUrl = client.dashboardService.constructDashboardUrl(result.id, accountInfo.subdomain);
|
|
403
|
-
return {
|
|
404
|
-
content: [
|
|
405
|
-
{
|
|
406
|
-
type: 'text',
|
|
407
|
-
text: JSON.stringify({
|
|
408
|
-
id: result.id,
|
|
409
|
-
name,
|
|
410
|
-
type,
|
|
411
|
-
url: dashboardUrl,
|
|
412
|
-
}),
|
|
413
|
-
},
|
|
414
|
-
],
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
catch (error) {
|
|
418
|
-
return {
|
|
419
|
-
content: [
|
|
420
|
-
{
|
|
421
|
-
type: 'text',
|
|
422
|
-
text: `Error creating dashboard: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
423
|
-
},
|
|
424
|
-
],
|
|
425
|
-
isError: true,
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
},
|
|
429
|
-
});
|
|
430
|
-
// Tool: Get dashboard details
|
|
431
|
-
this.registerTool({
|
|
432
|
-
name: 'get-dashboard-details',
|
|
433
|
-
description: (0, load_description_js_1.loadDescription)('get-dashboard-details.md'),
|
|
434
|
-
schema: {
|
|
435
|
-
dashboardId: zod_1.z.string(),
|
|
436
|
-
},
|
|
437
|
-
handler: async ({ dashboardId }, client) => {
|
|
438
|
-
try {
|
|
439
|
-
const dashboard = await client.getDashboard(dashboardId);
|
|
440
|
-
return {
|
|
441
|
-
content: [
|
|
442
|
-
{
|
|
443
|
-
type: 'text',
|
|
444
|
-
text: JSON.stringify({
|
|
445
|
-
id: dashboard.id,
|
|
446
|
-
name: dashboard.name,
|
|
447
|
-
category: dashboard.category,
|
|
448
|
-
supportedUseCase: dashboard.supportedUseCase,
|
|
449
|
-
isJ1ManagedBoard: dashboard.isJ1ManagedBoard,
|
|
450
|
-
published: dashboard.published,
|
|
451
|
-
publishedToUserIds: dashboard.publishedToUserIds,
|
|
452
|
-
publishedToGroupIds: dashboard.publishedToGroupIds,
|
|
453
|
-
groupIds: dashboard.groupIds,
|
|
454
|
-
userIds: dashboard.userIds,
|
|
455
|
-
scopeFilters: dashboard.scopeFilters,
|
|
456
|
-
resourceGroupId: dashboard.resourceGroupId,
|
|
457
|
-
starred: dashboard.starred,
|
|
458
|
-
lastUpdated: dashboard._timeUpdated,
|
|
459
|
-
createdAt: dashboard._createdAt,
|
|
460
|
-
prerequisites: dashboard.prerequisites
|
|
461
|
-
? {
|
|
462
|
-
prerequisitesMet: dashboard.prerequisites.prerequisitesMet,
|
|
463
|
-
preRequisitesGroupsFulfilled: dashboard.prerequisites.preRequisitesGroupsFulfilled,
|
|
464
|
-
preRequisitesGroupsRequired: dashboard.prerequisites.preRequisitesGroupsRequired,
|
|
465
|
-
}
|
|
466
|
-
: null,
|
|
467
|
-
parameters: dashboard.parameters.map((param) => ({
|
|
468
|
-
id: param.id,
|
|
469
|
-
label: param.label,
|
|
470
|
-
name: param.name,
|
|
471
|
-
type: param.type,
|
|
472
|
-
valueType: param.valueType,
|
|
473
|
-
default: param.default,
|
|
474
|
-
options: param.options,
|
|
475
|
-
requireValue: param.requireValue,
|
|
476
|
-
disableCustomInput: param.disableCustomInput,
|
|
477
|
-
})),
|
|
478
|
-
widgets: dashboard.widgets.map((widget) => ({
|
|
479
|
-
id: widget.id,
|
|
480
|
-
title: widget.title,
|
|
481
|
-
description: widget.description,
|
|
482
|
-
type: widget.type,
|
|
483
|
-
questionId: widget.questionId,
|
|
484
|
-
noResultMessage: widget.noResultMessage,
|
|
485
|
-
includeDeleted: widget.includeDeleted,
|
|
486
|
-
config: {
|
|
487
|
-
queries: widget.config.queries.map((query) => ({
|
|
488
|
-
id: query.id,
|
|
489
|
-
name: query.name,
|
|
490
|
-
query: query.query,
|
|
491
|
-
})),
|
|
492
|
-
settings: widget.config.settings,
|
|
493
|
-
postQueryFilters: widget.config.postQueryFilters,
|
|
494
|
-
disableQueryPolicyFilters: widget.config.disableQueryPolicyFilters,
|
|
495
|
-
},
|
|
496
|
-
})),
|
|
497
|
-
layouts: {
|
|
498
|
-
xs: dashboard.layouts.xs.map((item) => ({
|
|
499
|
-
i: item.i,
|
|
500
|
-
x: item.x,
|
|
501
|
-
y: item.y,
|
|
502
|
-
w: item.w,
|
|
503
|
-
h: item.h,
|
|
504
|
-
static: item.static,
|
|
505
|
-
moved: item.moved,
|
|
506
|
-
})),
|
|
507
|
-
sm: dashboard.layouts.sm.map((item) => ({
|
|
508
|
-
i: item.i,
|
|
509
|
-
x: item.x,
|
|
510
|
-
y: item.y,
|
|
511
|
-
w: item.w,
|
|
512
|
-
h: item.h,
|
|
513
|
-
static: item.static,
|
|
514
|
-
moved: item.moved,
|
|
515
|
-
})),
|
|
516
|
-
md: dashboard.layouts.md.map((item) => ({
|
|
517
|
-
i: item.i,
|
|
518
|
-
x: item.x,
|
|
519
|
-
y: item.y,
|
|
520
|
-
w: item.w,
|
|
521
|
-
h: item.h,
|
|
522
|
-
static: item.static,
|
|
523
|
-
moved: item.moved,
|
|
524
|
-
})),
|
|
525
|
-
lg: dashboard.layouts.lg.map((item) => ({
|
|
526
|
-
i: item.i,
|
|
527
|
-
x: item.x,
|
|
528
|
-
y: item.y,
|
|
529
|
-
w: item.w,
|
|
530
|
-
h: item.h,
|
|
531
|
-
static: item.static,
|
|
532
|
-
moved: item.moved,
|
|
533
|
-
})),
|
|
534
|
-
xl: dashboard.layouts.xl.map((item) => ({
|
|
535
|
-
i: item.i,
|
|
536
|
-
x: item.x,
|
|
537
|
-
y: item.y,
|
|
538
|
-
w: item.w,
|
|
539
|
-
h: item.h,
|
|
540
|
-
static: item.static,
|
|
541
|
-
moved: item.moved,
|
|
542
|
-
})),
|
|
543
|
-
},
|
|
544
|
-
}),
|
|
545
|
-
},
|
|
546
|
-
],
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
catch (error) {
|
|
550
|
-
return {
|
|
551
|
-
content: [
|
|
552
|
-
{
|
|
553
|
-
type: 'text',
|
|
554
|
-
text: `Error getting dashboard details: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
555
|
-
},
|
|
556
|
-
],
|
|
557
|
-
isError: true,
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
},
|
|
561
|
-
});
|
|
562
|
-
// Tool: Get integration definitions
|
|
563
|
-
this.registerTool({
|
|
564
|
-
name: 'get-integration-definitions',
|
|
565
|
-
description: (0, load_description_js_1.loadDescription)('get-integration-definitions.md'),
|
|
566
|
-
schema: {
|
|
567
|
-
cursor: zod_1.z.string().optional().describe('Optional cursor for pagination'),
|
|
568
|
-
includeConfig: zod_1.z.boolean().optional().describe('Whether to include configuration fields'),
|
|
569
|
-
},
|
|
570
|
-
handler: async ({ cursor, includeConfig }, client) => {
|
|
571
|
-
try {
|
|
572
|
-
const definitions = await client.getIntegrationDefinitions(cursor, includeConfig);
|
|
573
|
-
return {
|
|
574
|
-
content: [
|
|
575
|
-
{
|
|
576
|
-
type: 'text',
|
|
577
|
-
text: JSON.stringify({
|
|
578
|
-
total: definitions.definitions.length,
|
|
579
|
-
definitions: definitions.definitions.map((def) => ({
|
|
580
|
-
id: def.id,
|
|
581
|
-
name: def.name,
|
|
582
|
-
type: def.type,
|
|
583
|
-
title: def.title,
|
|
584
|
-
displayMode: def.displayMode,
|
|
585
|
-
integrationType: def.integrationType,
|
|
586
|
-
integrationClass: def.integrationClass,
|
|
587
|
-
integrationCategory: def.integrationCategory,
|
|
588
|
-
beta: def.beta,
|
|
589
|
-
docsWebLink: def.docsWebLink,
|
|
590
|
-
repoWebLink: def.repoWebLink,
|
|
591
|
-
invocationPaused: def.invocationPaused,
|
|
592
|
-
managedExecutionDisabled: def.managedExecutionDisabled,
|
|
593
|
-
managedCreateDisabled: def.managedCreateDisabled,
|
|
594
|
-
managedDeleteDisabled: def.managedDeleteDisabled,
|
|
595
|
-
totalInstanceCount: def.totalInstanceCount,
|
|
596
|
-
description: def.description,
|
|
597
|
-
provisioningType: def.provisioningType,
|
|
598
|
-
customDefinitionType: def.customDefinitionType,
|
|
599
|
-
integrationPlatformFeatures: def.integrationPlatformFeatures,
|
|
600
|
-
configFields: def.configFields,
|
|
601
|
-
authSections: def.authSections,
|
|
602
|
-
configSections: def.configSections,
|
|
603
|
-
})),
|
|
604
|
-
pageInfo: definitions.pageInfo,
|
|
605
|
-
}),
|
|
606
|
-
},
|
|
607
|
-
],
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
catch (error) {
|
|
611
|
-
return {
|
|
612
|
-
content: [
|
|
613
|
-
{
|
|
614
|
-
type: 'text',
|
|
615
|
-
text: `Error getting integration definitions: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
616
|
-
},
|
|
617
|
-
],
|
|
618
|
-
isError: true,
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
},
|
|
622
|
-
});
|
|
623
|
-
// Tool: Get integration instances
|
|
624
|
-
this.registerTool({
|
|
625
|
-
name: 'get-integration-instances',
|
|
626
|
-
description: (0, load_description_js_1.loadDescription)('get-integration-instances.md'),
|
|
627
|
-
schema: {
|
|
628
|
-
definitionId: zod_1.z
|
|
629
|
-
.string()
|
|
630
|
-
.optional()
|
|
631
|
-
.describe('Optional ID to filter instances by definition'),
|
|
632
|
-
limit: zod_1.z
|
|
633
|
-
.number()
|
|
634
|
-
.min(1)
|
|
635
|
-
.max(1000)
|
|
636
|
-
.optional()
|
|
637
|
-
.describe('Optional limit for number of instances to return'),
|
|
638
|
-
cursor: zod_1.z
|
|
639
|
-
.string()
|
|
640
|
-
.optional()
|
|
641
|
-
.describe('Optional cursor for pagination; pass the endCursor from a previous response'),
|
|
642
|
-
},
|
|
643
|
-
handler: async ({ definitionId, limit, cursor }, client) => {
|
|
644
|
-
try {
|
|
645
|
-
const instances = await client.getIntegrationInstances(definitionId, cursor, limit);
|
|
646
|
-
return {
|
|
647
|
-
content: [
|
|
648
|
-
{
|
|
649
|
-
type: 'text',
|
|
650
|
-
text: JSON.stringify({
|
|
651
|
-
total: instances.instances.length,
|
|
652
|
-
instances: instances.instances.map((instance) => ({
|
|
653
|
-
id: instance.id,
|
|
654
|
-
name: instance.name,
|
|
655
|
-
accountId: instance.accountId,
|
|
656
|
-
sourceIntegrationInstanceId: instance.sourceIntegrationInstanceId,
|
|
657
|
-
pollingInterval: instance.pollingInterval,
|
|
658
|
-
pollingIntervalCronExpression: instance.pollingIntervalCronExpression,
|
|
659
|
-
integrationDefinitionId: instance.integrationDefinitionId,
|
|
660
|
-
description: instance.description,
|
|
661
|
-
config: instance.config,
|
|
662
|
-
instanceRelationship: instance.instanceRelationship,
|
|
663
|
-
resourceGroupId: instance.resourceGroupId,
|
|
664
|
-
createdOn: instance.createdOn,
|
|
665
|
-
createdBy: instance.createdBy,
|
|
666
|
-
updatedOn: instance.updatedOn,
|
|
667
|
-
updatedBy: instance.updatedBy,
|
|
668
|
-
mostRecentJob: instance.mostRecentJob
|
|
669
|
-
? {
|
|
670
|
-
status: instance.mostRecentJob.status,
|
|
671
|
-
hasSkippedSteps: instance.mostRecentJob.hasSkippedSteps,
|
|
672
|
-
createDate: instance.mostRecentJob.createDate,
|
|
673
|
-
}
|
|
674
|
-
: null,
|
|
675
|
-
})),
|
|
676
|
-
pageInfo: instances.pageInfo,
|
|
677
|
-
}),
|
|
678
|
-
},
|
|
679
|
-
],
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
catch (error) {
|
|
683
|
-
return {
|
|
684
|
-
content: [
|
|
685
|
-
{
|
|
686
|
-
type: 'text',
|
|
687
|
-
text: `Error getting integration instances: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
688
|
-
},
|
|
689
|
-
],
|
|
690
|
-
isError: true,
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
},
|
|
694
|
-
});
|
|
695
|
-
// Tool: Get integration jobs
|
|
696
|
-
this.registerTool({
|
|
697
|
-
name: 'get-integration-jobs',
|
|
698
|
-
description: (0, load_description_js_1.loadDescription)('get-integration-jobs.md'),
|
|
699
|
-
schema: {
|
|
700
|
-
status: zod_1.z
|
|
701
|
-
.enum(['PENDING', 'RUNNING', 'COMPLETED', 'FAILED', 'CANCELLED'])
|
|
702
|
-
.optional()
|
|
703
|
-
.describe('Optional status to filter jobs'),
|
|
704
|
-
integrationInstanceId: zod_1.z
|
|
705
|
-
.string()
|
|
706
|
-
.optional()
|
|
707
|
-
.describe('Optional ID to filter jobs by instance'),
|
|
708
|
-
integrationDefinitionId: zod_1.z
|
|
709
|
-
.string()
|
|
710
|
-
.optional()
|
|
711
|
-
.describe('Optional ID to filter jobs by definition'),
|
|
712
|
-
integrationInstanceIds: zod_1.z
|
|
713
|
-
.array(zod_1.z.string())
|
|
714
|
-
.optional()
|
|
715
|
-
.describe('Optional array of instance IDs to filter jobs'),
|
|
716
|
-
size: zod_1.z
|
|
717
|
-
.number()
|
|
718
|
-
.min(1)
|
|
719
|
-
.max(1000)
|
|
720
|
-
.optional()
|
|
721
|
-
.describe('Optional size limit for number of jobs to return'),
|
|
722
|
-
cursor: zod_1.z
|
|
723
|
-
.string()
|
|
724
|
-
.optional()
|
|
725
|
-
.describe('Optional cursor for pagination; pass the endCursor from a previous response'),
|
|
726
|
-
},
|
|
727
|
-
handler: async ({ status, integrationInstanceId, integrationDefinitionId, integrationInstanceIds, size, cursor, }, client) => {
|
|
728
|
-
try {
|
|
729
|
-
const jobs = await client.getIntegrationJobs(status, integrationInstanceId, integrationDefinitionId, integrationInstanceIds, cursor, size);
|
|
730
|
-
return {
|
|
731
|
-
content: [
|
|
732
|
-
{
|
|
733
|
-
type: 'text',
|
|
734
|
-
text: JSON.stringify({
|
|
735
|
-
total: jobs.jobs.length,
|
|
736
|
-
jobs: jobs.jobs.map((job) => ({
|
|
737
|
-
id: job.id,
|
|
738
|
-
status: job.status,
|
|
739
|
-
integrationInstanceId: job.integrationInstanceId,
|
|
740
|
-
createDate: job.createDate,
|
|
741
|
-
endDate: job.endDate,
|
|
742
|
-
hasSkippedSteps: job.hasSkippedSteps,
|
|
743
|
-
integrationInstance: job.integrationInstance,
|
|
744
|
-
integrationDefinition: job.integrationDefinition,
|
|
745
|
-
})),
|
|
746
|
-
pageInfo: jobs.pageInfo,
|
|
747
|
-
}),
|
|
748
|
-
},
|
|
749
|
-
],
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
catch (error) {
|
|
753
|
-
return {
|
|
754
|
-
content: [
|
|
755
|
-
{
|
|
756
|
-
type: 'text',
|
|
757
|
-
text: `Error getting integration jobs: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
758
|
-
},
|
|
759
|
-
],
|
|
760
|
-
isError: true,
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
},
|
|
764
|
-
});
|
|
765
|
-
// Shared action schema for rule tools (uses z.lazy for recursive FOR_EACH_ITEM support)
|
|
766
|
-
const actionSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
767
|
-
id: zod_1.z.string().optional(),
|
|
768
|
-
type: zod_1.z
|
|
769
|
-
.string()
|
|
770
|
-
.describe('Action type (e.g., SET_PROPERTY, CREATE_ALERT, SEND_EMAIL, WEBHOOK, FOR_EACH_ITEM)'),
|
|
771
|
-
targetProperty: zod_1.z
|
|
772
|
-
.string()
|
|
773
|
-
.optional()
|
|
774
|
-
.describe('Property to set (for SET_PROPERTY actions)'),
|
|
775
|
-
targetValue: zod_1.z.any().optional().describe('Value to set (for SET_PROPERTY actions)'),
|
|
776
|
-
integrationInstanceId: zod_1.z
|
|
777
|
-
.string()
|
|
778
|
-
.optional()
|
|
779
|
-
.describe('ID of the integration instance for integration actions'),
|
|
780
|
-
recipients: zod_1.z
|
|
781
|
-
.array(zod_1.z.string())
|
|
782
|
-
.optional()
|
|
783
|
-
.describe('Email recipients for SEND_EMAIL action'),
|
|
784
|
-
body: zod_1.z
|
|
785
|
-
.union([zod_1.z.string(), zod_1.z.record(zod_1.z.any())])
|
|
786
|
-
.optional()
|
|
787
|
-
.describe('Message body for email/slack/webhook actions'),
|
|
788
|
-
channels: zod_1.z
|
|
789
|
-
.array(zod_1.z.string())
|
|
790
|
-
.optional()
|
|
791
|
-
.describe('Slack channels for SEND_SLACK_MESSAGE action'),
|
|
792
|
-
bucket: zod_1.z.string().optional().describe('S3 bucket name for SEND_TO_S3 action'),
|
|
793
|
-
region: zod_1.z.string().optional().describe('AWS region for SEND_TO_S3 action'),
|
|
794
|
-
data: zod_1.z.any().optional().describe('Additional data for actions'),
|
|
795
|
-
entityClass: zod_1.z
|
|
796
|
-
.string()
|
|
797
|
-
.optional()
|
|
798
|
-
.describe('Entity class for CREATE_JIRA_TICKET action'),
|
|
799
|
-
summary: zod_1.z.string().optional().describe('Summary for CREATE_JIRA_TICKET action'),
|
|
800
|
-
issueType: zod_1.z.string().optional().describe('Issue type for CREATE_JIRA_TICKET action'),
|
|
801
|
-
project: zod_1.z.string().optional().describe('Project key for CREATE_JIRA_TICKET action'),
|
|
802
|
-
updateContentOnChanges: zod_1.z
|
|
803
|
-
.boolean()
|
|
804
|
-
.optional()
|
|
805
|
-
.describe('Whether to update content on changes for CREATE_JIRA_TICKET action'),
|
|
806
|
-
additionalFields: zod_1.z
|
|
807
|
-
.any()
|
|
808
|
-
.optional()
|
|
809
|
-
.describe('Additional fields for CREATE_JIRA_TICKET action'),
|
|
810
|
-
autoResolve: zod_1.z
|
|
811
|
-
.boolean()
|
|
812
|
-
.optional()
|
|
813
|
-
.describe('Auto-resolve Jira ticket when entity no longer matches (CREATE_JIRA_TICKET)'),
|
|
814
|
-
resolvedStatus: zod_1.z
|
|
815
|
-
.string()
|
|
816
|
-
.optional()
|
|
817
|
-
.describe('Status to transition to on auto-resolve, e.g. "Closed" (CREATE_JIRA_TICKET)'),
|
|
818
|
-
entities: zod_1.z.string().optional().describe('Entities for TAG_ENTITIES action'),
|
|
819
|
-
tags: zod_1.z
|
|
820
|
-
.array(zod_1.z.object({
|
|
821
|
-
name: zod_1.z.string(),
|
|
822
|
-
value: zod_1.z.string().nullable(),
|
|
823
|
-
}))
|
|
824
|
-
.optional()
|
|
825
|
-
.describe('Tags for TAG_ENTITIES action'),
|
|
826
|
-
method: zod_1.z
|
|
827
|
-
.string()
|
|
828
|
-
.optional()
|
|
829
|
-
.describe('HTTP method for WEBHOOK action (e.g., POST, GET)'),
|
|
830
|
-
endpoint: zod_1.z.string().optional().describe('Webhook URL endpoint for WEBHOOK action'),
|
|
831
|
-
headers: zod_1.z.record(zod_1.z.string()).optional().describe('HTTP headers for WEBHOOK action'),
|
|
832
|
-
items: zod_1.z
|
|
833
|
-
.string()
|
|
834
|
-
.optional()
|
|
835
|
-
.describe('Template reference to iterate over for FOR_EACH_ITEM (e.g., "{{queries.query0.data}}")'),
|
|
836
|
-
itemRef: zod_1.z
|
|
837
|
-
.string()
|
|
838
|
-
.optional()
|
|
839
|
-
.describe('Variable name for current item in FOR_EACH_ITEM loop (e.g., "result")'),
|
|
840
|
-
actions: zod_1.z
|
|
841
|
-
.array(actionSchema)
|
|
842
|
-
.optional()
|
|
843
|
-
.describe('Nested actions to execute for each item in FOR_EACH_ITEM'),
|
|
844
|
-
}));
|
|
845
|
-
// Tool: Create inline question rule instance
|
|
846
|
-
this.registerTool({
|
|
847
|
-
name: 'create-inline-question-rule',
|
|
848
|
-
description: (0, load_description_js_1.loadDescription)('create-inline-question-rule.md'),
|
|
849
|
-
schema: {
|
|
850
|
-
name: zod_1.z.string().describe('Name of the rule'),
|
|
851
|
-
description: zod_1.z.string().describe('Description of the rule'),
|
|
852
|
-
notifyOnFailure: zod_1.z.boolean().optional().describe('Whether to notify on failure'),
|
|
853
|
-
triggerActionsOnNewEntitiesOnly: zod_1.z
|
|
854
|
-
.boolean()
|
|
855
|
-
.optional()
|
|
856
|
-
.describe('Whether to trigger actions only on new entities'),
|
|
857
|
-
ignorePreviousResults: zod_1.z
|
|
858
|
-
.boolean()
|
|
859
|
-
.optional()
|
|
860
|
-
.describe('Whether to ignore previous results'),
|
|
861
|
-
pollingInterval: zod_1.z
|
|
862
|
-
.enum([
|
|
863
|
-
'DISABLED',
|
|
864
|
-
'THIRTY_MINUTES',
|
|
865
|
-
'ONE_HOUR',
|
|
866
|
-
'FOUR_HOURS',
|
|
867
|
-
'EIGHT_HOURS',
|
|
868
|
-
'TWELVE_HOURS',
|
|
869
|
-
'ONE_DAY',
|
|
870
|
-
'ONE_WEEK',
|
|
871
|
-
])
|
|
872
|
-
.describe('How frequently to evaluate the rule'),
|
|
873
|
-
outputs: zod_1.z.array(zod_1.z.string()).describe('Output fields from the rule evaluation'),
|
|
874
|
-
specVersion: zod_1.z.number().optional().describe('Specification version'),
|
|
875
|
-
tags: zod_1.z.array(zod_1.z.string()).optional().describe('Tags for categorizing the rule'),
|
|
876
|
-
templates: zod_1.z.record(zod_1.z.any()).optional().describe('Template variables'),
|
|
877
|
-
question: zod_1.z
|
|
878
|
-
.object({
|
|
879
|
-
queries: zod_1.z.array(zod_1.z.object({
|
|
880
|
-
query: zod_1.z.string().describe('J1QL query string'),
|
|
881
|
-
name: zod_1.z.string().describe('Name identifier for the query'),
|
|
882
|
-
version: zod_1.z.string().optional().describe('Version of the query'),
|
|
883
|
-
includeDeleted: zod_1.z.boolean().describe('Whether to include deleted entities'),
|
|
884
|
-
})),
|
|
885
|
-
})
|
|
886
|
-
.describe('Question configuration'),
|
|
887
|
-
labels: zod_1.z
|
|
888
|
-
.array(zod_1.z.object({
|
|
889
|
-
labelName: zod_1.z.string(),
|
|
890
|
-
labelValue: zod_1.z.string().nullable(),
|
|
891
|
-
}))
|
|
892
|
-
.describe('Labels for the rule'),
|
|
893
|
-
operations: zod_1.z
|
|
894
|
-
.array(zod_1.z.object({
|
|
895
|
-
when: zod_1.z
|
|
896
|
-
.object({
|
|
897
|
-
type: zod_1.z.literal('FILTER'),
|
|
898
|
-
condition: zod_1.z
|
|
899
|
-
.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number()]))]))
|
|
900
|
-
.describe('Filter condition array (e.g., ["AND", ["queries.query0.total", ">", 0]])'),
|
|
901
|
-
})
|
|
902
|
-
.describe('Condition that triggers the actions'),
|
|
903
|
-
actions: zod_1.z.array(actionSchema).describe('Actions to take when condition is met'),
|
|
904
|
-
}))
|
|
905
|
-
.describe('Operations to perform when conditions are met'),
|
|
906
|
-
},
|
|
907
|
-
handler: async ({ name, description, notifyOnFailure, triggerActionsOnNewEntitiesOnly, ignorePreviousResults, pollingInterval, outputs, specVersion, labels, tags, templates, question, operations, }, client, validator) => {
|
|
908
|
-
try {
|
|
909
|
-
// Validate all queries before creating the rule
|
|
910
|
-
const validationResults = await this.validateQueries(question.queries, validator);
|
|
911
|
-
if (validationResults.length > 0) {
|
|
912
|
-
return this.createValidationErrorResponse(validationResults);
|
|
913
|
-
}
|
|
914
|
-
const instance = {
|
|
915
|
-
name,
|
|
916
|
-
description,
|
|
917
|
-
notifyOnFailure,
|
|
918
|
-
triggerActionsOnNewEntitiesOnly,
|
|
919
|
-
ignorePreviousResults,
|
|
920
|
-
pollingInterval,
|
|
921
|
-
outputs,
|
|
922
|
-
specVersion,
|
|
923
|
-
labels,
|
|
924
|
-
tags,
|
|
925
|
-
templates,
|
|
926
|
-
question,
|
|
927
|
-
operations,
|
|
928
|
-
};
|
|
929
|
-
const result = await client.createInlineQuestionRuleInstance(instance);
|
|
930
|
-
// Get account info to construct the URL
|
|
931
|
-
const accountInfo = await client.getAccountInfo();
|
|
932
|
-
const ruleUrl = client.ruleService.constructRuleUrl(result.id, accountInfo.subdomain);
|
|
933
|
-
return {
|
|
934
|
-
content: [
|
|
935
|
-
{
|
|
936
|
-
type: 'text',
|
|
937
|
-
text: JSON.stringify({
|
|
938
|
-
success: true,
|
|
939
|
-
rule: {
|
|
940
|
-
id: result.id,
|
|
941
|
-
name: result.name,
|
|
942
|
-
description: result.description,
|
|
943
|
-
version: result.version,
|
|
944
|
-
pollingInterval: result.pollingInterval,
|
|
945
|
-
outputs: result.outputs,
|
|
946
|
-
specVersion: result.specVersion,
|
|
947
|
-
notifyOnFailure: result.notifyOnFailure,
|
|
948
|
-
triggerActionsOnNewEntitiesOnly: result.triggerActionsOnNewEntitiesOnly,
|
|
949
|
-
ignorePreviousResults: result.ignorePreviousResults,
|
|
950
|
-
tags: result.tags,
|
|
951
|
-
question: result.question,
|
|
952
|
-
operations: result.operations,
|
|
953
|
-
latestAlertId: result.latestAlertId,
|
|
954
|
-
latestAlertIsActive: result.latestAlertIsActive,
|
|
955
|
-
url: ruleUrl,
|
|
956
|
-
},
|
|
957
|
-
}),
|
|
958
|
-
},
|
|
959
|
-
],
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
catch (error) {
|
|
963
|
-
return {
|
|
964
|
-
content: [
|
|
965
|
-
{
|
|
966
|
-
type: 'text',
|
|
967
|
-
text: `Error creating inline question rule: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
968
|
-
},
|
|
969
|
-
],
|
|
970
|
-
isError: true,
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
},
|
|
974
|
-
});
|
|
975
|
-
// Tool: Update inline question rule instance
|
|
976
|
-
this.registerTool({
|
|
977
|
-
name: 'update-inline-question-rule',
|
|
978
|
-
description: (0, load_description_js_1.loadDescription)('update-inline-question-rule.md'),
|
|
979
|
-
schema: {
|
|
980
|
-
id: zod_1.z.string().describe('ID of the rule to update'),
|
|
981
|
-
name: zod_1.z.string().describe('Name of the rule'),
|
|
982
|
-
description: zod_1.z.string().describe('Description of the rule'),
|
|
983
|
-
notifyOnFailure: zod_1.z.boolean().describe('Whether to notify on failure'),
|
|
984
|
-
triggerActionsOnNewEntitiesOnly: zod_1.z
|
|
985
|
-
.boolean()
|
|
986
|
-
.describe('Whether to trigger actions only on new entities'),
|
|
987
|
-
ignorePreviousResults: zod_1.z.boolean().describe('Whether to ignore previous results'),
|
|
988
|
-
pollingInterval: zod_1.z
|
|
989
|
-
.enum([
|
|
990
|
-
'DISABLED',
|
|
991
|
-
'THIRTY_MINUTES',
|
|
992
|
-
'ONE_HOUR',
|
|
993
|
-
'FOUR_HOURS',
|
|
994
|
-
'EIGHT_HOURS',
|
|
995
|
-
'TWELVE_HOURS',
|
|
996
|
-
'ONE_DAY',
|
|
997
|
-
'ONE_WEEK',
|
|
998
|
-
])
|
|
999
|
-
.describe('How frequently to evaluate the rule'),
|
|
1000
|
-
outputs: zod_1.z.array(zod_1.z.string()).describe('Output fields from the rule evaluation'),
|
|
1001
|
-
version: zod_1.z.number().describe('Current version number of the rule (from get-rule-details)'),
|
|
1002
|
-
specVersion: zod_1.z.number().describe('Specification version'),
|
|
1003
|
-
tags: zod_1.z.array(zod_1.z.string()).describe('Tags for categorizing the rule'),
|
|
1004
|
-
templates: zod_1.z.record(zod_1.z.any()).describe('Template variables'),
|
|
1005
|
-
labels: zod_1.z
|
|
1006
|
-
.array(zod_1.z.object({
|
|
1007
|
-
labelName: zod_1.z.string(),
|
|
1008
|
-
labelValue: zod_1.z.string().nullable(),
|
|
1009
|
-
}))
|
|
1010
|
-
.describe('Labels for the rule'),
|
|
1011
|
-
resourceGroupId: zod_1.z.string().nullable().describe('Resource group ID'),
|
|
1012
|
-
remediationSteps: zod_1.z
|
|
1013
|
-
.string()
|
|
1014
|
-
.nullable()
|
|
1015
|
-
.describe('Steps to remediate issues found by the rule'),
|
|
1016
|
-
question: zod_1.z
|
|
1017
|
-
.object({
|
|
1018
|
-
queries: zod_1.z.array(zod_1.z.object({
|
|
1019
|
-
query: zod_1.z.string().describe('J1QL query string'),
|
|
1020
|
-
name: zod_1.z.string().describe('Name identifier for the query'),
|
|
1021
|
-
version: zod_1.z.string().optional().describe('Version of the query'),
|
|
1022
|
-
includeDeleted: zod_1.z.boolean().describe('Whether to include deleted entities'),
|
|
1023
|
-
})),
|
|
1024
|
-
})
|
|
1025
|
-
.describe('Question configuration'),
|
|
1026
|
-
operations: zod_1.z
|
|
1027
|
-
.array(zod_1.z.object({
|
|
1028
|
-
when: zod_1.z
|
|
1029
|
-
.object({
|
|
1030
|
-
type: zod_1.z.literal('FILTER'),
|
|
1031
|
-
condition: zod_1.z
|
|
1032
|
-
.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number()]))]))
|
|
1033
|
-
.describe('Filter condition array (e.g., ["AND", ["queries.query0.total", ">", 0]])'),
|
|
1034
|
-
})
|
|
1035
|
-
.describe('Condition that triggers the actions'),
|
|
1036
|
-
actions: zod_1.z.array(actionSchema),
|
|
1037
|
-
}))
|
|
1038
|
-
.describe('Operations that define when and what actions to take'),
|
|
1039
|
-
},
|
|
1040
|
-
handler: async ({ id, name, description, notifyOnFailure, triggerActionsOnNewEntitiesOnly, ignorePreviousResults, pollingInterval, outputs, version, specVersion, tags, templates, labels, resourceGroupId, remediationSteps, question, operations, }, client, validator) => {
|
|
1041
|
-
try {
|
|
1042
|
-
// Validate all queries before updating the rule
|
|
1043
|
-
const validationResults = await this.validateQueries(question?.queries, validator);
|
|
1044
|
-
if (validationResults.length > 0) {
|
|
1045
|
-
return this.createValidationErrorResponse(validationResults);
|
|
1046
|
-
}
|
|
1047
|
-
const instance = {
|
|
1048
|
-
id,
|
|
1049
|
-
name,
|
|
1050
|
-
description,
|
|
1051
|
-
notifyOnFailure,
|
|
1052
|
-
triggerActionsOnNewEntitiesOnly,
|
|
1053
|
-
ignorePreviousResults,
|
|
1054
|
-
pollingInterval,
|
|
1055
|
-
outputs,
|
|
1056
|
-
version,
|
|
1057
|
-
specVersion,
|
|
1058
|
-
labels,
|
|
1059
|
-
tags,
|
|
1060
|
-
templates,
|
|
1061
|
-
resourceGroupId,
|
|
1062
|
-
remediationSteps,
|
|
1063
|
-
question,
|
|
1064
|
-
operations,
|
|
1065
|
-
};
|
|
1066
|
-
const result = await client.updateInlineQuestionRuleInstance(instance);
|
|
1067
|
-
// Get account info to construct the URL
|
|
1068
|
-
const accountInfo = await client.getAccountInfo();
|
|
1069
|
-
const ruleUrl = client.ruleService.constructRuleUrl(result.id, accountInfo.subdomain);
|
|
1070
|
-
return {
|
|
1071
|
-
content: [
|
|
1072
|
-
{
|
|
1073
|
-
type: 'text',
|
|
1074
|
-
text: JSON.stringify({
|
|
1075
|
-
success: true,
|
|
1076
|
-
rule: {
|
|
1077
|
-
id: result.id,
|
|
1078
|
-
name: result.name,
|
|
1079
|
-
description: result.description,
|
|
1080
|
-
version: result.version,
|
|
1081
|
-
pollingInterval: result.pollingInterval,
|
|
1082
|
-
outputs: result.outputs,
|
|
1083
|
-
specVersion: result.specVersion,
|
|
1084
|
-
notifyOnFailure: result.notifyOnFailure,
|
|
1085
|
-
triggerActionsOnNewEntitiesOnly: result.triggerActionsOnNewEntitiesOnly,
|
|
1086
|
-
ignorePreviousResults: result.ignorePreviousResults,
|
|
1087
|
-
tags: result.tags,
|
|
1088
|
-
labels: result.labels,
|
|
1089
|
-
question: result.question,
|
|
1090
|
-
operations: result.operations,
|
|
1091
|
-
latestAlertId: result.latestAlertId,
|
|
1092
|
-
latestAlertIsActive: result.latestAlertIsActive,
|
|
1093
|
-
resourceGroupId: result.resourceGroupId,
|
|
1094
|
-
remediationSteps: result.remediationSteps,
|
|
1095
|
-
url: ruleUrl,
|
|
1096
|
-
},
|
|
1097
|
-
}),
|
|
1098
|
-
},
|
|
1099
|
-
],
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
catch (error) {
|
|
1103
|
-
return {
|
|
1104
|
-
content: [
|
|
1105
|
-
{
|
|
1106
|
-
type: 'text',
|
|
1107
|
-
text: `Error updating inline question rule: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1108
|
-
},
|
|
1109
|
-
],
|
|
1110
|
-
isError: true,
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
});
|
|
1115
|
-
// Add get-integration-job tool
|
|
1116
|
-
this.registerTool({
|
|
1117
|
-
name: 'get-integration-job',
|
|
1118
|
-
description: (0, load_description_js_1.loadDescription)('get-integration-job.md'),
|
|
1119
|
-
schema: {
|
|
1120
|
-
integrationJobId: zod_1.z.string().describe('ID of the job to get'),
|
|
1121
|
-
integrationInstanceId: zod_1.z.string().describe('ID of the instance the job belongs to'),
|
|
1122
|
-
},
|
|
1123
|
-
handler: async ({ integrationJobId, integrationInstanceId }, client) => {
|
|
1124
|
-
try {
|
|
1125
|
-
const job = await client.getIntegrationJob(integrationJobId, integrationInstanceId);
|
|
1126
|
-
return {
|
|
1127
|
-
content: [
|
|
1128
|
-
{
|
|
1129
|
-
type: 'text',
|
|
1130
|
-
text: JSON.stringify({
|
|
1131
|
-
id: job.id,
|
|
1132
|
-
status: job.status,
|
|
1133
|
-
integrationInstanceId: job.integrationInstanceId,
|
|
1134
|
-
createDate: job.createDate,
|
|
1135
|
-
endDate: job.endDate,
|
|
1136
|
-
hasSkippedSteps: job.hasSkippedSteps,
|
|
1137
|
-
integrationInstance: job.integrationInstance,
|
|
1138
|
-
integrationDefinition: job.integrationDefinition,
|
|
1139
|
-
}),
|
|
1140
|
-
},
|
|
1141
|
-
],
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
catch (error) {
|
|
1145
|
-
return {
|
|
1146
|
-
content: [
|
|
1147
|
-
{
|
|
1148
|
-
type: 'text',
|
|
1149
|
-
text: `Error: ${error instanceof Error ? error.message : 'Unknown error occurred'}`,
|
|
1150
|
-
},
|
|
1151
|
-
],
|
|
1152
|
-
isError: true,
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
},
|
|
1156
|
-
});
|
|
1157
|
-
// Add get-integration-events tool
|
|
1158
|
-
this.registerTool({
|
|
1159
|
-
name: 'get-integration-events',
|
|
1160
|
-
description: (0, load_description_js_1.loadDescription)('get-integration-events.md'),
|
|
1161
|
-
schema: {
|
|
1162
|
-
jobId: zod_1.z.string().describe('ID of the job to get events for'),
|
|
1163
|
-
integrationInstanceId: zod_1.z.string().describe('ID of the instance the job belongs to'),
|
|
1164
|
-
cursor: zod_1.z.string().optional().describe('Optional cursor for pagination'),
|
|
1165
|
-
size: zod_1.z
|
|
1166
|
-
.number()
|
|
1167
|
-
.min(1)
|
|
1168
|
-
.max(1000)
|
|
1169
|
-
.optional()
|
|
1170
|
-
.describe('Optional size limit for number of events to return (1-1000)'),
|
|
1171
|
-
},
|
|
1172
|
-
handler: async ({ jobId, integrationInstanceId, cursor, size }, client) => {
|
|
1173
|
-
try {
|
|
1174
|
-
const events = await client.getIntegrationEvents(jobId, integrationInstanceId, cursor, size);
|
|
1175
|
-
return {
|
|
1176
|
-
content: [
|
|
1177
|
-
{
|
|
1178
|
-
type: 'text',
|
|
1179
|
-
text: JSON.stringify({
|
|
1180
|
-
events: events.events.map((event) => ({
|
|
1181
|
-
id: event.id,
|
|
1182
|
-
name: event.name,
|
|
1183
|
-
description: event.description,
|
|
1184
|
-
createDate: event.createDate,
|
|
1185
|
-
jobId: event.jobId,
|
|
1186
|
-
level: event.level,
|
|
1187
|
-
eventCode: event.eventCode,
|
|
1188
|
-
})),
|
|
1189
|
-
pageInfo: events.pageInfo,
|
|
1190
|
-
}),
|
|
1191
|
-
},
|
|
1192
|
-
],
|
|
1193
|
-
};
|
|
1194
|
-
}
|
|
1195
|
-
catch (error) {
|
|
1196
|
-
return {
|
|
1197
|
-
content: [
|
|
1198
|
-
{
|
|
1199
|
-
type: 'text',
|
|
1200
|
-
text: `Error: ${error instanceof Error ? error.message : 'Unknown error occurred'}`,
|
|
1201
|
-
},
|
|
1202
|
-
],
|
|
1203
|
-
isError: true,
|
|
1204
|
-
};
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
});
|
|
1208
|
-
// Tool: List rule evaluations
|
|
1209
|
-
this.registerTool({
|
|
1210
|
-
name: 'list-rule-evaluations',
|
|
1211
|
-
description: (0, load_description_js_1.loadDescription)('list-rule-evaluations.md'),
|
|
1212
|
-
schema: {
|
|
1213
|
-
ruleId: zod_1.z.string(),
|
|
1214
|
-
beginTimestamp: zod_1.z.number().optional(),
|
|
1215
|
-
endTimestamp: zod_1.z.number().optional(),
|
|
1216
|
-
limit: zod_1.z.number().min(1).max(1000).optional(),
|
|
1217
|
-
tag: zod_1.z.string().optional(),
|
|
1218
|
-
},
|
|
1219
|
-
handler: async ({ ruleId, beginTimestamp, endTimestamp, limit, tag }, client) => {
|
|
1220
|
-
try {
|
|
1221
|
-
const evaluations = await client.getAllRuleEvaluations({
|
|
1222
|
-
collectionType: 'RULE_EVALUATION',
|
|
1223
|
-
collectionOwnerId: ruleId,
|
|
1224
|
-
beginTimestamp: beginTimestamp || 0,
|
|
1225
|
-
endTimestamp: endTimestamp || Date.now(),
|
|
1226
|
-
limit,
|
|
1227
|
-
tag,
|
|
1228
|
-
});
|
|
1229
|
-
return {
|
|
1230
|
-
content: [
|
|
1231
|
-
{
|
|
1232
|
-
type: 'text',
|
|
1233
|
-
text: JSON.stringify({
|
|
1234
|
-
total: evaluations.length,
|
|
1235
|
-
evaluations: evaluations.map((evaluation) => ({
|
|
1236
|
-
accountId: evaluation.accountId,
|
|
1237
|
-
collectionOwnerId: evaluation.collectionOwnerId,
|
|
1238
|
-
collectionOwnerVersion: evaluation.collectionOwnerVersion,
|
|
1239
|
-
collectionType: evaluation.collectionType,
|
|
1240
|
-
outputs: evaluation.outputs,
|
|
1241
|
-
rawDataDescriptors: evaluation.rawDataDescriptors,
|
|
1242
|
-
tag: evaluation.tag,
|
|
1243
|
-
timestamp: evaluation.timestamp,
|
|
1244
|
-
})),
|
|
1245
|
-
}),
|
|
1246
|
-
},
|
|
1247
|
-
],
|
|
1248
|
-
};
|
|
1249
|
-
}
|
|
1250
|
-
catch (error) {
|
|
1251
|
-
return {
|
|
1252
|
-
content: [
|
|
1253
|
-
{
|
|
1254
|
-
type: 'text',
|
|
1255
|
-
text: `Error listing rule evaluations: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1256
|
-
},
|
|
1257
|
-
],
|
|
1258
|
-
isError: true,
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
},
|
|
1262
|
-
});
|
|
1263
|
-
// Tool: Get rule evaluation details
|
|
1264
|
-
this.registerTool({
|
|
1265
|
-
name: 'get-rule-evaluation-details',
|
|
1266
|
-
description: (0, load_description_js_1.loadDescription)('get-rule-evaluation-details.md'),
|
|
1267
|
-
schema: {
|
|
1268
|
-
ruleId: zod_1.z.string(),
|
|
1269
|
-
timestamp: zod_1.z.number(),
|
|
1270
|
-
},
|
|
1271
|
-
handler: async ({ ruleId, timestamp }, client) => {
|
|
1272
|
-
try {
|
|
1273
|
-
const details = await client.getRuleEvaluationDetails({
|
|
1274
|
-
ruleInstanceId: ruleId,
|
|
1275
|
-
timestamp,
|
|
1276
|
-
});
|
|
1277
|
-
return {
|
|
1278
|
-
content: [
|
|
1279
|
-
{
|
|
1280
|
-
type: 'text',
|
|
1281
|
-
text: JSON.stringify({
|
|
1282
|
-
accountRuleId: details.accountRuleId,
|
|
1283
|
-
startedOn: details.startedOn,
|
|
1284
|
-
question: {
|
|
1285
|
-
totalDuration: details.question.totalDuration,
|
|
1286
|
-
queries: Array.isArray(details.question.queries)
|
|
1287
|
-
? details.question.queries.map((query) => ({
|
|
1288
|
-
status: query.status,
|
|
1289
|
-
queryEvaluationDetails: Array.isArray(query.queryEvaluationDetails)
|
|
1290
|
-
? query.queryEvaluationDetails.map((detail) => ({
|
|
1291
|
-
name: detail.name,
|
|
1292
|
-
duration: detail.duration,
|
|
1293
|
-
status: detail.status,
|
|
1294
|
-
error: detail.error,
|
|
1295
|
-
}))
|
|
1296
|
-
: [],
|
|
1297
|
-
}))
|
|
1298
|
-
: [],
|
|
1299
|
-
},
|
|
1300
|
-
conditions: Array.isArray(details.conditions)
|
|
1301
|
-
? details.conditions.map((condition) => ({
|
|
1302
|
-
status: condition.status,
|
|
1303
|
-
condition: condition.condition,
|
|
1304
|
-
}))
|
|
1305
|
-
: [],
|
|
1306
|
-
actions: Array.isArray(details.actions)
|
|
1307
|
-
? details.actions.map((action) => ({
|
|
1308
|
-
status: action.status,
|
|
1309
|
-
actionEvaluationDetails: Array.isArray(action.actionEvaluationDetails)
|
|
1310
|
-
? action.actionEvaluationDetails.map((detail) => ({
|
|
1311
|
-
actionId: detail.actionId,
|
|
1312
|
-
action: detail.action,
|
|
1313
|
-
status: detail.status,
|
|
1314
|
-
duration: detail.duration,
|
|
1315
|
-
finishedOn: detail.finishedOn,
|
|
1316
|
-
logs: detail.logs,
|
|
1317
|
-
}))
|
|
1318
|
-
: [],
|
|
1319
|
-
}))
|
|
1320
|
-
: [],
|
|
1321
|
-
ruleEvaluationOrigin: details.ruleEvaluationOrigin,
|
|
1322
|
-
}),
|
|
1323
|
-
},
|
|
1324
|
-
],
|
|
1325
|
-
};
|
|
1326
|
-
}
|
|
1327
|
-
catch (error) {
|
|
1328
|
-
return {
|
|
1329
|
-
content: [
|
|
1330
|
-
{
|
|
1331
|
-
type: 'text',
|
|
1332
|
-
text: `Error getting rule evaluation details: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1333
|
-
},
|
|
1334
|
-
],
|
|
1335
|
-
isError: true,
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
},
|
|
1339
|
-
});
|
|
1340
|
-
// Tool: Get raw data download URL
|
|
1341
|
-
this.registerTool({
|
|
1342
|
-
name: 'get-raw-data-download-url',
|
|
1343
|
-
description: (0, load_description_js_1.loadDescription)('get-raw-data-download-url.md'),
|
|
1344
|
-
schema: {
|
|
1345
|
-
rawDataKey: zod_1.z.string(),
|
|
1346
|
-
},
|
|
1347
|
-
handler: async ({ rawDataKey }, client) => {
|
|
1348
|
-
try {
|
|
1349
|
-
const downloadUrl = await client.getRawDataDownloadUrl(rawDataKey);
|
|
1350
|
-
return {
|
|
1351
|
-
content: [
|
|
1352
|
-
{
|
|
1353
|
-
type: 'text',
|
|
1354
|
-
text: JSON.stringify({
|
|
1355
|
-
rawDataKey,
|
|
1356
|
-
downloadUrl,
|
|
1357
|
-
}),
|
|
1358
|
-
},
|
|
1359
|
-
],
|
|
1360
|
-
};
|
|
1361
|
-
}
|
|
1362
|
-
catch (error) {
|
|
1363
|
-
return {
|
|
1364
|
-
content: [
|
|
1365
|
-
{
|
|
1366
|
-
type: 'text',
|
|
1367
|
-
text: `Error getting raw data download URL: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1368
|
-
},
|
|
1369
|
-
],
|
|
1370
|
-
isError: true,
|
|
1371
|
-
};
|
|
1372
|
-
}
|
|
1373
|
-
},
|
|
1374
|
-
});
|
|
1375
|
-
// Tool: Get rule evaluation query results
|
|
1376
|
-
this.registerTool({
|
|
1377
|
-
name: 'get-rule-evaluation-query-results',
|
|
1378
|
-
description: (0, load_description_js_1.loadDescription)('get-rule-evaluation-query-results.md'),
|
|
1379
|
-
schema: {
|
|
1380
|
-
rawDataKey: zod_1.z.string(),
|
|
1381
|
-
},
|
|
1382
|
-
handler: async ({ rawDataKey }, client) => {
|
|
1383
|
-
try {
|
|
1384
|
-
const results = await client.getRawDataResults(rawDataKey);
|
|
1385
|
-
return {
|
|
1386
|
-
content: [
|
|
1387
|
-
{
|
|
1388
|
-
type: 'text',
|
|
1389
|
-
text: JSON.stringify(results),
|
|
1390
|
-
},
|
|
1391
|
-
],
|
|
1392
|
-
};
|
|
1393
|
-
}
|
|
1394
|
-
catch (error) {
|
|
1395
|
-
return {
|
|
1396
|
-
content: [
|
|
1397
|
-
{
|
|
1398
|
-
type: 'text',
|
|
1399
|
-
text: `Error getting rule evaluation query results: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1400
|
-
},
|
|
1401
|
-
],
|
|
1402
|
-
isError: true,
|
|
1403
|
-
};
|
|
1404
|
-
}
|
|
1405
|
-
},
|
|
1406
|
-
});
|
|
1407
|
-
// Tool: Create dashboard widget
|
|
1408
|
-
this.registerTool({
|
|
1409
|
-
name: 'create-dashboard-widget',
|
|
1410
|
-
description: (0, load_description_js_1.loadDescription)('create-dashboard-widget.md'),
|
|
1411
|
-
schema: {
|
|
1412
|
-
dashboardId: zod_1.z.string().describe('ID of the dashboard to add the widget to'),
|
|
1413
|
-
input: zod_1.z.any().describe('Widget input object (CreateInsightsWidgetInput)'),
|
|
1414
|
-
},
|
|
1415
|
-
handler: async ({ dashboardId, input }, client, validator) => {
|
|
1416
|
-
try {
|
|
1417
|
-
let widgetInput = input;
|
|
1418
|
-
if (typeof input === 'string') {
|
|
1419
|
-
try {
|
|
1420
|
-
widgetInput = JSON.parse(input);
|
|
1421
|
-
}
|
|
1422
|
-
catch (e) {
|
|
1423
|
-
throw new Error('Input must be a valid object or JSON string');
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
// Validate queries before creating widget
|
|
1427
|
-
const validationResults = await this.validateWidgetQueries(widgetInput.config?.queries, validator);
|
|
1428
|
-
if (validationResults.length > 0) {
|
|
1429
|
-
return this.createValidationErrorResponse(validationResults);
|
|
1430
|
-
}
|
|
1431
|
-
const widget = await client.createDashboardWidget(dashboardId, widgetInput);
|
|
1432
|
-
// Get account info to construct the dashboard URL
|
|
1433
|
-
const accountInfo = await client.getAccountInfo();
|
|
1434
|
-
const dashboardUrl = client.dashboardService.constructDashboardUrl(dashboardId, accountInfo.subdomain);
|
|
1435
|
-
return {
|
|
1436
|
-
content: [
|
|
1437
|
-
{
|
|
1438
|
-
type: 'text',
|
|
1439
|
-
text: JSON.stringify({
|
|
1440
|
-
...widget,
|
|
1441
|
-
dashboardUrl,
|
|
1442
|
-
}),
|
|
1443
|
-
},
|
|
1444
|
-
],
|
|
1445
|
-
};
|
|
1446
|
-
}
|
|
1447
|
-
catch (error) {
|
|
1448
|
-
return {
|
|
1449
|
-
content: [
|
|
1450
|
-
{
|
|
1451
|
-
type: 'text',
|
|
1452
|
-
text: `Error creating dashboard widget: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1453
|
-
},
|
|
1454
|
-
],
|
|
1455
|
-
isError: true,
|
|
1456
|
-
};
|
|
1457
|
-
}
|
|
1458
|
-
},
|
|
1459
|
-
});
|
|
1460
|
-
// Tool: Update dashboard
|
|
1461
|
-
this.registerTool({
|
|
1462
|
-
name: 'update-dashboard',
|
|
1463
|
-
description: (0, load_description_js_1.loadDescription)('update-dashboard.md'),
|
|
1464
|
-
schema: {
|
|
1465
|
-
dashboardId: zod_1.z.string().describe('ID of the dashboard to update'),
|
|
1466
|
-
layouts: zod_1.z
|
|
1467
|
-
.object({
|
|
1468
|
-
xs: zod_1.z
|
|
1469
|
-
.array(zod_1.z.object({
|
|
1470
|
-
w: zod_1.z.number(),
|
|
1471
|
-
h: zod_1.z.number(),
|
|
1472
|
-
x: zod_1.z.number(),
|
|
1473
|
-
y: zod_1.z.number(),
|
|
1474
|
-
i: zod_1.z.string(),
|
|
1475
|
-
moved: zod_1.z.boolean(),
|
|
1476
|
-
static: zod_1.z.boolean(),
|
|
1477
|
-
}))
|
|
1478
|
-
.optional(),
|
|
1479
|
-
sm: zod_1.z
|
|
1480
|
-
.array(zod_1.z.object({
|
|
1481
|
-
w: zod_1.z.number(),
|
|
1482
|
-
h: zod_1.z.number(),
|
|
1483
|
-
x: zod_1.z.number(),
|
|
1484
|
-
y: zod_1.z.number(),
|
|
1485
|
-
i: zod_1.z.string(),
|
|
1486
|
-
moved: zod_1.z.boolean(),
|
|
1487
|
-
static: zod_1.z.boolean(),
|
|
1488
|
-
}))
|
|
1489
|
-
.optional(),
|
|
1490
|
-
md: zod_1.z
|
|
1491
|
-
.array(zod_1.z.object({
|
|
1492
|
-
w: zod_1.z.number(),
|
|
1493
|
-
h: zod_1.z.number(),
|
|
1494
|
-
x: zod_1.z.number(),
|
|
1495
|
-
y: zod_1.z.number(),
|
|
1496
|
-
i: zod_1.z.string(),
|
|
1497
|
-
moved: zod_1.z.boolean(),
|
|
1498
|
-
static: zod_1.z.boolean(),
|
|
1499
|
-
}))
|
|
1500
|
-
.optional(),
|
|
1501
|
-
lg: zod_1.z
|
|
1502
|
-
.array(zod_1.z.object({
|
|
1503
|
-
w: zod_1.z.number(),
|
|
1504
|
-
h: zod_1.z.number(),
|
|
1505
|
-
x: zod_1.z.number(),
|
|
1506
|
-
y: zod_1.z.number(),
|
|
1507
|
-
i: zod_1.z.string(),
|
|
1508
|
-
moved: zod_1.z.boolean(),
|
|
1509
|
-
static: zod_1.z.boolean(),
|
|
1510
|
-
}))
|
|
1511
|
-
.optional(),
|
|
1512
|
-
xl: zod_1.z
|
|
1513
|
-
.array(zod_1.z.object({
|
|
1514
|
-
w: zod_1.z.number(),
|
|
1515
|
-
h: zod_1.z.number(),
|
|
1516
|
-
x: zod_1.z.number(),
|
|
1517
|
-
y: zod_1.z.number(),
|
|
1518
|
-
i: zod_1.z.string(),
|
|
1519
|
-
moved: zod_1.z.boolean(),
|
|
1520
|
-
static: zod_1.z.boolean(),
|
|
1521
|
-
}))
|
|
1522
|
-
.optional(),
|
|
1523
|
-
})
|
|
1524
|
-
.describe('Layouts object for the dashboard'),
|
|
1525
|
-
},
|
|
1526
|
-
handler: async ({ dashboardId, layouts }, client) => {
|
|
1527
|
-
try {
|
|
1528
|
-
const updated = await client.updateDashboard({ dashboardId, layouts });
|
|
1529
|
-
return {
|
|
1530
|
-
content: [
|
|
1531
|
-
{
|
|
1532
|
-
type: 'text',
|
|
1533
|
-
text: JSON.stringify(updated),
|
|
1534
|
-
},
|
|
1535
|
-
],
|
|
1536
|
-
};
|
|
1537
|
-
}
|
|
1538
|
-
catch (error) {
|
|
1539
|
-
return {
|
|
1540
|
-
content: [
|
|
1541
|
-
{
|
|
1542
|
-
type: 'text',
|
|
1543
|
-
text: `Error updating dashboard: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1544
|
-
},
|
|
1545
|
-
],
|
|
1546
|
-
isError: true,
|
|
1547
|
-
};
|
|
1548
|
-
}
|
|
1549
|
-
},
|
|
1550
|
-
});
|
|
1551
|
-
// Tool: Execute J1QL query
|
|
1552
|
-
this.registerTool({
|
|
1553
|
-
name: 'execute-j1ql-query',
|
|
1554
|
-
description: (0, load_description_js_1.loadDescription)('execute-j1ql-query.md'),
|
|
1555
|
-
schema: {
|
|
1556
|
-
query: zod_1.z.string().describe('A J1QL query string that describes what data to return'),
|
|
1557
|
-
variables: zod_1.z
|
|
1558
|
-
.record(zod_1.z.any())
|
|
1559
|
-
.optional()
|
|
1560
|
-
.describe('A JSON map of values to be used as parameters for the query'),
|
|
1561
|
-
cursor: zod_1.z
|
|
1562
|
-
.string()
|
|
1563
|
-
.optional()
|
|
1564
|
-
.describe('A token that can be exchanged to fetch the next page of information'),
|
|
1565
|
-
includeDeleted: zod_1.z
|
|
1566
|
-
.boolean()
|
|
1567
|
-
.optional()
|
|
1568
|
-
.describe('Include recently deleted information in the results'),
|
|
1569
|
-
flags: zod_1.z.record(zod_1.z.any()).optional().describe('Flags for query execution'),
|
|
1570
|
-
scopeFilters: zod_1.z
|
|
1571
|
-
.array(zod_1.z.record(zod_1.z.any()))
|
|
1572
|
-
.optional()
|
|
1573
|
-
.describe('Array of filters that define the desired vertex'),
|
|
1574
|
-
},
|
|
1575
|
-
handler: async ({ query, variables, cursor, includeDeleted, flags, scopeFilters }, client, validator) => {
|
|
1576
|
-
try {
|
|
1577
|
-
// Build flags object
|
|
1578
|
-
const queryFlags = { ...flags };
|
|
1579
|
-
if (typeof includeDeleted === 'boolean')
|
|
1580
|
-
queryFlags.includeDeleted = includeDeleted;
|
|
1581
|
-
const result = await client.executeJ1qlQuery({
|
|
1582
|
-
query,
|
|
1583
|
-
variables,
|
|
1584
|
-
cursor,
|
|
1585
|
-
scopeFilters,
|
|
1586
|
-
flags: Object.keys(queryFlags).length > 0 ? queryFlags : undefined,
|
|
1587
|
-
});
|
|
1588
|
-
// Get account info to construct the URL
|
|
1589
|
-
const accountInfo = await client.getAccountInfo();
|
|
1590
|
-
const queryUrl = client.j1qlService.constructQueryUrl(query, accountInfo.subdomain);
|
|
1591
|
-
// Add URL to the result
|
|
1592
|
-
const enhancedResult = {
|
|
1593
|
-
...result,
|
|
1594
|
-
url: queryUrl,
|
|
1595
|
-
};
|
|
1596
|
-
return {
|
|
1597
|
-
content: [
|
|
1598
|
-
{
|
|
1599
|
-
type: 'text',
|
|
1600
|
-
text: JSON.stringify(enhancedResult),
|
|
1601
|
-
},
|
|
1602
|
-
],
|
|
1603
|
-
};
|
|
1604
|
-
}
|
|
1605
|
-
catch (error) {
|
|
1606
|
-
return this.createQueryErrorResponse(error, query, validator);
|
|
1607
|
-
}
|
|
1608
|
-
},
|
|
1609
|
-
});
|
|
1610
|
-
// Tool: List entity types
|
|
1611
|
-
this.registerTool({
|
|
1612
|
-
name: 'list-entity-types',
|
|
1613
|
-
description: (0, load_description_js_1.loadDescription)('list-entity-types.md'),
|
|
1614
|
-
schema: {},
|
|
1615
|
-
handler: async (_, client) => {
|
|
1616
|
-
try {
|
|
1617
|
-
const results = await client.listEntityTypes();
|
|
1618
|
-
return {
|
|
1619
|
-
content: [
|
|
1620
|
-
{
|
|
1621
|
-
type: 'text',
|
|
1622
|
-
text: JSON.stringify(results),
|
|
1623
|
-
},
|
|
1624
|
-
],
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
1627
|
-
catch (error) {
|
|
1628
|
-
return {
|
|
1629
|
-
content: [
|
|
1630
|
-
{
|
|
1631
|
-
type: 'text',
|
|
1632
|
-
text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
1633
|
-
},
|
|
1634
|
-
],
|
|
1635
|
-
isError: true,
|
|
1636
|
-
};
|
|
1637
|
-
}
|
|
1638
|
-
},
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
// Helper methods for validation
|
|
1642
|
-
async validateQueries(queries, validator) {
|
|
1643
|
-
if (!queries || !Array.isArray(queries))
|
|
1644
|
-
return [];
|
|
1645
|
-
const validationResults = [];
|
|
1646
|
-
for (const queryObj of queries) {
|
|
1647
|
-
if (queryObj.query) {
|
|
1648
|
-
const validation = await validator.validateQuery(queryObj.query);
|
|
1649
|
-
if (!validation.isValid) {
|
|
1650
|
-
validationResults.push({
|
|
1651
|
-
queryName: queryObj.name || 'Unnamed query',
|
|
1652
|
-
error: validation.error || 'Query validation failed',
|
|
1653
|
-
suggestion: validation.suggestion || 'Please check the query syntax and try again',
|
|
1654
|
-
});
|
|
1655
|
-
}
|
|
55
|
+
async invoke(tool, params) {
|
|
56
|
+
let client = this.client;
|
|
57
|
+
let validator = this.validator;
|
|
58
|
+
let toolParams = params;
|
|
59
|
+
let accountId;
|
|
60
|
+
if (this.hasEnvironmentAccount) {
|
|
61
|
+
const { accountId: requested, ...otherParams } = params;
|
|
62
|
+
if (!requested || typeof requested !== 'string') {
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'text',
|
|
67
|
+
text: 'Error: accountId is required for this operation because no default JUPITERONE_ACCOUNT_ID is configured.',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
isError: true,
|
|
71
|
+
};
|
|
1656
72
|
}
|
|
73
|
+
accountId = requested;
|
|
74
|
+
client = this.client.cloneWithAccountId(requested);
|
|
75
|
+
validator = new j1ql_validator_js_1.J1QLValidator(client.j1qlService);
|
|
76
|
+
toolParams = otherParams;
|
|
77
|
+
}
|
|
78
|
+
const startedAt = Date.now();
|
|
79
|
+
let outcome = 'success';
|
|
80
|
+
let errorClass;
|
|
81
|
+
try {
|
|
82
|
+
const result = await tool.handler(toolParams, client, validator);
|
|
83
|
+
if (result.isError)
|
|
84
|
+
outcome = 'error';
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
outcome = 'error';
|
|
89
|
+
errorClass = error instanceof Error ? error.constructor.name : 'UnknownError';
|
|
90
|
+
return tool.formatError
|
|
91
|
+
? tool.formatError(error, toolParams, validator)
|
|
92
|
+
: (0, errors_js_1.toErrorResponse)(error, tool.errorContext);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
this.telemetry({
|
|
96
|
+
tool: tool.name,
|
|
97
|
+
outcome,
|
|
98
|
+
durationMs: Date.now() - startedAt,
|
|
99
|
+
errorClass,
|
|
100
|
+
accountId,
|
|
101
|
+
});
|
|
1657
102
|
}
|
|
1658
|
-
return validationResults;
|
|
1659
|
-
}
|
|
1660
|
-
async validateWidgetQueries(queries, validator) {
|
|
1661
|
-
// Use the same validation logic as rules - actually execute the queries
|
|
1662
|
-
return this.validateQueries(queries, validator);
|
|
1663
|
-
}
|
|
1664
|
-
createValidationErrorResponse(validationResults) {
|
|
1665
|
-
return {
|
|
1666
|
-
content: [
|
|
1667
|
-
{
|
|
1668
|
-
type: 'text',
|
|
1669
|
-
text: `Query validation failed. Please fix the following issues:\n\n${validationResults
|
|
1670
|
-
.map((r) => `Query: ${r.queryName}\nError: ${r.error}\nSuggestion: ${r.suggestion}`)
|
|
1671
|
-
.join('\n\n')}\n\nUse the execute-j1ql-query tool to test and refine your queries first.`,
|
|
1672
|
-
},
|
|
1673
|
-
],
|
|
1674
|
-
isError: true,
|
|
1675
|
-
};
|
|
1676
|
-
}
|
|
1677
|
-
createQueryErrorResponse(error, query, validator) {
|
|
1678
|
-
const errorResult = validator.handleQueryError(error, query);
|
|
1679
|
-
return {
|
|
1680
|
-
content: [
|
|
1681
|
-
{
|
|
1682
|
-
type: 'text',
|
|
1683
|
-
text: `Error executing J1QL query:\n\n${errorResult.error}\n\nSuggestion: ${errorResult.suggestion}\n\nDebugging tips:\n1. Modify existing queries that are already working as expected.\n2. Use discovery queries to understand available data\n3. Verify entity classes exist (use proper capitalization)\n4. Check property names match exactly\n5. Use single quotes for strings, not double quotes\n6. Place aliases after WITH statements\n7. Add LIMIT clause to prevent timeouts`,
|
|
1684
|
-
},
|
|
1685
|
-
],
|
|
1686
|
-
isError: true,
|
|
1687
|
-
};
|
|
1688
103
|
}
|
|
1689
104
|
async start() {
|
|
1690
105
|
const transport = new stdio_js_1.StdioServerTransport();
|