@smartbear/mcp 0.11.0 → 0.12.1

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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/bugsnag/client/api/Error.js +52 -14
  3. package/dist/bugsnag/client/api/Project.js +193 -8
  4. package/dist/bugsnag/client/api/api.js +130 -3
  5. package/dist/bugsnag/client/api/base.js +19 -0
  6. package/dist/bugsnag/client/api/index.js +1 -1
  7. package/dist/bugsnag/client.js +527 -20
  8. package/dist/bugsnag/input-schemas.js +14 -6
  9. package/dist/common/transport-stdio.js +5 -0
  10. package/dist/qmetry/client/auto-resolve.js +10 -0
  11. package/dist/qmetry/client/automation.js +171 -0
  12. package/dist/qmetry/client/handlers.js +9 -2
  13. package/dist/qmetry/client/project.js +87 -1
  14. package/dist/qmetry/client/testsuite.js +37 -1
  15. package/dist/qmetry/client/tools/automation-tools.js +290 -0
  16. package/dist/qmetry/client/tools/index.js +3 -0
  17. package/dist/qmetry/client/tools/issue-tools.js +1 -1
  18. package/dist/qmetry/client/tools/project-tools.js +311 -1
  19. package/dist/qmetry/client/tools/requirement-tools.js +1 -1
  20. package/dist/qmetry/client/tools/testcase-tools.js +311 -39
  21. package/dist/qmetry/client/tools/testsuite-tools.js +337 -23
  22. package/dist/qmetry/config/constants.js +6 -0
  23. package/dist/qmetry/config/rest-endpoints.js +8 -0
  24. package/dist/qmetry/types/automation.js +8 -0
  25. package/dist/qmetry/types/common.js +299 -4
  26. package/dist/qmetry/types/issues.js +5 -0
  27. package/dist/qmetry/types/project.js +13 -0
  28. package/dist/qmetry/types/requirements.js +5 -0
  29. package/dist/qmetry/types/testcase.js +5 -0
  30. package/dist/qmetry/types/testsuite.js +9 -0
  31. package/dist/swagger/client/api.js +93 -36
  32. package/dist/swagger/client/configuration.js +3 -1
  33. package/dist/swagger/client/portal-types.js +7 -6
  34. package/dist/swagger/client/registry-types.js +26 -0
  35. package/dist/swagger/client/tools.js +15 -16
  36. package/dist/swagger/client.js +6 -6
  37. package/dist/tests/unit/bugsnag/utils/factories.js +86 -0
  38. package/dist/zephyr/client.js +4 -0
  39. package/dist/zephyr/tool/environment/get-environments.js +68 -0
  40. package/dist/zephyr/tool/test-execution/get-test-executions.js +45 -0
  41. package/package.json +3 -2
@@ -10,7 +10,8 @@ const HUB_DOMAIN = "bugsnag.smartbear.com";
10
10
  const cacheKeys = {
11
11
  ORG: "bugsnag_org",
12
12
  PROJECTS: "bugsnag_projects",
13
- PROJECT_EVENT_FILTERS: "bugsnag_project_event_filters",
13
+ PROJECT_EVENT_FIELDS: "bugsnag_project_event_fields",
14
+ PROJECT_TRACE_FIELDS: "bugsnag_project_trace_fields",
14
15
  CURRENT_PROJECT: "bugsnag_current_project",
15
16
  };
16
17
  // Exclude certain event fields from the project event filters to improve agent usage
@@ -101,7 +102,7 @@ export class BugsnagClient {
101
102
  console.error("An error occurred while fetching project information", error);
102
103
  }
103
104
  if (currentProject) {
104
- await this.getProjectEventFilters(currentProject);
105
+ await this.getProjectEventFields(currentProject);
105
106
  }
106
107
  else {
107
108
  // Clear the project API key to allow tools to work across all projects
@@ -201,8 +202,8 @@ export class BugsnagClient {
201
202
  }
202
203
  return project;
203
204
  }
