@smartbear/mcp 0.3.0 → 0.5.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,621 +0,0 @@
1
- import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import { MCP_SERVER_NAME, MCP_SERVER_VERSION } from "../common/info.js";
3
- 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
- import { ProjectAPI } from "./client/api/Project.js";
8
- import { FilterObjectSchema, toQueryString } from "./client/api/filters.js";
9
- import { toolDescriptionTemplate, createParameter, createExample } from "../common/templates.js";
10
- const HUB_PREFIX = "00000";
11
- const DEFAULT_DOMAIN = "bugsnag.com";
12
- const HUB_DOMAIN = "insighthub.smartbear.com";
13
- const cacheKeys = {
14
- ORG: "insight_hub_org",
15
- PROJECTS: "insight_hub_projects",
16
- CURRENT_PROJECT: "insight_hub_current_project",
17
- CURRENT_PROJECT_EVENT_FILTERS: "insight_hub_current_project_event_filters",
18
- };
19
- // Exclude certain event fields from the project event filters to improve agent usage
20
- const EXCLUDED_EVENT_FIELDS = new Set([
21
- "search" // This is searches multiple fields and is more a convenience for humans, we're removing to avoid over-matching
22
- ]);
23
- const PERMITTED_UPDATE_OPERATIONS = [
24
- "override_severity",
25
- "open",
26
- "fix",
27
- "ignore",
28
- "discard",
29
- "undiscard"
30
- ];
31
- export class InsightHubClient {
32
- currentUserApi;
33
- errorsApi;
34
- cache;
35
- projectApi;
36
- projectApiKey;
37
- apiEndpoint;
38
- appEndpoint;
39
- constructor(token, projectApiKey, endpoint) {
40
- this.apiEndpoint = this.getEndpoint("api", projectApiKey, endpoint);
41
- this.appEndpoint = this.getEndpoint("app", projectApiKey, endpoint);
42
- const config = new Configuration({
43
- authToken: token,
44
- headers: {
45
- "User-Agent": `${MCP_SERVER_NAME}/${MCP_SERVER_VERSION}`,
46
- "Content-Type": "application/json",
47
- "X-Bugsnag-API": "true",
48
- "X-Version": "2",
49
- },
50
- basePath: this.apiEndpoint,
51
- });
52
- this.currentUserApi = new CurrentUserAPI(config);
53
- this.errorsApi = new ErrorAPI(config);
54
- this.cache = new NodeCache();
55
- this.projectApi = new ProjectAPI(config);
56
- this.projectApiKey = projectApiKey;
57
- }
58
- async initialize() {
59
- // Trigger caching of org and projects
60
- await this.getProjects();
61
- await this.getCurrentProject();
62
- }
63
- getHost(apiKey, subdomain) {
64
- if (apiKey && apiKey.startsWith(HUB_PREFIX)) {
65
- return `https://${subdomain}.${HUB_DOMAIN}`;
66
- }
67
- else {
68
- return `https://${subdomain}.${DEFAULT_DOMAIN}`;
69
- }
70
- }
71
- // If the endpoint is not provided, it will use the default API endpoint based on the project API key.
72
- // if the project api key is not provided, the endpoint will be the default API endpoint.
73
- // if the endpoint is provided, it will be used as is for custom domains, or normalized for known domains.
74
- getEndpoint(subdomain, apiKey, endpoint) {
75
- let subDomainEndpoint;
76
- if (!endpoint) {
77
- if (apiKey && apiKey.startsWith(HUB_PREFIX)) {
78
- subDomainEndpoint = `https://${subdomain}.${HUB_DOMAIN}`;
79
- }
80
- else {
81
- subDomainEndpoint = `https://${subdomain}.${DEFAULT_DOMAIN}`;
82
- }
83
- }
84
- else {
85
- // check if the endpoint matches either the HUB_DOMAIN or DEFAULT_DOMAIN
86
- const url = new URL(endpoint);
87
- if (url.hostname.endsWith(HUB_DOMAIN) || url.hostname.endsWith(DEFAULT_DOMAIN)) {
88
- // For known domains (Hub or Bugsnag), always use HTTPS and standard format
89
- if (url.hostname.endsWith(HUB_DOMAIN)) {
90
- subDomainEndpoint = `https://${subdomain}.${HUB_DOMAIN}`;
91
- }
92
- else {
93
- subDomainEndpoint = `https://${subdomain}.${DEFAULT_DOMAIN}`;
94
- }
95
- }
96
- else {
97
- // For custom domains, use the endpoint exactly as provided
98
- subDomainEndpoint = endpoint;
99
- }
100
- }
101
- return subDomainEndpoint;
102
- }
103
- async getDashboardUrl(project) {
104
- return `${this.appEndpoint}/${(await this.getOrganization()).slug}/${project.slug}`;
105
- }
106
- async getErrorUrl(project, errorId, queryString = '') {
107
- const dashboardUrl = await this.getDashboardUrl(project);
108
- return `${dashboardUrl}/errors/${errorId}${queryString}`;
109
- }
110
- async getOrganization() {
111
- let org = this.cache.get(cacheKeys.ORG);
112
- if (!org) {
113
- const response = await this.currentUserApi.listUserOrganizations();
114
- const orgs = response.body || [];
115
- if (!orgs || orgs.length === 0) {
116
- throw new Error("No organizations found for the current user.");
117
- }
118
- org = orgs[0];
119
- this.cache.set(cacheKeys.ORG, org);
120
- }
121
- return org;
122
- }
123
- // This method retrieves all projects for the organization stored in the cache.
124
- // If no projects are found in the cache, it fetches them from the API and
125
- // stores them in the cache for future use.
126
- // It throws an error if no organizations are found in the cache.
127
- async getProjects() {
128
- let projects = this.cache.get(cacheKeys.PROJECTS);
129
- if (!projects) {
130
- const org = await this.getOrganization();
131
- const options = {
132
- paginate: true
133
- };
134
- const response = await this.currentUserApi.getOrganizationProjects(org.id, options);
135
- projects = response.body || [];
136
- this.cache.set(cacheKeys.PROJECTS, projects);
137
- }
138
- return projects;
139
- }
140
- async getProject(projectId) {
141
- const projects = await this.getProjects();
142
- return projects.find((p) => p.id === projectId) || null;
143
- }
144
- async getCurrentProject() {
145
- let project = this.cache.get(cacheKeys.CURRENT_PROJECT) ?? null;
146
- if (!project && this.projectApiKey) {
147
- const projects = await this.getProjects();
148
- project = projects.find((p) => p.api_key === this.projectApiKey) ?? null;
149
- if (!project) {
150
- throw new Error(`Unable to find project with API key ${this.projectApiKey} in organization.`);
151
- }
152
- this.cache.set(cacheKeys.CURRENT_PROJECT, project);
153
- if (project) {
154
- this.cache.set(cacheKeys.CURRENT_PROJECT_EVENT_FILTERS, await this.getProjectEventFilters(project));
155
- }
156
- }
157
- return project;
158
- }
159
- async getProjectEventFilters(project) {
160
- let filtersResponse = (await this.projectApi.listProjectEventFields(project.id)).body;
161
- if (!filtersResponse || filtersResponse.length === 0) {
162
- throw new Error(`No event fields found for project ${project.name}.`);
163
- }
164
- filtersResponse = filtersResponse.filter(field => !EXCLUDED_EVENT_FIELDS.has(field.display_id));
165
- return filtersResponse;
166
- }
167
- async getEvent(eventId, projectId) {
168
- const projectIds = projectId ? [projectId] : (await this.getProjects()).map((p) => p.id);
169
- const projectEvents = await Promise.all(projectIds.map((projectId) => this.errorsApi.viewEventById(projectId, eventId).catch(_e => null)));
170
- return projectEvents.find(event => event && !!event.body)?.body || null;
171
- }
172
- async updateError(projectId, errorId, operation, options) {
173
- const errorUpdateRequest = {
174
- operation: operation,
175
- ...options
176
- };
177
- const response = await this.errorsApi.updateErrorOnProject(projectId, errorId, errorUpdateRequest);
178
- return response.status === 200 || response.status === 204;
179
- }
180
- async getInputProject(projectId) {
181
- if (typeof projectId === 'string') {
182
- const maybeProject = await this.getProject(projectId);
183
- if (!maybeProject) {
184
- throw new Error(`Project with ID ${projectId} not found.`);
185
- }
186
- return maybeProject;
187
- }
188
- else {
189
- const currentProject = await this.getCurrentProject();
190
- if (!currentProject) {
191
- throw new Error('No current project found. Please provide a projectId or configure a project API key.');
192
- }
193
- return currentProject;
194
- }
195
- }
196
- registerTools(server) {
197
- 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.",
262
- 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"
267
- ],
268
- 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
- })
288
- ],
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
- 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")
298
- ],
299
- 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",
305
- ]
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;
340
- }
341
- catch (e) {
342
- console.warn("Failed to fetch latest event:", e);
343
- // Continue without latest event rather than failing the entire request
344
- }
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}`),
350
- };
351
- return {
352
- content: [{ type: "text", text: JSON.stringify(content) }]
353
- };
354
- }
355
- catch (e) {
356
- Bugsnag.notify(e);
357
- throw e;
358
- }
359
- });
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", {
381
- 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.");
406
- }
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;
415
- }
416
- });
417
- // 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", {
448
- filters: {
449
- "user.email": [{ "type": "eq", "value": "user@example.com" }],
450
- "event.since": [{ "type": "eq", "value": "24h" }]
451
- }
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
- }
466
- }, 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
- }
477
- }
478
- }
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
- }
493
- });
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: {}
513
- }, 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
- }
526
- });
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", {
549
- errorId: "6863e2af8c857c0a5023b411",
550
- 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
- }
569
- }, async (args, _extra) => {
570
- 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
- }
586
- }
587
- },
588
- required: ["severity"]
589
- });
590
- if (result.action === "accept" && result.content?.severity) {
591
- severity = result.content.severity;
592
- }
593
- }
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
- }
603
- });
604
- }
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
- }
619
- });
620
- }
621
- }