@smartbear/mcp 0.3.0 → 0.4.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.
@@ -1,12 +1,9 @@
1
- import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import NodeCache from "node-cache";
2
+ import { z } from "zod";
2
3
  import { MCP_SERVER_NAME, MCP_SERVER_VERSION } from "../common/info.js";
3
4
  import { CurrentUserAPI, ErrorAPI, Configuration } from "./client/index.js";
4
- import { z } from "zod";
5
- import Bugsnag from "../common/bugsnag.js";
6
- import NodeCache from "node-cache";
7
5
  import { ProjectAPI } from "./client/api/Project.js";
8
6
  import { FilterObjectSchema, toQueryString } from "./client/api/filters.js";
9
- import { toolDescriptionTemplate, createParameter, createExample } from "../common/templates.js";
10
7
  const HUB_PREFIX = "00000";
11
8
  const DEFAULT_DOMAIN = "bugsnag.com";
12
9
  const HUB_DOMAIN = "insighthub.smartbear.com";
@@ -36,6 +33,8 @@ export class InsightHubClient {
36
33
  projectApiKey;
37
34
  apiEndpoint;
38
35
  appEndpoint;
36
+ name = "Insight Hub";
37
+ prefix = "insight_hub";
39
38
  constructor(token, projectApiKey, endpoint) {
40
39
  this.apiEndpoint = this.getEndpoint("api", projectApiKey, endpoint);
41
40
  this.appEndpoint = this.getEndpoint("app", projectApiKey, endpoint);
@@ -193,429 +192,428 @@ export class InsightHubClient {
193
192
  return currentProject;
194
193
  }
195
194
  }
196
- registerTools(server) {
195
+ registerTools(register, getInput) {
197
196
  if (!this.projectApiKey) {
198
- server.registerTool("list_insight_hub_projects", {
199
- description: toolDescriptionTemplate({
200
- summary: "List all projects in the organization with optional pagination",
201
- purpose: "Retrieve available projects for browsing and selecting which project to analyze",
202
- useCases: [
203
- "Browse available projects when no specific project API key is configured",
204
- "Find project IDs needed for other tools",
205
- "Get an overview of all projects in the organization"
206
- ],
207
- parameters: [
208
- createParameter("page_size", "number", false, "Number of projects to return per page for pagination", {
209
- examples: ["10", "25", "50"]
210
- }),
211
- createParameter("page", "number", false, "Page number to return (starts from 1)", {
212
- examples: ["1", "2", "3"]
213
- })
214
- ],
215
- examples: [
216
- createExample("Get first 10 projects", {
217
- page_size: 10,
218
- page: 1
219
- }, "JSON array of project objects with IDs, names, and metadata"),
220
- createExample("Get all projects (no pagination)", {}, "JSON array of all available projects")
221
- ],
222
- hints: [
223
- "Use pagination for organizations with many projects to avoid large responses",
224
- "Project IDs from this list can be used with other tools when no project API key is configured"
225
- ]
226
- }),
227
- inputSchema: {
228
- page_size: z.number().optional().describe("Number of projects to return per page"),
229
- page: z.number().optional().describe("Page number to return"),
230
- }
231
- }, async (args, _extra) => {
232
- try {
233
- let projects = await this.getProjects();
234
- if (!projects || projects.length === 0) {
235
- return {
236
- content: [{ type: "text", text: "No projects found." }],
237
- };
238
- }
239
- if (args.page_size || args.page) {
240
- const pageSize = args.page_size || 10;
241
- const page = args.page || 1;
242
- projects = projects.slice((page - 1) * pageSize, page * pageSize);
243
- }
244
- const result = {
245
- data: projects,
246
- count: projects.length,
247
- };
248
- return {
249
- content: [{ type: "text", text: JSON.stringify(result) }],
250
- };
251
- }
252
- catch (e) {
253
- Bugsnag.notify(e);
254
- throw e;
255
- }
256
- });
257
- }
258
- server.registerTool("get_insight_hub_error", {
259
- description: toolDescriptionTemplate({
260
- summary: "Get full details on an error, including aggregated and summarised data across all events (occurrences) and details of the latest event (occurrence), such as breadcrumbs, metadata and the stacktrace. Use the filters parameter to narrow down the summaries further.",
261
- purpose: "Retrieve all the information required on a specified error to understand who it is affecting and why.",
197
+ register({
198
+ title: "List Projects",
199
+ summary: "List all projects in the organization with optional pagination",
200
+ purpose: "Retrieve available projects for browsing and selecting which project to analyze",
262
201
  useCases: [
263
- "Investigate a specific error found through list_insight_hub_project_errors",
264
- "Understand which types of user are affected by the error using summarised event data",
265
- "Get error details for debugging and root cause analysis",
266
- "Retrieve error metadata for incident reports and documentation"
202
+ "Browse available projects when no specific project API key is configured",
203
+ "Find project IDs needed for other tools",
204
+ "Get an overview of all projects in the organization"
267
205
  ],
268
206
  parameters: [
269
- createParameter("errorId", "string", true, "Unique identifier of the error to retrieve", {
270
- examples: ["6863e2af8c857c0a5023b411"]
271
- }),
272
- ...(this.projectApiKey ? [] : [
273
- createParameter("projectId", "string", true, "ID of the project containing the error")
274
- ]),
275
- createParameter("filters", "FilterObject", false, "Apply filters to narrow down the error list. Use get_project_event_filters to discover available filter fields", {
276
- examples: [
277
- '{"error.status": [{"type": "eq", "value": "open"}]}',
278
- '{"event.since": [{"type": "eq", "value": "7d"}]} // Relative time: last 7 days',
279
- '{"event.since": [{"type": "eq", "value": "2018-05-20T00:00:00Z"}]} // ISO 8601 UTC format',
280
- '{"user.email": [{"type": "eq", "value": "user@example.com"}]}'
281
- ],
282
- constraints: [
283
- "Time filters support ISO 8601 format (e.g. 2018-05-20T00:00:00Z) or relative format (e.g. 7d, 24h)",
284
- "ISO 8601 times must be in UTC and use extended format",
285
- "Relative time periods: h (hours), d (days)"
286
- ]
287
- })
207
+ {
208
+ name: "page_size",
209
+ type: z.number(),
210
+ description: "Number of projects to return per page for pagination",
211
+ required: false,
212
+ examples: ["10", "25", "50"]
213
+ },
214
+ {
215
+ name: "page",
216
+ type: z.number(),
217
+ description: "Page number to return (starts from 1)",
218
+ required: false,
219
+ examples: ["1", "2", "3"]
220
+ }
288
221
  ],
289
- outputFormat: "JSON object containing: " +
290
- " - error_details: Aggregated data about the error, including first and last seen occurrence" +
291
- " - latest_event: Detailed information about the most recent occurrence of the error, including stacktrace, breadcrumbs, user and context" +
292
- " - pivots: List of pivots (summaries) for the error, which can be used to analyze patterns in occurrences" +
293
- " - url: A link to the error in the Insight Hub dashboard - this should be shown to the user for them to perform further analysis",
294
222
  examples: [
295
- createExample("Get details for a specific error", {
296
- errorId: "6863e2af8c857c0a5023b411"
297
- }, "JSON object with error details including message, stack trace, occurrence count, and metadata")
223
+ {
224
+ description: "Get first 10 projects",
225
+ parameters: {
226
+ page_size: 10,
227
+ page: 1
228
+ },
229
+ expectedOutput: "JSON array of project objects with IDs, names, and metadata",
230
+ },
231
+ {
232
+ description: "Get all projects (no pagination)",
233
+ parameters: {},
234
+ expectedOutput: "JSON array of all available projects"
235
+ }
298
236
  ],
299
237
  hints: [
300
- "Error IDs can be found using the list_insight_hub_project_errors tool",
301
- "Use this after filtering errors to get detailed information about specific errors",
302
- "If you used a filter to get this error, you can pass the same filters here to restrict the results or apply further filters",
303
- "The response also includes the latest event for the error, do not call get_insight_hub_error_latest_event afterwards as this will be redundant",
304
- "The URL provided in the response points should be shown to the user in all cases as it allows them to view the error in the Insight Hub dashboard and perform further analysis",
238
+ "Use pagination for organizations with many projects to avoid large responses",
239
+ "Project IDs from this list can be used with other tools when no project API key is configured"
305
240
  ]
306
- }),
307
- inputSchema: {
308
- errorId: z.string().describe("ID of the error to fetch"),
309
- ...(!this.projectApiKey ? { projectId: z.string().optional().describe("ID of the project") } : {}),
310
- filters: FilterObjectSchema.optional().describe("Filters to apply to the error list. Valid filters for a project can be found in the `get_project_event_filters` tool.")
311
- }
312
- }, async (args, _extra) => {
313
- try {
314
- const project = await this.getInputProject(args.projectId);
315
- if (!args.errorId)
316
- throw new Error("Both projectId and errorId arguments are required");
317
- const errorDetails = (await this.errorsApi.viewErrorOnProject(project.id, args.errorId)).body;
318
- if (!errorDetails) {
319
- throw new Error(`Error with ID ${args.errorId} not found in project ${project.id}.`);
320
- }
321
- // Build query parameters
322
- const params = new URLSearchParams();
323
- // Add sorting and pagination parameters to get the latest event
324
- params.append('sort', 'timestamp');
325
- params.append('direction', 'desc');
326
- params.append('per_page', '1');
327
- params.append('full_reports', 'true');
328
- const filters = {
329
- "error": [{ type: "eq", value: args.errorId }],
330
- ...args.filters
331
- };
332
- const filtersQueryString = toQueryString(filters);
333
- const listEventsQueryString = `?${params}&${filtersQueryString}`;
334
- // Get the latest event for this error using the events endpoint with filters
335
- let latestEvent = null;
336
- try {
337
- const eventsResponse = await this.errorsApi.listEventsOnProject(project.id, listEventsQueryString);
338
- const events = eventsResponse.body || [];
339
- latestEvent = events[0] || null;
241
+ }, async (args, _extra) => {
242
+ let projects = await this.getProjects();
243
+ if (!projects || projects.length === 0) {
244
+ return {
245
+ content: [{ type: "text", text: "No projects found." }],
246
+ };
340
247
  }
341
- catch (e) {
342
- console.warn("Failed to fetch latest event:", e);
343
- // Continue without latest event rather than failing the entire request
248
+ if (args.page_size || args.page) {
249
+ const pageSize = args.page_size || 10;
250
+ const page = args.page || 1;
251
+ projects = projects.slice((page - 1) * pageSize, page * pageSize);
344
252
  }
345
- const content = {
346
- error_details: errorDetails,
347
- latest_event: latestEvent,
348
- pivots: (await this.errorsApi.listErrorPivots(project.id, args.errorId)).body || [],
349
- url: await this.getErrorUrl(project, args.errorId, `?${filtersQueryString}`),
253
+ const result = {
254
+ data: projects,
255
+ count: projects.length,
350
256
  };
351
257
  return {
352
- content: [{ type: "text", text: JSON.stringify(content) }]
258
+ content: [{ type: "text", text: JSON.stringify(result) }],
353
259
  };
260
+ });
261
+ }
262
+ register({
263
+ title: "Get Error",
264
+ summary: "Get full details on an error, including aggregated and summarized data across all events (occurrences) and details of the latest event (occurrence), such as breadcrumbs, metadata and the stacktrace. Use the filters parameter to narrow down the summaries further.",
265
+ purpose: "Retrieve all the information required on a specified error to understand who it is affecting and why.",
266
+ useCases: [
267
+ "Investigate a specific error found through the List Project Errors tool",
268
+ "Understand which types of user are affected by the error using summarized event data",
269
+ "Get error details for debugging and root cause analysis",
270
+ "Retrieve error metadata for incident reports and documentation"
271
+ ],
272
+ parameters: [
273
+ {
274
+ name: "errorId",
275
+ type: z.string(),
276
+ required: true,
277
+ description: "Unique identifier of the error to retrieve",
278
+ examples: ["6863e2af8c857c0a5023b411"]
279
+ },
280
+ ...(this.projectApiKey ? [] : [
281
+ {
282
+ name: "projectId",
283
+ type: z.string(),
284
+ required: true,
285
+ description: "ID of the project containing the error",
286
+ }
287
+ ]),
288
+ {
289
+ name: "filters",
290
+ type: FilterObjectSchema,
291
+ required: false,
292
+ description: "Apply filters to narrow down the error list. Use the List Project Event Filters tool to discover available filter fields",
293
+ examples: [
294
+ '{"error.status": [{"type": "eq", "value": "open"}]}',
295
+ '{"event.since": [{"type": "eq", "value": "7d"}]} // Relative time: last 7 days',
296
+ '{"event.since": [{"type": "eq", "value": "2018-05-20T00:00:00Z"}]} // ISO 8601 UTC format',
297
+ '{"user.email": [{"type": "eq", "value": "user@example.com"}]}'
298
+ ],
299
+ constraints: [
300
+ "Time filters support ISO 8601 format (e.g. 2018-05-20T00:00:00Z) or relative format (e.g. 7d, 24h)",
301
+ "ISO 8601 times must be in UTC and use extended format",
302
+ "Relative time periods: h (hours), d (days)"
303
+ ]
304
+ }
305
+ ],
306
+ outputFormat: "JSON object containing: " +
307
+ " - error_details: Aggregated data about the error, including first and last seen occurrence" +
308
+ " - latest_event: Detailed information about the most recent occurrence of the error, including stacktrace, breadcrumbs, user and context" +
309
+ " - pivots: List of pivots (summaries) for the error, which can be used to analyze patterns in occurrences" +
310
+ " - url: A link to the error in the dashboard - this should be shown to the user for them to perform further analysis",
311
+ examples: [
312
+ {
313
+ description: "Get details for a specific error",
314
+ parameters: {
315
+ errorId: "6863e2af8c857c0a5023b411"
316
+ },
317
+ expectedOutput: "JSON object with error details including message, stack trace, occurrence count, and metadata"
318
+ }
319
+ ],
320
+ hints: [
321
+ "Error IDs can be found using the List Errors tool",
322
+ "Use this after filtering errors to get detailed information about specific errors",
323
+ "If you used a filter to get this error, you can pass the same filters here to restrict the results or apply further filters",
324
+ "The URL provided in the response points should be shown to the user in all cases as it allows them to view the error in the dashboard and perform further analysis",
325
+ ],
326
+ }, async (args, _extra) => {
327
+ const project = await this.getInputProject(args.projectId);
328
+ if (!args.errorId)
329
+ throw new Error("Both projectId and errorId arguments are required");
330
+ const errorDetails = (await this.errorsApi.viewErrorOnProject(project.id, args.errorId)).body;
331
+ if (!errorDetails) {
332
+ throw new Error(`Error with ID ${args.errorId} not found in project ${project.id}.`);
333
+ }
334
+ // Build query parameters
335
+ const params = new URLSearchParams();
336
+ // Add sorting and pagination parameters to get the latest event
337
+ params.append('sort', 'timestamp');
338
+ params.append('direction', 'desc');
339
+ params.append('per_page', '1');
340
+ params.append('full_reports', 'true');
341
+ const filters = {
342
+ "error": [{ type: "eq", value: args.errorId }],
343
+ ...args.filters
344
+ };
345
+ const filtersQueryString = toQueryString(filters);
346
+ const listEventsQueryString = `?${params}&${filtersQueryString}`;
347
+ // Get the latest event for this error using the events endpoint with filters
348
+ let latestEvent = null;
349
+ try {
350
+ const eventsResponse = await this.errorsApi.listEventsOnProject(project.id, listEventsQueryString);
351
+ const events = eventsResponse.body || [];
352
+ latestEvent = events[0] || null;
354
353
  }
355
354
  catch (e) {
356
- Bugsnag.notify(e);
357
- throw e;
355
+ console.warn("Failed to fetch latest event:", e);
356
+ // Continue without latest event rather than failing the entire request
358
357
  }
358
+ const content = {
359
+ error_details: errorDetails,
360
+ latest_event: latestEvent,
361
+ pivots: (await this.errorsApi.listErrorPivots(project.id, args.errorId)).body || [],
362
+ url: await this.getErrorUrl(project, args.errorId, `?${filtersQueryString}`),
363
+ };
364
+ return {
365
+ content: [{ type: "text", text: JSON.stringify(content) }]
366
+ };
359
367
  });
360
- server.registerTool("get_insight_hub_event_details", {
361
- description: toolDescriptionTemplate({
362
- summary: "Get detailed information about a specific event using its Insight Hub dashboard URL",
363
- purpose: "Retrieve event details directly from an Insight Hub web interface URL for quick debugging",
364
- useCases: [
365
- "Get event details when given an Insight Hub dashboard URL from a user or notification",
366
- "Extract event information from shared links or browser URLs",
367
- "Quick lookup of event details without needing separate project and event IDs"
368
- ],
369
- parameters: [
370
- createParameter("link", "string", true, "Full URL to the event details page in the Insight Hub dashboard (web interface)", {
371
- examples: [
372
- "https://app.bugsnag.com/my-org/my-project/errors/6863e2af8c857c0a5023b411?event_id=6863e2af012caf1d5c320000"
373
- ],
374
- constraints: [
375
- "Must be a valid Insight Hub dashboard URL containing project slug and event_id parameter"
376
- ]
377
- })
378
- ],
379
- examples: [
380
- createExample("Get event details from Insight Hub URL", {
368
+ register({
369
+ title: "Get Event Details",
370
+ summary: "Get detailed information about a specific event using its dashboard URL",
371
+ purpose: "Retrieve event details directly from a dashboard URL for quick debugging",
372
+ useCases: [
373
+ "Get event details when given a dashboard URL from a user or notification",
374
+ "Extract event information from shared links or browser URLs",
375
+ "Quick lookup of event details without needing separate project and event IDs"
376
+ ],
377
+ parameters: [
378
+ {
379
+ name: "link",
380
+ type: z.string(),
381
+ description: "Full URL to the event details page in the Insight Hub dashboard (web interface)",
382
+ required: true,
383
+ examples: [
384
+ "https://app.bugsnag.com/my-org/my-project/errors/6863e2af8c857c0a5023b411?event_id=6863e2af012caf1d5c320000"
385
+ ],
386
+ constraints: [
387
+ "Must be a valid dashboard URL containing project slug and event_id parameter"
388
+ ]
389
+ }
390
+ ],
391
+ examples: [
392
+ {
393
+ description: "Get event details from a dashboard URL",
394
+ parameters: {
381
395
  link: "https://app.bugsnag.com/my-org/my-project/errors/6863e2af8c857c0a5023b411?event_id=6863e2af012caf1d5c320000"
382
- }, "JSON object with complete event details including stack trace, metadata, and context")
383
- ],
384
- hints: [
385
- "The URL must contain both project slug in the path and event_id in query parameters",
386
- "This is useful when users share Insight Hub dashboard URLs and you need to extract the event data"
387
- ]
388
- }),
389
- inputSchema: {
390
- link: z.string().describe("Link to the event details"),
391
- }
392
- }, async (args, _extra) => {
393
- try {
394
- if (!args.link)
395
- throw new Error("link argument is required");
396
- const url = new URL(args.link);
397
- const eventId = url.searchParams.get("event_id");
398
- const projectSlug = url.pathname.split('/')[2];
399
- if (!projectSlug || !eventId)
400
- throw new Error("Both projectSlug and eventId must be present in the link");
401
- // get the project id from list of projects
402
- const projects = await this.getProjects();
403
- const projectId = projects.find((p) => p.slug === projectSlug)?.id;
404
- if (!projectId) {
405
- throw new Error("Project with the specified slug not found.");
396
+ },
397
+ expectedOutput: "JSON object with complete event details including stack trace, metadata, and context"
406
398
  }
407
- const response = await this.getEvent(eventId, projectId);
408
- return {
409
- content: [{ type: "text", text: JSON.stringify(response) }],
410
- };
411
- }
412
- catch (e) {
413
- Bugsnag.notify(e);
414
- throw e;
399
+ ],
400
+ hints: [
401
+ "The URL must contain both project slug in the path and event_id in query parameters",
402
+ "This is useful when users share Insight Hub dashboard URLs and you need to extract the event data"
403
+ ]
404
+ }, async (args, _extra) => {
405
+ if (!args.link)
406
+ throw new Error("link argument is required");
407
+ const url = new URL(args.link);
408
+ const eventId = url.searchParams.get("event_id");
409
+ const projectSlug = url.pathname.split('/')[2];
410
+ if (!projectSlug || !eventId)
411
+ throw new Error("Both projectSlug and eventId must be present in the link");
412
+ // get the project id from list of projects
413
+ const projects = await this.getProjects();
414
+ const projectId = projects.find((p) => p.slug === projectSlug)?.id;
415
+ if (!projectId) {
416
+ throw new Error("Project with the specified slug not found.");
415
417
  }
418
+ const response = await this.getEvent(eventId, projectId);
419
+ return {
420
+ content: [{ type: "text", text: JSON.stringify(response) }],
421
+ };
416
422
  });
417
423
  // Dynamically infer the filters schema from cached project event fields
418
- server.registerTool("list_insight_hub_project_errors", {
419
- description: toolDescriptionTemplate({
420
- summary: "List and search errors in a project using customizable filters",
421
- purpose: "Retrieve filtered list of errors from a project for analysis, debugging, and reporting",
422
- useCases: [
423
- "Debug recent application errors by filtering for open errors in the last 7 days",
424
- "Generate error reports for stakeholders by filtering specific error types or severity levels",
425
- "Monitor error trends over time using date range filters",
426
- "Find errors affecting specific users or environments using metadata filters"
427
- ],
428
- parameters: [
429
- createParameter("filters", "FilterObject", false, "Apply filters to narrow down the error list. Use get_project_event_filters to discover available filter fields", {
430
- examples: [
431
- '{"error.status": [{"type": "eq", "value": "open"}]}',
432
- '{"event.since": [{"type": "eq", "value": "7d"}]} // Relative time: last 7 days',
433
- '{"event.since": [{"type": "eq", "value": "2018-05-20T00:00:00Z"}]} // ISO 8601 UTC format',
434
- '{"user.email": [{"type": "eq", "value": "user@example.com"}]}'
435
- ],
436
- constraints: [
437
- "Time filters support ISO 8601 format (e.g. 2018-05-20T00:00:00Z) or relative format (e.g. 7d, 24h)",
438
- "ISO 8601 times must be in UTC and use extended format",
439
- "Relative time periods: h (hours), d (days)"
440
- ]
441
- }),
442
- ...(this.projectApiKey ? [] : [
443
- createParameter("projectId", "string", true, "ID of the project to query for errors")
444
- ])
445
- ],
446
- examples: [
447
- createExample("Find errors affecting a specific user in the last 24 hours", {
424
+ register({
425
+ title: "List Project Errors",
426
+ summary: "List and search errors in a project using customizable filters",
427
+ purpose: "Retrieve filtered list of errors from a project for analysis, debugging, and reporting",
428
+ useCases: [
429
+ "Debug recent application errors by filtering for open errors in the last 7 days",
430
+ "Generate error reports for stakeholders by filtering specific error types or severity levels",
431
+ "Monitor error trends over time using date range filters",
432
+ "Find errors affecting specific users or environments using metadata filters"
433
+ ],
434
+ parameters: [
435
+ {
436
+ name: "filters",
437
+ type: FilterObjectSchema,
438
+ description: "Apply filters to narrow down the error list. Use the List Errors or Get Error tools to discover available filter fields",
439
+ required: false,
440
+ examples: [
441
+ '{"error.status": [{"type": "eq", "value": "open"}]}',
442
+ '{"event.since": [{"type": "eq", "value": "7d"}]} // Relative time: last 7 days',
443
+ '{"event.since": [{"type": "eq", "value": "2018-05-20T00:00:00Z"}]} // ISO 8601 UTC format',
444
+ '{"user.email": [{"type": "eq", "value": "user@example.com"}]}'
445
+ ],
446
+ constraints: [
447
+ "Time filters support ISO 8601 format (e.g. 2018-05-20T00:00:00Z) or relative format (e.g. 7d, 24h)",
448
+ "ISO 8601 times must be in UTC and use extended format",
449
+ "Relative time periods: h (hours), d (days)"
450
+ ]
451
+ },
452
+ ...(this.projectApiKey ? [] : [
453
+ {
454
+ name: "projectId",
455
+ type: z.string(),
456
+ description: "ID of the project to query for errors",
457
+ required: true,
458
+ }
459
+ ])
460
+ ],
461
+ examples: [
462
+ {
463
+ description: "Find errors affecting a specific user in the last 24 hours",
464
+ parameters: {
448
465
  filters: {
449
466
  "user.email": [{ "type": "eq", "value": "user@example.com" }],
450
467
  "event.since": [{ "type": "eq", "value": "24h" }]
451
468
  }
452
- }, "JSON object with a list of errors in the 'data' field, and an error count in the 'count' field")
453
- ],
454
- hints: [
455
- "Use get_project_event_filters tool first to discover valid filter field names for your project",
456
- "Combine multiple filters to narrow results - filters are applied with AND logic",
457
- "For time filters: use relative format (7d, 24h) for recent periods or ISO 8601 UTC format (2018-05-20T00:00:00Z) for specific dates",
458
- "Common time filters: event.since (from this time), event.before (until this time)",
459
- "There may not be any errors matching the filters - this is not a problem with the tool, in fact it might be a good thing that the user's application had no errors"
460
- ]
461
- }),
462
- inputSchema: {
463
- filters: FilterObjectSchema.optional().describe("Filters to apply to the error list. Valid filters for a project can be found in the `get_project_event_filters` tool."),
464
- ...(!this.projectApiKey ? { projectId: z.string().optional().describe("ID of the project containing the error") } : {}),
465
- }
469
+ },
470
+ expectedOutput: "JSON object with a list of errors in the 'data' field, and an error count in the 'count' field"
471
+ }
472
+ ],
473
+ hints: [
474
+ "Use list_project_event_filters tool first to discover valid filter field names for your project",
475
+ "Combine multiple filters to narrow results - filters are applied with AND logic",
476
+ "For time filters: use relative format (7d, 24h) for recent periods or ISO 8601 UTC format (2018-05-20T00:00:00Z) for specific dates",
477
+ "Common time filters: event.since (from this time), event.before (until this time)",
478
+ "There may not be any errors matching the filters - this is not a problem with the tool, in fact it might be a good thing that the user's application had no errors"
479
+ ]
466
480
  }, async (args, _extra) => {
467
- try {
468
- const project = await this.getInputProject(args.projectId);
469
- // Optionally, validate filter keys against cached event fields
470
- const eventFields = this.cache.get(cacheKeys.CURRENT_PROJECT_EVENT_FILTERS) || [];
471
- if (args.filters) {
472
- const validKeys = new Set(eventFields.map(f => f.display_id));
473
- for (const key of Object.keys(args.filters)) {
474
- if (!validKeys.has(key)) {
475
- throw new Error(`Invalid filter key: ${key}`);
476
- }
481
+ const project = await this.getInputProject(args.projectId);
482
+ // Optionally, validate filter keys against cached event fields
483
+ const eventFields = this.cache.get(cacheKeys.CURRENT_PROJECT_EVENT_FILTERS) || [];
484
+ if (args.filters) {
485
+ const validKeys = new Set(eventFields.map(f => f.display_id));
486
+ for (const key of Object.keys(args.filters)) {
487
+ if (!validKeys.has(key)) {
488
+ throw new Error(`Invalid filter key: ${key}`);
477
489
  }
478
490
  }
479
- const response = await this.errorsApi.listProjectErrors(project.id, { filters: args.filters });
480
- const errors = response.body || [];
481
- const result = {
482
- data: errors,
483
- count: errors.length,
484
- };
485
- return {
486
- content: [{ type: "text", text: JSON.stringify(result) }],
487
- };
488
- }
489
- catch (e) {
490
- Bugsnag.notify(e);
491
- throw e;
492
491
  }
492
+ const response = await this.errorsApi.listProjectErrors(project.id, { filters: args.filters });
493
+ const errors = response.body || [];
494
+ const result = {
495
+ data: errors,
496
+ count: errors.length,
497
+ };
498
+ return {
499
+ content: [{ type: "text", text: JSON.stringify(result) }],
500
+ };
493
501
  });
494
- server.registerTool("get_project_event_filters", {
495
- description: toolDescriptionTemplate({
496
- summary: "Get available event filter fields for the current project",
497
- purpose: "Discover valid filter field names and options that can be used with list_insight_hub_project_errors",
498
- useCases: [
499
- "Discover what filter fields are available before searching for errors",
500
- "Find the correct field names for filtering by user, environment, or custom metadata",
501
- "Understand filter options and data types for building complex queries"
502
- ],
503
- parameters: [],
504
- examples: [
505
- createExample("Get all available filter fields", {}, "JSON array of EventField objects containing display_id, custom flag, and filter/pivot options")
506
- ],
507
- hints: [
508
- "Use this tool before list_insight_hub_project_errors to understand available filters",
509
- "Look for display_id field in the response - these are the field names to use in filters"
510
- ]
511
- }),
512
- inputSchema: {}
502
+ register({
503
+ title: "List Project Event Filters",
504
+ summary: "Get available event filter fields for the current project",
505
+ purpose: "Discover valid filter field names and options that can be used with the List Errors or Get Error tools",
506
+ useCases: [
507
+ "Discover what filter fields are available before searching for errors",
508
+ "Find the correct field names for filtering by user, environment, or custom metadata",
509
+ "Understand filter options and data types for building complex queries"
510
+ ],
511
+ parameters: [],
512
+ examples: [
513
+ {
514
+ description: "Get all available filter fields",
515
+ parameters: {},
516
+ expectedOutput: "JSON array of EventField objects containing display_id, custom flag, and filter/pivot options"
517
+ }
518
+ ],
519
+ hints: [
520
+ "Use this tool before the List Errors or Get Error tools to understand available filters",
521
+ "Look for display_id field in the response - these are the field names to use in filters"
522
+ ]
513
523
  }, async (_args, _extra) => {
514
- try {
515
- const projectFields = this.cache.get(cacheKeys.CURRENT_PROJECT_EVENT_FILTERS);
516
- if (!projectFields)
517
- throw new Error("No event filters found in cache.");
518
- return {
519
- content: [{ type: "text", text: JSON.stringify(projectFields) }],
520
- };
521
- }
522
- catch (e) {
523
- Bugsnag.notify(e);
524
- throw e;
525
- }
524
+ const projectFields = this.cache.get(cacheKeys.CURRENT_PROJECT_EVENT_FILTERS);
525
+ if (!projectFields)
526
+ throw new Error("No event filters found in cache.");
527
+ return {
528
+ content: [{ type: "text", text: JSON.stringify(projectFields) }],
529
+ };
526
530
  });
527
- server.registerTool("update_error", {
528
- description: toolDescriptionTemplate({
529
- summary: "Update the status of an error in Insight Hub",
530
- purpose: "Change an error's workflow state, such as marking it as resolved or ignored",
531
- useCases: [
532
- "Mark an error as open, fixed or ignored",
533
- "Discard or undiscard an error",
534
- "Update the severity of an error"
535
- ],
536
- parameters: [
537
- ...(this.projectApiKey ? [] : [
538
- createParameter("projectId", "string", true, "ID of the project that contains the error to be updated")
539
- ]),
540
- createParameter("errorId", "string", true, "ID of the error to update", {
541
- examples: ["6863e2af8c857c0a5023b411"]
542
- }),
543
- createParameter("operation", "string", true, "The operation to apply to the error", {
544
- examples: ["fix", "open", "ignore", "discard", "undiscard"]
545
- })
546
- ],
547
- examples: [
548
- createExample("Mark an error as fixed", {
531
+ register({
532
+ title: "Update Error",
533
+ summary: "Update the status of an error",
534
+ purpose: "Change an error's workflow state, such as marking it as resolved or ignored",
535
+ useCases: [
536
+ "Mark an error as open, fixed or ignored",
537
+ "Discard or un-discard an error",
538
+ "Update the severity of an error"
539
+ ],
540
+ parameters: [
541
+ ...(this.projectApiKey ? [] : [
542
+ {
543
+ name: "projectId",
544
+ type: z.string(),
545
+ description: "ID of the project that contains the error to be updated",
546
+ required: true,
547
+ }
548
+ ]),
549
+ {
550
+ name: "errorId",
551
+ type: z.string(),
552
+ description: "ID of the error to update",
553
+ required: true,
554
+ examples: ["6863e2af8c857c0a5023b411"]
555
+ },
556
+ {
557
+ name: "operation",
558
+ type: z.enum(PERMITTED_UPDATE_OPERATIONS),
559
+ description: "The operation to apply to the error",
560
+ required: true,
561
+ examples: ["fix", "open", "ignore", "discard", "undiscard"]
562
+ }
563
+ ],
564
+ examples: [
565
+ {
566
+ description: "Mark an error as fixed",
567
+ parameters: {
549
568
  errorId: "6863e2af8c857c0a5023b411",
550
569
  operation: "fix"
551
- }, "Success response indicating the error was marked as fixed")
552
- ],
553
- hints: [
554
- "Only use valid operations - Insight Hub may reject invalid values"
555
- ]
556
- }),
557
- inputSchema: {
558
- errorId: z.string().describe("ID of the error to update"),
559
- ...(!this.projectApiKey ? { projectId: z.string().optional().describe("ID of the project containing the error") } : {}),
560
- operation: z.enum(PERMITTED_UPDATE_OPERATIONS).describe("The operation to apply to the error"),
561
- },
562
- annotations: {
563
- title: "Update an Insight Hub Error",
564
- readOnlyHint: false,
565
- destructiveHint: true,
566
- idempotentHint: false,
567
- openWorldHint: true
568
- }
570
+ },
571
+ expectedOutput: "Success response indicating the error was marked as fixed"
572
+ }
573
+ ],
574
+ hints: [
575
+ "Only use valid operations - Insight Hub may reject invalid values"
576
+ ],
577
+ readOnly: false,
578
+ idempotent: false,
569
579
  }, async (args, _extra) => {
570
580
  const { errorId, operation } = args;
571
- try {
572
- const project = await this.getInputProject(args.projectId);
573
- let severity = undefined;
574
- if (operation === 'override_severity') {
575
- // illicit the severity from the user
576
- const result = await server.server.elicitInput({
577
- message: "Please provide the new severity for the error (e.g. 'info', 'warning', 'error', 'critical')",
578
- requestedSchema: {
579
- type: "object",
580
- properties: {
581
- severity: {
582
- type: "string",
583
- enum: ['info', 'warning', 'error'],
584
- description: "The new severity level for the error"
585
- }
581
+ const project = await this.getInputProject(args.projectId);
582
+ let severity = undefined;
583
+ if (operation === 'override_severity') {
584
+ // illicit the severity from the user
585
+ const result = await getInput({
586
+ message: "Please provide the new severity for the error (e.g. 'info', 'warning', 'error', 'critical')",
587
+ requestedSchema: {
588
+ type: "object",
589
+ properties: {
590
+ severity: {
591
+ type: "string",
592
+ enum: ['info', 'warning', 'error'],
593
+ description: "The new severity level for the error"
586
594
  }
587
- },
588
- required: ["severity"]
589
- });
590
- if (result.action === "accept" && result.content?.severity) {
591
- severity = result.content.severity;
592
- }
595
+ }
596
+ },
597
+ required: ["severity"]
598
+ });
599
+ if (result.action === "accept" && result.content?.severity) {
600
+ severity = result.content.severity;
593
601
  }
594
- const result = await this.updateError(project.id, errorId, operation, { severity });
595
- return {
596
- content: [{ type: "text", text: JSON.stringify({ success: result }) }],
597
- };
598
- }
599
- catch (e) {
600
- Bugsnag.notify(e);
601
- throw e;
602
602
  }
603
+ const result = await this.updateError(project.id, errorId, operation, { severity });
604
+ return {
605
+ content: [{ type: "text", text: JSON.stringify({ success: result }) }],
606
+ };
603
607
  });
604
608
  }
605
- registerResources(server) {
606
- server.resource("insight_hub_event", new ResourceTemplate("insighthub://event/{id}", { list: undefined }), async (uri, { id }) => {
607
- try {
608
- return {
609
- contents: [{
610
- uri: uri.href,
611
- text: JSON.stringify(await this.getEvent(id))
612
- }]
613
- };
614
- }
615
- catch (e) {
616
- Bugsnag.notify(e);
617
- throw e;
618
- }
609
+ registerResources(register) {
610
+ register("event", "{id}", async (uri, variables, _extra) => {
611
+ return {
612
+ contents: [{
613
+ uri: uri.href,
614
+ text: JSON.stringify(await this.getEvent(variables.id))
615
+ }]
616
+ };
619
617
  });
620
618
  }
621
619
  }