204
- async getProjectEventFilters(project) {
205
- const projectFiltersCache = this.cache?.get(cacheKeys.PROJECT_EVENT_FILTERS) || {};
205
+ async getProjectEventFields(project) {
206
+ const projectFiltersCache = this.cache?.get(cacheKeys.PROJECT_EVENT_FIELDS) || {};
206
207
  if (!projectFiltersCache[project.id]) {
207
208
  let filtersResponse = (await this.projectApi.listProjectEventFields(project.id)).body;
208
209
  if (!filtersResponse || filtersResponse.length === 0) {
@@ -210,7 +211,19 @@ export class BugsnagClient {
210
211
  }
211
212
  filtersResponse = filtersResponse.filter((field) => field.displayId && !EXCLUDED_EVENT_FIELDS.has(field.displayId));
212
213
  projectFiltersCache[project.id] = filtersResponse;
213
- this.cache?.set(cacheKeys.PROJECT_EVENT_FILTERS, projectFiltersCache);
214
+ this.cache?.set(cacheKeys.PROJECT_EVENT_FIELDS, projectFiltersCache);
215
+ }
216
+ return projectFiltersCache[project.id];
217
+ }
218
+ async getProjectTraceFields(project) {
219
+ const projectFiltersCache = this.cache?.get(cacheKeys.PROJECT_TRACE_FIELDS) || {};
220
+ if (!projectFiltersCache[project.id]) {
221
+ const filtersResponse = (await this.projectApi.listProjectTraceFields(project.id)).body;
222
+ if (!filtersResponse || filtersResponse.length === 0) {
223
+ throw new ToolError(`No trace fields found for project ${project.name}.`);
224
+ }
225
+ projectFiltersCache[project.id] = filtersResponse;
226
+ this.cache?.set(cacheKeys.PROJECT_TRACE_FIELDS, projectFiltersCache);
214
227
  }
215
228
  return projectFiltersCache[project.id];
216
229
  }
@@ -221,6 +234,17 @@ export class BugsnagClient {
221
234
  const projectEvents = await Promise.all(projectIds.map((projectId) => this.errorsApi.viewEventById(projectId, eventId).catch((_e) => null)));
222
235
  return projectEvents.find((event) => event && !!event.body)?.body || null;
223
236
  }
237
+ async validateEventFields(project, fields) {
238
+ if (fields) {
239
+ const eventFields = await this.getProjectEventFields(project);
240
+ const validKeys = new Set(eventFields.map((f) => f.displayId));
241
+ for (const key of Object.keys(fields)) {
242
+ if (!validKeys.has(key)) {
243
+ throw new ToolError(`Invalid filter key: ${key}`);
244
+ }
245
+ }
246
+ }
247
+ }
224
248
  async getInputProject(projectId) {
225
249
  if (typeof projectId === "string") {
226
250
  const maybeProject = await this.getProject(projectId);
@@ -361,6 +385,7 @@ export class BugsnagClient {
361
385
  hints: [
362
386
  "Error IDs can be found using the List Project Errors tool",
363
387
  "Use this after filtering errors to get detailed information about specific errors",
388
+ "Use Get Event Details tool if you need detailed information about a specific event (occurrence) rather than the aggregated error",
364
389
  "If you used a filter to get this error, you can pass the same filters here to restrict the results or apply further filters",
365
390
  "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",
366
391
  ],
@@ -375,12 +400,14 @@ export class BugsnagClient {
375
400
  error: [{ type: "eq", value: params.errorId }],
376
401
  ...args.filters,
377
402
  };
403
+ await this.validateEventFields(project, filters);
378
404
  // Get the latest event for this error using the events endpoint with filters
379
405
  let latestEvent = null;
380
406
  try {
381
407
  const latestEvents = (await this.errorsApi.listEventsOnProject(project.id, null, "timestamp", "desc", 1, filters, true)).body;
382
408
  if (latestEvents && latestEvents.length > 0) {
383
409
  latestEvent = latestEvents[0];
410
+ latestEvent.threads = undefined; // Remove threads to reduce payload size
384
411
  }
385
412
  }
386
413
  catch (e) {
@@ -397,13 +424,42 @@ export class BugsnagClient {
397
424
  content: [{ type: "text", text: JSON.stringify(content) }],
398
425
  };
399
426
  });
400
- const getEventDetailsInputSchema = z.object({
427
+ const getEventInputSchema = z.object({
428
+ projectId: toolInputParameters.projectId,
429
+ eventId: toolInputParameters.eventId,
430
+ });
431
+ register({
432
+ title: "Get Event",
433
+ summary: "Get detailed information about a specific event",
434
+ purpose: "Retrieve event details directly from its ID",
435
+ useCases: [
436
+ "Get the full details of an event, including any thread stack traces",
437
+ ],
438
+ inputSchema: getEventInputSchema,
439
+ examples: [
440
+ {
441
+ description: "Get event details of an event",
442
+ parameters: {
443
+ eventId: "6863e2af012caf1d5c320000",
444
+ },
445
+ expectedOutput: "JSON object with complete event details including stack trace (error trace and other threads, if present), metadata, and context",
446
+ },
447
+ ],
448
+ }, async (args, _extra) => {
449
+ const params = getEventInputSchema.parse(args);
450
+ const project = await this.getInputProject(params.projectId);
451
+ const response = await this.getEvent(params.eventId, project.id);
452
+ return {
453
+ content: [{ type: "text", text: JSON.stringify(response) }],
454
+ };
455
+ });
456
+ const getEventDetailsFromDashboardUrlInputSchema = z.object({
401
457
  link: z
402
458
  .string()
403
459
  .describe("Full URL to the event details page in the BugSnag dashboard (web interface), containing project slug and event_id parameter."),
404
460
  });
405
461
  register({
406
- title: "Get Event Details",
462
+ title: "Get Event Details From Dashboard URL",
407
463
  summary: "Get detailed information about a specific event using its dashboard URL",
408
464
  purpose: "Retrieve event details directly from a dashboard URL for quick debugging",
409
465
  useCases: [
@@ -411,7 +467,7 @@ export class BugsnagClient {
411
467
  "Extract event information from shared links or browser URLs",
412
468
  "Quick lookup of event details without needing separate project and event IDs",
413
469
  ],
414
- inputSchema: getEventDetailsInputSchema,
470
+ inputSchema: getEventDetailsFromDashboardUrlInputSchema,
415
471
  examples: [
416
472
  {
417
473
  description: "Get event details from a dashboard URL",
@@ -426,7 +482,7 @@ export class BugsnagClient {
426
482
  "This is useful when users share BugSnag dashboard URLs and you need to extract the event data",
427
483
  ],
428
484
  }, async (args, _extra) => {
429
- const params = getEventDetailsInputSchema.parse(args);
485
+ const params = getEventDetailsFromDashboardUrlInputSchema.parse(args);
430
486
  const url = new URL(params.link);
431
487
  const eventId = url.searchParams.get("event_id");
432
488
  const projectSlug = url.pathname.split("/")[2];
@@ -510,21 +566,13 @@ export class BugsnagClient {
510
566
  }, async (args, _extra) => {
511
567
  const params = listProjectErrorsInputSchema.parse(args);
512
568
  const project = await this.getInputProject(params.projectId);
513
- // Validate filter keys against cached event fields
514
- if (params.filters) {
515
- const eventFields = await this.getProjectEventFilters(project);
516
- const validKeys = new Set(eventFields.map((f) => f.displayId));
517
- for (const key of Object.keys(params.filters)) {
518
- if (!validKeys.has(key)) {
519
- throw new ToolError(`Invalid filter key: ${key}`);
520
- }
521
- }
522
- }
523
569
  const filters = {
524
570
  "event.since": [{ type: "eq", value: "30d" }],
525
571
  "error.status": [{ type: "eq", value: "open" }],
526
572
  ...params.filters,
527
573
  };
574
+ // Validate filter keys against cached event fields
575
+ await this.validateEventFields(project, filters);
528
576
  const response = await this.errorsApi.listProjectErrors(project.id, null, params.sort, params.direction, params.perPage, filters, params.nextUrl);
529
577
  const result = {
530
578
  data: response.body,
@@ -562,7 +610,7 @@ export class BugsnagClient {
562
610
  ],
563
611
  }, async (args, _extra) => {
564
612
  const params = listProjectEventFiltersInputSchema.parse(args);
565
- const eventFilters = await this.getProjectEventFilters(await this.getInputProject(params.projectId));
613
+ const eventFilters = await this.getProjectEventFields(await this.getInputProject(params.projectId));
566
614
  return {
567
615
  content: [{ type: "text", text: JSON.stringify(eventFilters) }],
568
616
  };
@@ -800,6 +848,465 @@ export class BugsnagClient {
800
848
  content: [{ type: "text", text: JSON.stringify(build) }],
801
849
  };
802
850
  });
851
+ // ============================================================
852
+ // Performance Monitoring Tools
853
+ // ============================================================
854
+ const listSpanGroupsInputSchema = z.object({
855
+ projectId: toolInputParameters.projectId,
856
+ sort: z
857
+ .enum([
858
+ "total_spans",
859
+ "last_seen",
860
+ "name",
861
+ "display_name",
862
+ "network_http_method",
863
+ "rendering_slow_frame_span_percentage",
864
+ "rendering_frozen_frame_span_percentage",
865
+ "duration_p50",
866
+ "duration_p75",
867
+ "duration_p90",
868
+ "duration_p95",
869
+ "duration_p99",
870
+ "system_metrics_cpu_total_mean_p50",
871
+ "system_metrics_cpu_total_mean_p75",
872
+ "system_metrics_cpu_total_mean_p90",
873
+ "system_metrics_cpu_total_mean_p95",
874
+ "system_metrics_cpu_total_mean_p99",
875
+ "system_metrics_memory_device_mean_p50",
876
+ "system_metrics_memory_device_mean_p75",
877
+ "system_metrics_memory_device_mean_p90",
878
+ "system_metrics_memory_device_mean_p95",
879
+ "system_metrics_memory_device_mean_p99",
880
+ "rendering_metrics_fps_mean_p50",
881
+ "rendering_metrics_fps_mean_p75",
882
+ "rendering_metrics_fps_mean_p90",
883
+ "rendering_metrics_fps_mean_p95",
884
+ "rendering_metrics_fps_mean_p99",
885
+ "http_response_4xx_percentage",
886
+ "http_response_5xx_percentage",
887
+ ])
888
+ .optional()
889
+ .describe("Field to sort by"),
890
+ direction: toolInputParameters.direction,
891
+ perPage: toolInputParameters.perPage,
892
+ starredOnly: z
893
+ .boolean()
894
+ .optional()
895
+ .describe("Show only starred span groups"),
896
+ nextUrl: toolInputParameters.nextUrl,
897
+ filters: toolInputParameters.performanceFilters,
898
+ });
899
+ register({
900
+ title: "List Span Groups",
901
+ summary: "List span groups (operations) tracked for performance monitoring",
902
+ purpose: "Discover and analyze different operations being monitored",
903
+ useCases: [
904
+ "View all operations being tracked for performance",
905
+ "Find slow operations by sorting by duration metrics",
906
+ "Filter to starred/important span groups",
907
+ ],
908
+ inputSchema: listSpanGroupsInputSchema,
909
+ examples: [
910
+ {
911
+ description: "List slowest operations",
912
+ parameters: {
913
+ sort: "duration_p95",
914
+ direction: "desc",
915
+ perPage: 10,
916
+ },
917
+ expectedOutput: "Array of span groups sorted by 95th percentile duration",
918
+ },
919
+ {
920
+ description: "List starred span groups with filtering",
921
+ parameters: {
922
+ starredOnly: true,
923
+ filters: {
924
+ "span_group.category": [
925
+ { type: "eq", value: "full_page_load" },
926
+ ],
927
+ },
928
+ },
929
+ expectedOutput: "Array of starred span groups filtered by category",
930
+ },
931
+ ],
932
+ hints: [
933
+ "Span groups represent different operation types (page loads, API calls, etc.)",
934
+ "Use sort by duration_p95 or duration_p99 to find the slowest operations",
935
+ "Star important span groups for quick access",
936
+ "Use nextUrl for pagination",
937
+ ],
938
+ }, async (args, _extra) => {
939
+ const params = listSpanGroupsInputSchema.parse(args);
940
+ const project = await this.getInputProject(params.projectId);
941
+ const result = await this.projectApi.listProjectSpanGroups(project.id, params.sort, params.direction, params.perPage, undefined, params.filters, params.starredOnly, params.nextUrl);
942
+ return {
943
+ content: [
944
+ {
945
+ type: "text",
946
+ text: JSON.stringify({
947
+ data: result.body,
948
+ next_url: result.nextUrl,
949
+ count: result.body?.length,
950
+ }),
951
+ },
952
+ ],
953
+ };
954
+ });
955
+ const getSpanGroupInputSchema = z.object({
956
+ projectId: toolInputParameters.projectId,
957
+ spanGroupId: toolInputParameters.spanGroupId,
958
+ filters: toolInputParameters.performanceFilters,
959
+ });
960
+ register({
961
+ title: "Get Span Group",
962
+ summary: "Get detailed performance metrics for a specific span group",
963
+ purpose: "Analyze performance characteristics of a specific operation",
964
+ useCases: [
965
+ "View detailed statistics (p50, p75, p90, p95, p99) for an operation",
966
+ "Check if performance targets are configured",
967
+ "Monitor span count to understand operation volume",
968
+ ],
969
+ inputSchema: getSpanGroupInputSchema,
970
+ examples: [
971
+ {
972
+ description: "Get details for an API endpoint span group",
973
+ parameters: { spanGroupId: "[HttpClient]GET-api.example.com" },
974
+ expectedOutput: "Statistics, category, and performance target info",
975
+ },
976
+ {
977
+ description: "Get span group details with device filtering",
978
+ parameters: {
979
+ spanGroupId: "[HttpClient]GET-api.example.com",
980
+ filters: {
981
+ "device.browser_name": [{ type: "eq", value: "Chrome" }],
982
+ },
983
+ },
984
+ expectedOutput: "Statistics filtered for Chrome browser only",
985
+ },
986
+ ],
987
+ hints: [
988
+ "Use List Span Groups first to discover available span group IDs",
989
+ "IDs are automatically URL-encoded - provide the raw ID",
990
+ "Statistics include p50, p75, p90, p95, p99 percentiles",
991
+ ],
992
+ }, async (args, _extra) => {
993
+ const params = getSpanGroupInputSchema.parse(args);
994
+ const project = await this.getInputProject(params.projectId);
995
+ const spanGroupResults = await this.projectApi.getProjectSpanGroup(project.id, params.spanGroupId, params.filters);
996
+ const spanGroupTimelineResult = await this.projectApi.getProjectSpanGroupTimeline(project.id, params.spanGroupId, params.filters);
997
+ const spanGroupDistributionResult = await this.projectApi.getProjectSpanGroupDistribution(project.id, params.spanGroupId, params.filters);
998
+ const result = {
999
+ ...spanGroupResults.body,
1000
+ timeline: spanGroupTimelineResult.body,
1001
+ distribution: spanGroupDistributionResult.body,
1002
+ };
1003
+ return {
1004
+ content: [{ type: "text", text: JSON.stringify(result) }],
1005
+ };
1006
+ });
1007
+ const listSpansInputSchema = z.object({
1008
+ projectId: toolInputParameters.projectId,
1009
+ spanGroupId: toolInputParameters.spanGroupId,
1010
+ sort: z
1011
+ .enum([
1012
+ "duration",
1013
+ "timestamp",
1014
+ "full_page_load_lcp",
1015
+ "full_page_load_fid",
1016
+ "full_page_load_cls",
1017
+ "full_page_load_ttfb",
1018
+ "full_page_load_fcp",
1019
+ "rendering_slow_frame_percentage",
1020
+ "rendering_frozen_frame_percentage",
1021
+ "system_metrics_cpu_total_mean",
1022
+ "system_metrics_memory_device_mean",
1023
+ "rendering_metrics_fps_mean",
1024
+ "rendering_metrics_fps_minimum",
1025
+ "rendering_metrics_fps_maximum",
1026
+ "http_response_code",
1027
+ ])
1028
+ .optional()
1029
+ .describe("Field to sort by"),
1030
+ direction: toolInputParameters.direction,
1031
+ perPage: toolInputParameters.perPage,
1032
+ nextUrl: toolInputParameters.nextUrl,
1033
+ filters: toolInputParameters.performanceFilters,
1034
+ });
1035
+ register({
1036
+ title: "List Spans",
1037
+ summary: "Get individual spans belonging to a span group",
1038
+ purpose: "Examine individual operation instances within a span group",
1039
+ useCases: [
1040
+ "Analyze individual slow operations",
1041
+ "Debug performance issues by examining specific traces",
1042
+ "Find patterns in operation attributes",
1043
+ ],
1044
+ inputSchema: listSpansInputSchema,
1045
+ examples: [
1046
+ {
1047
+ description: "Get slowest spans for an operation",
1048
+ parameters: {
1049
+ spanGroupId: "[HttpClient]GET-api.example.com",
1050
+ sort: "duration",
1051
+ direction: "desc",
1052
+ perPage: 10,
1053
+ },
1054
+ expectedOutput: "Array of the 10 slowest span instances",
1055
+ },
1056
+ {
1057
+ description: "Get spans filtered by OS with pagination",
1058
+ parameters: {
1059
+ spanGroupId: "[HttpClient]GET-api.example.com",
1060
+ sort: "timestamp",
1061
+ filters: {
1062
+ "os.name": [{ type: "eq", value: "iOS" }],
1063
+ },
1064
+ nextUrl: "/projects/123/spans?offset=30&per_page=30",
1065
+ },
1066
+ expectedOutput: "Array of spans from iOS devices with next page navigation",
1067
+ },
1068
+ ],
1069
+ hints: [
1070
+ "Sort by duration descending to find the slowest instances",
1071
+ "Each span includes trace ID for further investigation",
1072
+ ],
1073
+ }, async (args, _extra) => {
1074
+ const params = listSpansInputSchema.parse(args);
1075
+ const project = await this.getInputProject(params.projectId);
1076
+ const result = await this.projectApi.listSpansBySpanGroupId(project.id, params.spanGroupId, params.filters, params.sort, params.direction, params.perPage, params.nextUrl);
1077
+ return {
1078
+ content: [
1079
+ {
1080
+ type: "text",
1081
+ text: JSON.stringify({
1082
+ data: result.body,
1083
+ next_url: result.nextUrl,
1084
+ count: result.body?.length,
1085
+ }),
1086
+ },
1087
+ ],
1088
+ };
1089
+ });
1090
+ const getTraceInputSchema = z.object({
1091
+ projectId: toolInputParameters.projectId,
1092
+ traceId: z.string().describe("Trace ID"),
1093
+ from: z.string().describe("Start time (ISO 8601 format)"),
1094
+ to: z.string().describe("End time (ISO 8601 format)"),
1095
+ targetSpanId: z
1096
+ .string()
1097
+ .optional()
1098
+ .describe("Optional target span ID to focus on"),
1099
+ perPage: toolInputParameters.perPage,
1100
+ nextUrl: toolInputParameters.nextUrl,
1101
+ });
1102
+ register({
1103
+ title: "Get Trace",
1104
+ summary: "Get all spans within a specific trace",
1105
+ purpose: "View the complete trace of operations for a request/transaction",
1106
+ useCases: [
1107
+ "Debug slow requests by viewing all operations in the trace",
1108
+ "Understand the flow of a request through the system",
1109
+ "Identify bottlenecks in distributed systems",
1110
+ ],
1111
+ inputSchema: getTraceInputSchema,
1112
+ examples: [
1113
+ {
1114
+ description: "Get all spans for a trace",
1115
+ parameters: {
1116
+ traceId: "abc123",
1117
+ from: "2024-01-01T00:00:00Z",
1118
+ to: "2024-01-01T23:59:59Z",
1119
+ },
1120
+ expectedOutput: "Array of all spans in the trace with timing and hierarchy",
1121
+ },
1122
+ {
1123
+ description: "Get spans for a trace with pagination and target span",
1124
+ parameters: {
1125
+ traceId: "def456",
1126
+ from: "2024-01-01T00:00:00Z",
1127
+ to: "2024-01-01T23:59:59Z",
1128
+ targetSpanId: "span-789",
1129
+ perPage: 50,
1130
+ },
1131
+ expectedOutput: "Array of up to 50 spans focused around the target span",
1132
+ },
1133
+ ],
1134
+ hints: [
1135
+ "Traces show the complete execution path of a request",
1136
+ "Use from/to parameters to narrow the time window",
1137
+ "targetSpanId can be used to focus on a specific span in the trace",
1138
+ ],
1139
+ }, async (args, _extra) => {
1140
+ const params = getTraceInputSchema.parse(args);
1141
+ const project = await this.getInputProject(params.projectId);
1142
+ if (!params.traceId || !params.from || !params.to) {
1143
+ throw new ToolError("traceId, from, and to are required");
1144
+ }
1145
+ const result = await this.projectApi.listSpansByTraceId(project.id, params.traceId, params.from, params.to, params.targetSpanId, params.perPage, params.nextUrl);
1146
+ return {
1147
+ content: [
1148
+ {
1149
+ type: "text",
1150
+ text: JSON.stringify({
1151
+ data: result.body,
1152
+ next_url: result.nextUrl,
1153
+ count: result.body?.length,
1154
+ }),
1155
+ },
1156
+ ],
1157
+ };
1158
+ });
1159
+ const listTraceFieldsInputSchema = z.object({
1160
+ projectId: toolInputParameters.projectId,
1161
+ });
1162
+ // Similar to event filters, consider caching
1163
+ register({
1164
+ title: "List Trace Fields",
1165
+ summary: "Get available trace fields/attributes for filtering",
1166
+ purpose: "Discover what custom attributes are available for filtering",
1167
+ useCases: [
1168
+ "Find available custom attributes for performance filtering",
1169
+ "Understand what metadata is attached to traces",
1170
+ "Build dynamic filters based on available fields",
1171
+ ],
1172
+ inputSchema: listTraceFieldsInputSchema,
1173
+ examples: [
1174
+ {
1175
+ description: "Get all trace fields",
1176
+ parameters: {},
1177
+ expectedOutput: "Array of field names and types available for filtering",
1178
+ },
1179
+ ],
1180
+ hints: [
1181
+ "Trace fields are custom attributes added to spans",
1182
+ "Use these fields for filtering other performance queries",
1183
+ ],
1184
+ }, async (args, _extra) => {
1185
+ const params = listTraceFieldsInputSchema.parse(args);
1186
+ const project = await this.getInputProject(params.projectId);
1187
+ const traceFields = await this.getProjectTraceFields(project);
1188
+ return {
1189
+ content: [{ type: "text", text: JSON.stringify(traceFields) }],
1190
+ };
1191
+ });
1192
+ const getNetworkGroupingInputSchema = z.object({
1193
+ projectId: toolInputParameters.projectId,
1194
+ });
1195
+ register({
1196
+ title: "Get Network Endpoint Groupings",
1197
+ summary: "Get the network endpoint grouping rules for a project",
1198
+ purpose: "Retrieve the URL patterns used to group network spans for performance monitoring",
1199
+ useCases: [
1200
+ "View current network endpoint grouping configuration",
1201
+ "Understand how network requests are being grouped in performance monitoring",
1202
+ "Check grouping patterns before making updates",
1203
+ ],
1204
+ inputSchema: getNetworkGroupingInputSchema,
1205
+ examples: [
1206
+ {
1207
+ description: "Get network grouping rules for a project",
1208
+ parameters: {},
1209
+ expectedOutput: "Array of endpoint URL patterns",
1210
+ },
1211
+ ],
1212
+ hints: [
1213
+ "Network grouping patterns help consolidate similar requests into single span groups",
1214
+ "Patterns use OpenAPI path templating syntax with curly braces for path parameters (e.g., /users/{userId})",
1215
+ "Wildcards (*) can be used in domains to match multiple subdomains (e.g., https://*.example.com)",
1216
+ ],
1217
+ readOnly: true,
1218
+ idempotent: true,
1219
+ }, async (args, _extra) => {
1220
+ const params = getNetworkGroupingInputSchema.parse(args);
1221
+ const project = await this.getInputProject(params.projectId);
1222
+ const result = await this.projectApi.getProjectNetworkGroupingRuleset(project.id);
1223
+ return {
1224
+ content: [
1225
+ { type: "text", text: JSON.stringify(result.body.endpoints || []) },
1226
+ ],
1227
+ };
1228
+ });
1229
+ const setNetworkGroupingInputSchema = z.object({
1230
+ projectId: toolInputParameters.projectId,
1231
+ endpoints: z
1232
+ .array(z.string())
1233
+ .describe("Array of URL patterns by which network spans are grouped. " +
1234
+ "Endpoints follow OpenAPI path templating syntax (https://swagger.io/specification/#path-templating) where path parameters use curly braces (e.g., /users/{id}). " +
1235
+ "If you encounter colon-prefixed parameters (e.g., :userId from Express/React Router), convert them to curly braces (e.g., {userId}). " +
1236
+ "Wildcards (*) can be used in domains (e.g., https://*.example.com) to match multiple subdomains."),
1237
+ });
1238
+ register({
1239
+ title: "Set Network Endpoint Groupings",
1240
+ summary: "Set the network endpoint grouping rules for a project",
1241
+ purpose: "Configure URL patterns to control how network spans are grouped in performance monitoring",
1242
+ useCases: [
1243
+ "Consolidate similar API endpoints into single span groups",
1244
+ "Group dynamic URLs using path parameters (e.g., /api/users/{userId} groups /api/users/123, /api/users/456)",
1245
+ "Match multiple subdomains using wildcards (e.g., https://*.example.com groups api.example.com, cdn.example.com)",
1246
+ "Simplify performance monitoring by reducing span group clutter",
1247
+ ],
1248
+ inputSchema: setNetworkGroupingInputSchema,
1249
+ examples: [
1250
+ {
1251
+ description: "Group API endpoints with path parameters",
1252
+ parameters: {
1253
+ endpoints: [
1254
+ "/api/users/{userId}",
1255
+ "/api/products/{productId}",
1256
+ "/api/orders/{orderId}/items/{itemId}",
1257
+ ],
1258
+ },
1259
+ expectedOutput: "Success response confirming the update",
1260
+ },
1261
+ {
1262
+ description: "Group endpoints with domain wildcards and path parameters",
1263
+ parameters: {
1264
+ endpoints: [
1265
+ "https://*.example.com/api/v1/{resourceId}",
1266
+ "https://api.example.com/v2/users/{userId}",
1267
+ "/graphql",
1268
+ ],
1269
+ },
1270
+ expectedOutput: "Success response confirming the update",
1271
+ },
1272
+ {
1273
+ description: "Convert colon-prefixed parameters to curly braces (e.g., from Express/React Router)",
1274
+ parameters: {
1275
+ endpoints: [
1276
+ "/{organizationSlug}/{projectSlug}/performance/view-load",
1277
+ "/api/{version}/items/{itemId}",
1278
+ ],
1279
+ },
1280
+ expectedOutput: "Success response confirming the update",
1281
+ },
1282
+ ],
1283
+ hints: [
1284
+ "Use Get Network Grouping first to see current patterns",
1285
+ "Use OpenAPI path templating with curly braces for path parameters: /users/{userId}, /orders/{orderId}/items/{itemId}",
1286
+ "Convert colon-prefixed parameters to curly braces: :organizationSlug becomes {organizationSlug}, :projectSlug becomes {projectSlug}",
1287
+ "Wildcards (*) can be used in domains to match subdomains: https://*.example.com/api",
1288
+ "This replaces all existing patterns - include all patterns you want to keep",
1289
+ "Well-designed patterns reduce noise in performance monitoring",
1290
+ ],
1291
+ readOnly: false,
1292
+ idempotent: true,
1293
+ }, async (args, _extra) => {
1294
+ const params = setNetworkGroupingInputSchema.parse(args);
1295
+ const project = await this.getInputProject(params.projectId);
1296
+ const result = await this.projectApi.updateProjectNetworkGroupingRuleset(project.id, params.endpoints);
1297
+ return {
1298
+ content: [
1299
+ {
1300
+ type: "text",
1301
+ text: JSON.stringify({
1302
+ success: result.status === 200 || result.status === 204,
1303
+ projectId: project.id,
1304
+ endpoints: params.endpoints,
1305
+ }),
1306
+ },
1307
+ ],
1308
+ };
1309
+ });
803
1310
  }
804
1311
  registerResources(register) {
805
1312
  register("event", "{id}", async (uri, variables, _extra) => {