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