@smartbear/mcp 0.35.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +1 -1
  2. package/dist/bearq/tool/tasks/wait-for-task.js +3 -3
  3. package/dist/bugsnag/client.js +1 -1
  4. package/dist/bugsnag/tool/error/get-error.js +1 -1
  5. package/dist/bugsnag/tool/error/list-project-errors.js +1 -1
  6. package/dist/bugsnag/tool/error/update-error.js +1 -1
  7. package/dist/bugsnag/tool/event/get-event-details-from-dashboard-url.js +1 -1
  8. package/dist/bugsnag/tool/event/get-event.js +1 -1
  9. package/dist/bugsnag/tool/event/list-error-events.js +1 -1
  10. package/dist/bugsnag/tool/performance/get-network-endpoint-groupings.js +1 -1
  11. package/dist/bugsnag/tool/performance/get-span-group.js +1 -1
  12. package/dist/bugsnag/tool/performance/get-trace.js +1 -1
  13. package/dist/bugsnag/tool/performance/list-span-groups.js +1 -1
  14. package/dist/bugsnag/tool/performance/list-spans.js +1 -1
  15. package/dist/bugsnag/tool/performance/list-trace-fields.js +1 -1
  16. package/dist/bugsnag/tool/performance/set-network-endpoint-groupings.js +1 -1
  17. package/dist/bugsnag/tool/project/get-current-project.js +1 -1
  18. package/dist/bugsnag/tool/project/list-project-event-filters.js +1 -1
  19. package/dist/bugsnag/tool/project/list-projects.js +1 -1
  20. package/dist/bugsnag/tool/release/get-build.js +1 -1
  21. package/dist/bugsnag/tool/release/get-release.js +1 -1
  22. package/dist/bugsnag/tool/release/list-releases.js +1 -1
  23. package/dist/collaborator/client.js +10 -10
  24. package/dist/common/server.js +11 -32
  25. package/dist/common/transport-http.js +5 -5
  26. package/dist/common/transport-stdio.js +1 -1
  27. package/dist/common/zod-utils.js +2 -1
  28. package/dist/package.json.js +1 -1
  29. package/dist/pactflow/client/base.js +8 -4
  30. package/dist/pactflow/client/tools.js +2 -2
  31. package/dist/pactflow/client.js +4 -4
  32. package/dist/qmetry/client/auto-resolve.js +5 -0
  33. package/dist/qmetry/client/date-utils.js +104 -0
  34. package/dist/qmetry/client/handlers.js +9 -5
  35. package/dist/qmetry/client/issues.js +124 -7
  36. package/dist/qmetry/client/testcase.js +36 -2
  37. package/dist/qmetry/client/testsuite.js +27 -2
  38. package/dist/qmetry/client/tools/issue-tools.js +202 -23
  39. package/dist/qmetry/client/tools/project-tools.js +14 -2
  40. package/dist/qmetry/client/tools/testcase-tools.js +275 -14
  41. package/dist/qmetry/client/tools/testsuite-tools.js +152 -5
  42. package/dist/qmetry/client/tools/udf-tools.js +83 -5
  43. package/dist/qmetry/client/udf.js +159 -4
  44. package/dist/qmetry/client.js +236 -1
  45. package/dist/qmetry/config/constants.js +5 -1
  46. package/dist/qmetry/config/rest-endpoints.js +7 -3
  47. package/dist/qmetry/types/common.js +113 -12
  48. package/dist/qmetry/types/testcase.js +1 -2
  49. package/dist/qmetry/types/udf.js +12 -1
  50. package/dist/reflect/tool/recording/connect-to-session.js +2 -2
  51. package/dist/swagger/client/api.js +96 -12
  52. package/dist/swagger/client/functional-testing-api.js +7 -1
  53. package/dist/swagger/client/functional-testing-tools.js +20 -17
  54. package/dist/swagger/client/functional-testing-types.js +184 -1
  55. package/dist/swagger/client/patch-spec-utils.js +31 -0
  56. package/dist/swagger/client/portal-types.js +1 -1
  57. package/dist/swagger/client/registry-types.js +44 -0
  58. package/dist/swagger/client/tools.js +11 -2
  59. package/dist/swagger/client/utils.js +8 -0
  60. package/dist/swagger/client.js +6 -2
  61. package/dist/zephyr/common/rest-api-schemas.js +3748 -3698
  62. package/dist/zephyr/tool/test-case/create-issue-link.js +4 -2
  63. package/dist/zephyr/tool/test-case/create-test-script.js +4 -2
  64. package/dist/zephyr/tool/test-case/create-test-steps.js +5 -1
  65. package/dist/zephyr/tool/test-case/get-test-steps.js +4 -2
  66. package/dist/zephyr/tool/test-case/update-test-case.js +3 -1
  67. package/dist/zephyr/tool/test-cycle/create-issue-link.js +4 -2
  68. package/dist/zephyr/tool/test-cycle/create-web-link.js +4 -2
  69. package/dist/zephyr/tool/test-cycle/update-test-cycle.js +5 -1
  70. package/dist/zephyr/tool/test-execution/create-issue-link.js +4 -2
  71. package/dist/zephyr/tool/test-execution/get-test-steps.js +4 -2
  72. package/dist/zephyr/tool/test-execution/update-test-execution.js +4 -2
  73. package/dist/zephyr/tool/test-execution/update-test-steps.js +4 -2
  74. package/package.json +7 -2
@@ -1,6 +1,81 @@
1
1
  import { QMetryToolsHandlers } from "../../config/constants.js";
2
- import { BulkUpdateTestRunUdfsArgsSchema, FetchTestRunUdfMetadataArgsSchema, FetchTestRunUdfValuesArgsSchema, FetchCascadeChildValuesArgsSchema } from "../../types/udf.js";
2
+ import { FetchUdfLayoutArgsSchema, BulkUpdateTestRunUdfsArgsSchema, FetchTestRunUdfMetadataArgsSchema, FetchTestRunUdfValuesArgsSchema, FetchCascadeChildValuesArgsSchema } from "../../types/udf.js";
3
3
  const UDF_TOOLS = [
4
+ {
5
+ title: "Fetch UDF Layout",
6
+ toolset: "UDF",
7
+ summary: "Fetch UDF (User Defined Field) definitions for Test Case, Test Suite, or Issue entities. Returns field names, types, fieldIDs, and lookup option IDs. Call this BEFORE creating or updating an entity with UDF values.",
8
+ handler: QMetryToolsHandlers.FETCH_UDF_LAYOUT,
9
+ inputSchema: FetchUdfLayoutArgsSchema,
10
+ purpose: "Discovers the UDF fields configured for a given entity type (TC/TS/IS) in the current QMetry project. For 'ADD' (create): returns field names, types, and list option IDs — no fieldID needed. For 'DETAIL' (update): returns fieldID (projectUserFieldID) required in the UDF update wrapper. Also returns step UDF definitions for Test Cases (stepFields). The 'listOptions' map provides valid IDs for LOOKUPLIST, MULTILOOKUPLIST, and CASCADINGLIST fields. For CASCADINGLIST child options, also call 'Fetch Cascade Child Values' after selecting a parent.",
11
+ useCases: [
12
+ "Discover UDF fields before creating a Test Case with custom fields",
13
+ "Get fieldIDs before updating a Test Suite's UDF values",
14
+ "Find valid dropdown option IDs for a LOOKUPLIST UDF before setting a value",
15
+ "Identify mandatory UDF fields before creating an Issue",
16
+ "List all step-level UDF fields available for Test Case steps",
17
+ "Get CASCADINGLIST parent option IDs before fetching child values"
18
+ ],
19
+ examples: [
20
+ {
21
+ description: "Get UDF field definitions for creating a Test Case",
22
+ parameters: { entityType: "TC", pageName: "ADD" },
23
+ expectedOutput: "{ fields: [{ name: 'custom_text', label: 'Custom Text', fieldTypeName: 'STRING', fieldID: null, isMandatory: false }, ...], stepFields: [{ name: 'step_field', label: 'Step Field', fieldTypeName: 'STRING', ... }], listOptions: { myListKey: [{ id: 101, name: 'Option A' }] } }"
24
+ },
25
+ {
26
+ description: "Get UDF fieldIDs for updating a Test Suite",
27
+ parameters: { entityType: "TS", pageName: "DETAIL" },
28
+ expectedOutput: "{ fields: [{ name: 'dropdown_field', label: 'Dropdown', fieldTypeName: 'LOOKUPLIST', fieldID: 2002, isMandatory: false, listName: 'myListKey' }, ...], listOptions: { myListKey: [{ id: 101, name: 'Option A' }, { id: 102, name: 'Option B' }] } }"
29
+ },
30
+ {
31
+ description: "Get UDF field definitions for creating an Issue",
32
+ parameters: { entityType: "IS", pageName: "ADD" },
33
+ expectedOutput: "{ fields: [{ name: 'TCR_STR', label: 'String Field', fieldTypeName: 'STRING', fieldID: null }, ...], listOptions: {} }"
34
+ }
35
+ ],
36
+ hints: [
37
+ "CALL THIS TOOL FIRST: Before creating or updating TC/TS/IS entities, always call this tool with pageName='ADD' to discover mandatory fields, defaults, field names, types, and valid option IDs.",
38
+ "pageName='ADD': Use before CREATE operations — returns field names + types + list options. fieldID is null (not needed on create).",
39
+ "pageName='DETAIL': Use before UPDATE operations — returns fieldID (projectUserFieldID) required in the UDF wrapper.",
40
+ "WORKFLOW FOR CREATE with UDFs:",
41
+ " 1. Call Fetch UDF Layout with entityType + pageName='ADD'",
42
+ " 2. For LOOKUPLIST/MULTILOOKUPLIST: pick IDs from listOptions[field.listName]",
43
+ " 3. For CASCADINGLIST: pick parent ID from listOptions[field.listName], then call Fetch Cascade Child Values to get child IDs",
44
+ " 4. Pass UDF values via 'udfFields' param on the create tool: { fieldName: value }",
45
+ " 5. Example: { udfFields: { custom_text: 'value', lookup_field: 101, multi_field: [101, 102], cascade_field: { parent: 201, child: 202 } } }",
46
+ "WORKFLOW FOR UPDATE with UDFs:",
47
+ " 1. Call Fetch UDF Layout with entityType + pageName='DETAIL' to get fieldIDs",
48
+ " 2. For LOOKUPLIST/MULTILOOKUPLIST: pick IDs from listOptions[field.listName]",
49
+ " 3. For CASCADINGLIST: pick parent ID, then call Fetch Cascade Child Values for child IDs",
50
+ " 4. Pass both 'udfFields' (flat root keys) AND 'UDF' wrapper (with fieldID) on the update tool:",
51
+ " udfFields: { custom_text: 'new value', lookup_field: 102 }",
52
+ " UDF: { custom_text: { fieldID: 1001, value: 'new value' }, lookup_field: { fieldID: 1002, value: 102 } }",
53
+ " 5. For LOOKUPLIST/MULTILOOKUPLIST in update: also set flat alias key — e.g. lookup_fieldAlias: 'Option B'",
54
+ "stepFields (TC only): Step-level UDF definitions are separate from entity-level UDF fields. They appear in stepFields (not fields). Use them when setting UDF values on test case steps.",
55
+ "listOptions: A map of listName → [{id, name, isArchived}]. Use 'id' as the UDF value for LOOKUPLIST/MULTILOOKUPLIST. Only include non-archived options unless user explicitly wants archived items.",
56
+ "EMPTY listOptions: If listOptions[field.listName] is missing or empty for a lookup field, the newlayout endpoint did not return those options. This tool automatically attempts a fallback to the UDF metadata endpoint to populate them. If listOptions is STILL empty after this tool returns, call 'Fetch Test Run UDF Metadata' with the same entityType — its 'lookupOptions' map uses the same listName keys and contains the full option list.",
57
+ "isMandatory: If true, this field MUST be included. Source: allowBlank=false in QMetry API (for UDF/system fields) or mandatory=true (for step system fields).",
58
+ "DATETIMEPICKER fields: date value MUST match the project's active date format.",
59
+ " Get format: project info → dateTimeFormatID → find in dateTimeFormatNew where id matches → read unique_value.",
60
+ " unique_value pattern: yyyy=4-digit year, MM=2-digit month (01-12), dd=2-digit day, MMM=3-letter month (Jan/Feb/...).",
61
+ " Re-format user date to match before sending. NEVER guess the format — always check project info first.",
62
+ "defaultValues: Pre-configured defaults from QMetry. If a mandatory field has a defaultValues entry, use that value automatically without asking the user. Only ask user for mandatory fields with NO default.",
63
+ "stepDefaultValues: Same as defaultValues but for test case step fields.",
64
+ "PRE-CREATE MANDATORY CHECK WORKFLOW (CRITICAL — do this before every create):",
65
+ " 1. Call Fetch UDF Layout with pageName='ADD' for the entity type",
66
+ " 2. Check systemFields: for each field where isMandatory=true, check if defaultValues[field.name] exists",
67
+ " - Has default → use defaultValues[field.name] as the value, no need to ask user",
68
+ " - No default → MUST ask user to provide value before creating",
69
+ " 3. Check fields (UDF): same logic — isMandatory=true + no defaultValues entry → ask user",
70
+ " 4. For TC steps: check stepSystemFields and stepFields isMandatory, use stepDefaultValues for auto-fill",
71
+ " 5. Only after all mandatory fields are resolved (via default or user input) → proceed with create",
72
+ "This tool is scoped per project — list options, fieldIDs, and defaults are all project-specific."
73
+ ],
74
+ outputDescription: "JSON with 'entityType', 'pageName'. All data is scoped by entityType key in the QMetry newlayout response: TC uses qmUDF.TC / qmSDF.TC / qmDefaultValue.TC; TS uses qmUDF.TS / qmSDF.TS / qmDefaultValue.TS; IS uses qmUDF.IS / qmSDF.IS / qmDefaultValue.IS. 'fields' array — UDF fields (name, label, fieldTypeName, fieldID, isMandatory, optional listName); isMandatory=true when allowBlank=false in QMetry. 'systemFields' array — system fields like Summary/Priority/Status (name, label, fieldTypeName, isMandatory); isMandatory=true when allowBlank=false. 'defaultValues' object — { fieldName: defaultValueId } pre-configured defaults (auto-fill when user omits the field; no need to ask user). TC-only: 'stepFields' — step UDF fields; 'stepSystemFields' — step system fields (mandatory via tcSteps[].mandatory=true); 'stepDefaultValues' — { fieldName: defaultValueId } from qmTCSDefaultValue.TCS. 'listOptions' map (listName → [{id, name, isArchived}]). '_note' with workflow instructions.",
75
+ readOnly: true,
76
+ destructive: false,
77
+ idempotent: true
78
+ },
4
79
  {
5
80
  title: "Bulk Update Test Run UDFs",
6
81
  toolset: "UDF",
@@ -195,10 +270,11 @@ const UDF_TOOLS = [
195
270
  hints: [
196
271
  "ALWAYS call this tool before 'Bulk Update Test Run UDFs' when the user has not explicitly provided a numeric fieldID. The 'fieldID' in the bulk update corresponds to 'projectUserFieldID' in this response.",
197
272
  "This tool is the authoritative source of fieldIDs for all Test Run UDF fields — do NOT guess or hard-code fieldIDs.",
198
- "For LOOKUPLIST and MULTILOOKUPLIST fields, the response 'lookupOptions' contains the valid item IDs and labels to use as values in bulk updates.",
199
- "DATE fields use MM-DD-YYYY format (e.g. '06-23-2026') when setting values via Bulk Update Test Run UDFs."
273
+ "For LOOKUPLIST and MULTILOOKUPLIST fields, the response 'lookupOptions' contains items with 'id', 'name' (display label), and 'uniqueLabel' (internal key stored in executions). When execution UDF values are returned by Fetch Issue Executions or Fetch Test Run UDF Values, LOOKUPLIST/MULTILOOKUPLIST values are already resolved from uniqueLabel → name. For bulk updates, use the item 'id' as the value.",
274
+ "DATE fields use MM-DD-YYYY format (e.g. '06-23-2026') when setting values via Bulk Update Test Run UDFs.",
275
+ "EMPTY lookupOptions: If 'lookupOptions' is empty or missing a list key for a LOOKUPLIST/MULTILOOKUPLIST field, the API did not return options for that field. In this case the user must provide the option name manually or check the QMetry UI for available option IDs. Do NOT proceed with a guess — ask the user for the option ID or name."
200
276
  ],
201
- outputDescription: "JSON object with 'fields' array (each item has fieldID, name, label, fieldType, allowBlank, and optional listName/listMasterID) and 'lookupOptions' map for list-based fields.",
277
+ outputDescription: "JSON object with 'fields' array (each item has fieldID, name, label, fieldType, allowBlank, and optional listName/listMasterID) and 'lookupOptions' map for list-based fields. If lookupOptions is empty for a list field, options could not be fetched automatically.",
202
278
  readOnly: true,
203
279
  destructive: false,
204
280
  idempotent: true
@@ -237,6 +313,8 @@ const UDF_TOOLS = [
237
313
  "'viewId' is auto-resolved from latestViews.TE.viewId — leave blank unless explicitly overriding. It is only needed when sourceRows is not supplied.",
238
314
  "If 'hasTcRunUdf' is false in the response, no Test Run UDFs are configured for this project.",
239
315
  "The 'testRunUdfs' array on each run contains enriched UDF values with label and fieldID — use fieldID from here when calling 'Bulk Update Test Run UDFs'.",
316
+ "VALUE RESOLUTION: For LOOKUPLIST and MULTILOOKUPLIST fields, 'value' is resolved from the internal uniqueLabel key to the human-readable display name using qmUDFList lookup options. Always display the resolved name, never the raw uniqueLabel.",
317
+ "LOOKUP RESOLUTION WARNING: If the response contains '_lookupWarning', lookup options were missing for some fields. Individual UDF entries may have '_rawValue: true' and '_note' indicating the value is an unresolved internal ID. In that case, call 'Fetch Test Run UDF Metadata' separately and use its 'lookupOptions' to resolve the display name before showing the user.",
240
318
  "This tool calls UDF metadata internally — no need to call 'Fetch Test Run UDF Metadata' separately when viewing values.",
241
319
  "When sourceRows is omitted, this tool also calls the test-suite-run execution list API internally. When sourceRows is provided, it reuses those rows and does not refetch the parent execution list."
242
320
  ],
@@ -277,7 +355,7 @@ const UDF_TOOLS = [
277
355
  ],
278
356
  hints: [
279
357
  "MANDATORY WORKFLOW for CASCADINGLIST bulk update:\n 1. Call 'Fetch Test Run UDF Metadata' → get the CASCADINGLIST field's 'fieldID' (projectUserFieldID) and parent item options from 'lookupOptions'.\n 2. Call this tool ('Fetch Cascade Child Values') with a parent item 'id' from step 1 → get child item IDs.\n 3. Call 'Bulk Update Test Run UDFs' with value: { parent: <parentId>, child: <childId> } and the 'fieldID' from step 1.",
280
- "The parent item IDs are in the 'lookupOptions' map returned by 'Fetch Test Run UDF Metadata'. Each entry under the field's listName contains items with 'id' — use that 'id' as the 'id' parameter here.",
358
+ "The parent item IDs are in the 'lookupOptions' map returned by 'Fetch Test Run UDF Metadata'. Each entry under the field's listName contains items with 'id' — use that 'id' as the 'id' parameter here. IMPORTANT: If 'lookupOptions' from Fetch Test Run UDF Metadata is empty for the CASCADINGLIST field, the API did not return parent options. In this case, ask the user to provide the parent item ID from the QMetry UI — do NOT guess.",
281
359
  "The response 'children' array contains objects with 'id', 'name', 'uniqueLabel', and 'isArchived'. Use 'id' as the 'child' value in the bulk update payload.",
282
360
  "Set 'isArchReq: true' only if the user explicitly asks to include archived/inactive child options.",
283
361
  "This endpoint requires 'scope' and 'orgcode' headers — these are injected automatically from the session context when 'Set Project Info' has been called. If you see an authorization error, call 'Set Project Info' first.",
@@ -88,7 +88,7 @@ function parseRawUdfs(row) {
88
88
  }
89
89
  return {};
90
90
  }
91
- function enrichUdfsForRow(row, fieldDefs) {
91
+ function enrichUdfsForRow(row, fieldDefs, lookupOptions = {}) {
92
92
  const rawUdfs = parseRawUdfs(row);
93
93
  const hasMetadata = Object.keys(fieldDefs).length > 0;
94
94
  if (!hasMetadata && Array.isArray(row.testRunUdfs)) return row.testRunUdfs;
@@ -96,13 +96,43 @@ function enrichUdfsForRow(row, fieldDefs) {
96
96
  return Object.values(fieldDefs).map((def) => {
97
97
  const fieldName = def.name ?? "";
98
98
  const rawValue = Object.hasOwn(rawUdfs, fieldName) ? rawUdfs[fieldName] : null;
99
- const value = typeof rawValue === "string" ? stripHtml(rawValue) : rawValue;
99
+ let value = typeof rawValue === "string" ? stripHtml(rawValue) : rawValue;
100
+ const options = def.qmListName ? lookupOptions[def.qmListName] ?? [] : [];
101
+ let valueResolved = false;
102
+ if (options.length > 0) {
103
+ if (typeof value === "string") {
104
+ const match = options.find((o) => o.uniqueLabel === value);
105
+ if (match) {
106
+ value = match.name;
107
+ valueResolved = true;
108
+ }
109
+ } else if (Array.isArray(value)) {
110
+ let allResolved = true;
111
+ value = value.map((v) => {
112
+ const match = options.find((o) => o.uniqueLabel === v);
113
+ if (!match) allResolved = false;
114
+ return match ? match.name : v;
115
+ });
116
+ valueResolved = allResolved;
117
+ } else {
118
+ valueResolved = true;
119
+ }
120
+ }
121
+ const isLookupField = [
122
+ "LOOKUPLIST",
123
+ "MULTILOOKUPLIST",
124
+ "CASCADINGLIST"
125
+ ].includes(def.fieldTypeName ?? "");
100
126
  return {
101
127
  name: fieldName,
102
128
  label: def.fieldLabel ?? fieldName,
103
129
  fieldID: def.projectUserFieldID ?? null,
104
130
  fieldType: def.fieldTypeName ?? "UNKNOWN",
105
- value
131
+ value,
132
+ ...isLookupField && !valueResolved && value !== null ? {
133
+ _rawValue: true,
134
+ _note: "Lookup options unavailable — value is raw internal ID. Call Fetch Test Run UDF Metadata to resolve."
135
+ } : {}
106
136
  };
107
137
  });
108
138
  }
@@ -225,6 +255,121 @@ async function fetchUdfFieldTypes() {
225
255
  async function fetchUdfModules() {
226
256
  return [...UDF_MODULES];
227
257
  }
258
+ async function fetchUdfLayout(token, baseUrl, project, payload) {
259
+ const { resolvedBaseUrl, resolvedProject } = resolveDefaults(
260
+ baseUrl,
261
+ project
262
+ );
263
+ if (!payload.entityType || !["TC", "TS", "IS"].includes(payload.entityType)) {
264
+ throw new Error(
265
+ "[fetchUdfLayout] Missing or invalid required parameter: 'entityType'. Must be 'TC', 'TS', or 'IS'."
266
+ );
267
+ }
268
+ const pageName = payload.pageName ?? "ADD";
269
+ const ENTITY_SCREEN = {
270
+ TC: "TESTCASE",
271
+ IS: "ISSUE"
272
+ // TS: no screenname header sent by browser
273
+ };
274
+ const extraHeaders = { action: "udf-view" };
275
+ if (ENTITY_SCREEN[payload.entityType]) {
276
+ extraHeaders.screenname = ENTITY_SCREEN[payload.entityType];
277
+ }
278
+ const raw = await qmetryRequest({
279
+ method: "POST",
280
+ path: QMETRY_PATHS.UDF.GET_LAYOUT,
281
+ token,
282
+ project: resolvedProject,
283
+ baseUrl: resolvedBaseUrl,
284
+ body: { entityType: payload.entityType, pageName },
285
+ scopeId: payload.scopeId,
286
+ orgCode: payload.orgCode,
287
+ extraHeaders
288
+ });
289
+ const entityUdfMap = raw.qmUDF?.[payload.entityType] ?? {};
290
+ const fields = Object.values(entityUdfMap).map((def) => ({
291
+ name: def.name,
292
+ label: def.label ?? def.fieldLabel ?? def.name,
293
+ fieldTypeName: def.fieldTypeName,
294
+ fieldID: def.projectUserFieldID ?? def.fieldID ?? null,
295
+ isMandatory: def.allowBlank === false,
296
+ ...def.qmListName ? { listName: def.qmListName } : {}
297
+ }));
298
+ const stepUdfMap = raw.qmTCSUDF?.TCS ?? {};
299
+ const stepFields = Object.values(stepUdfMap).map((def) => ({
300
+ name: def.name,
301
+ label: def.label ?? def.fieldLabel ?? def.name,
302
+ fieldTypeName: def.fieldTypeName,
303
+ fieldID: def.projectUserFieldID ?? def.fieldID ?? null,
304
+ isMandatory: def.allowBlank === false,
305
+ ...def.qmListName ? { listName: def.qmListName } : {}
306
+ }));
307
+ const sdfMap = raw.qmSDF?.[payload.entityType] ?? {};
308
+ const systemFields = Object.values(sdfMap).map((def) => ({
309
+ name: def.name,
310
+ label: def.fieldLabel ?? def.name,
311
+ fieldTypeName: def.fieldTypeName,
312
+ isMandatory: def.allowBlank === false
313
+ }));
314
+ const defaultValues = raw.qmDefaultValue?.[payload.entityType] ?? {};
315
+ const stepSystemFields = payload.entityType === "TC" ? (raw.tcSteps ?? []).map((f) => ({
316
+ name: f.name,
317
+ label: f.label,
318
+ fieldTypeName: f.fieldType,
319
+ isMandatory: f.mandatory === true
320
+ })) : [];
321
+ const stepDefaultValues = payload.entityType === "TC" ? raw.qmTCSDefaultValue?.TCS ?? {} : {};
322
+ let listOptions = raw.gis?.customList ?? {};
323
+ const lookupTypes = /* @__PURE__ */ new Set([
324
+ "LOOKUPLIST",
325
+ "MULTILOOKUPLIST",
326
+ "CASCADINGLIST"
327
+ ]);
328
+ const allLookupFields = [...fields, ...stepFields].filter(
329
+ (f) => lookupTypes.has(f.fieldTypeName) && f.listName
330
+ );
331
+ const missingOptions = allLookupFields.some(
332
+ (f) => !listOptions[f.listName] || listOptions[f.listName].length === 0
333
+ );
334
+ if (missingOptions) {
335
+ const metaRaw = await qmetryRequest({
336
+ method: "POST",
337
+ path: QMETRY_PATHS.UDF.TEST_RUN_UDF_METADATA,
338
+ token,
339
+ project: resolvedProject,
340
+ baseUrl: resolvedBaseUrl,
341
+ body: { entityType: payload.entityType },
342
+ scopeId: payload.scopeId,
343
+ orgCode: payload.orgCode
344
+ });
345
+ const metaList = metaRaw.qmUDFList ?? {};
346
+ listOptions = { ...metaList, ...listOptions };
347
+ for (const key of Object.keys(metaList)) {
348
+ if (!listOptions[key] || listOptions[key].length === 0) {
349
+ listOptions[key] = metaList[key];
350
+ }
351
+ }
352
+ }
353
+ const updateNote = pageName === "ADD" ? "Use 'fieldID: null' fields for create — no fieldID needed on create. For LOOKUPLIST/MULTILOOKUPLIST/CASCADINGLIST: use IDs from 'listOptions[listName]' as values. Pass values flat via udfFields param on the create tool." : "Use 'fieldID' from each field when building the 'UDF' wrapper for update: { fieldName: { fieldID: <fieldID>, value: <value> } }. Also pass the same values flat via udfFields param. For LOOKUPLIST/MULTILOOKUPLIST/CASCADINGLIST: use IDs from 'listOptions[listName]'.";
354
+ const diagnostics = {};
355
+ if (systemFields.length === 0) {
356
+ diagnostics._systemFields_note = "QMetry API returned no system field definitions (qmSDF missing or empty). Treat 'name' (Summary) and 'testCaseState' (Status) as always mandatory. Use customListObjs.testCaseState from project info for Status options.";
357
+ }
358
+ if (Object.keys(defaultValues).length === 0) {
359
+ diagnostics._defaultValues_note = "QMetry API returned no default values (qmDefaultValue missing or empty). Cannot auto-apply defaults — ask user for mandatory fields that have no value.";
360
+ }
361
+ return {
362
+ entityType: payload.entityType,
363
+ pageName,
364
+ fields,
365
+ systemFields,
366
+ defaultValues,
367
+ ...payload.entityType === "TC" ? { stepFields, stepSystemFields, stepDefaultValues } : {},
368
+ listOptions,
369
+ ...diagnostics,
370
+ _note: updateNote
371
+ };
372
+ }
228
373
  async function fetchTestRunUdfMetadata(token, baseUrl, project, payload) {
229
374
  const { resolvedBaseUrl, resolvedProject } = resolveDefaults(
230
375
  baseUrl,
@@ -330,10 +475,16 @@ async function fetchTestRunUdfValues(token, baseUrl, project, payload) {
330
475
  lookupOptions = meta.qmUDFList ?? {};
331
476
  } catch {
332
477
  }
478
+ const lookupFieldsMissingOptions = Object.values(fieldDefs).filter(
479
+ (def) => ["LOOKUPLIST", "MULTILOOKUPLIST", "CASCADINGLIST"].includes(
480
+ def.fieldTypeName
481
+ ) && def.qmListName && (!lookupOptions[def.qmListName] || lookupOptions[def.qmListName].length === 0)
482
+ );
483
+ const hasLookupWarning = lookupFieldsMissingOptions.length > 0;
333
484
  const rows = runsResponse.data ?? [];
334
485
  const runs = rows.map((row) => {
335
486
  const { udfjson: _udfjson, ...rowWithoutRawUdfJson } = row;
336
- const enrichedUdfs = enrichUdfsForRow(row, fieldDefs);
487
+ const enrichedUdfs = enrichUdfsForRow(row, fieldDefs, lookupOptions);
337
488
  return {
338
489
  ...rowWithoutRawUdfJson,
339
490
  testRunUdfs: enrichedUdfs
@@ -348,6 +499,9 @@ async function fetchTestRunUdfValues(token, baseUrl, project, payload) {
348
499
  sourceContext,
349
500
  hasTcRunUdf: runsResponse.hasTcRunUdf ?? true,
350
501
  total: runsResponse.total ?? rows.length,
502
+ ...hasLookupWarning ? {
503
+ _lookupWarning: `Lookup options missing for fields: ${lookupFieldsMissingOptions.map((d) => d.name).join(", ")}. Values for these fields may show raw internal IDs instead of display names. Call 'Fetch Test Run UDF Metadata' separately and use its 'lookupOptions' to resolve display names.`
504
+ } : {},
351
505
  defaultColumns: TEST_RUN_UDF_DISPLAY_COLUMNS[sourceContext].map(
352
506
  (column) => column.header
353
507
  ),
@@ -372,5 +526,6 @@ export {
372
526
  fetchTestRunUdfMetadata,
373
527
  fetchTestRunUdfValues,
374
528
  fetchUdfFieldTypes,
529
+ fetchUdfLayout,
375
530
  fetchUdfModules
376
531
  };
@@ -1,9 +1,11 @@
1
1
  import zod__default from "zod";
2
2
  import { getRequestHeader } from "../common/request-context.js";
3
3
  import { extractProjectContext, findAutoResolveConfig, autoResolveViewIdAndFolderPath } from "./client/auto-resolve.js";
4
+ import { resolveProjectDateFormat, extractDatetimePickerFieldNames, normalizeDateFieldsInArgs } from "./client/date-utils.js";
4
5
  import { QMETRY_HANDLER_MAP } from "./client/handlers.js";
5
6
  import { getProjectInfo } from "./client/project.js";
6
7
  import { TOOLS } from "./client/tools/index.js";
8
+ import { fetchUdfLayout } from "./client/udf.js";
7
9
  import { QMETRY_DEFAULTS, QMetryToolsHandlers } from "./config/constants.js";
8
10
  const ConfigurationSchema = zod__default.object({
9
11
  api_key: zod__default.string().optional().describe(
@@ -128,13 +130,246 @@ class QmetryClient {
128
130
  this.persistProjectContext(projectInfo);
129
131
  }
130
132
  }
133
+ if (tool.handler === QMetryToolsHandlers.CREATE_TEST_CASE) {
134
+ try {
135
+ const projectInfoForDate = await getProjectInfo(
136
+ this.getToken(),
137
+ baseUrl,
138
+ projectKey
139
+ );
140
+ const { scopeId: freshScopeId, orgCode: freshOrgCode } = extractProjectContext(projectInfoForDate);
141
+ const layout = await fetchUdfLayout(
142
+ this.getToken(),
143
+ baseUrl,
144
+ projectKey,
145
+ {
146
+ entityType: "TC",
147
+ pageName: "ADD",
148
+ ...freshScopeId !== void 0 ? { scopeId: freshScopeId } : {},
149
+ ...freshOrgCode !== void 0 ? { orgCode: freshOrgCode } : {}
150
+ }
151
+ );
152
+ const defaults = layout.defaultValues ?? {};
153
+ if (!a.udfFields) a.udfFields = {};
154
+ const systemFieldMap = new Map(
155
+ (layout.systemFields ?? []).map((f) => [
156
+ f.name,
157
+ f.fieldTypeName
158
+ ])
159
+ );
160
+ for (const [fieldName, defVal] of Object.entries(defaults)) {
161
+ const isSystemField = systemFieldMap.has(fieldName);
162
+ if (isSystemField) {
163
+ if (!(fieldName in a)) {
164
+ const fieldType = systemFieldMap.get(fieldName);
165
+ a[fieldName] = fieldType === "MULTILOOKUPLIST" && !Array.isArray(defVal) ? [defVal] : defVal;
166
+ }
167
+ } else {
168
+ if (!(fieldName in a.udfFields) && !(fieldName in a)) {
169
+ a.udfFields[fieldName] = defVal;
170
+ }
171
+ }
172
+ }
173
+ const targetDateFormat = resolveProjectDateFormat(projectInfoForDate);
174
+ const datetimePickers = extractDatetimePickerFieldNames(layout);
175
+ normalizeDateFieldsInArgs(a, datetimePickers, targetDateFormat);
176
+ if (!a.testCaseState) {
177
+ const stateOptions = layout.listOptions?.testCaseState ?? [];
178
+ const firstActive = stateOptions.find(
179
+ (s) => !s.isArchived
180
+ );
181
+ if (firstActive) a.testCaseState = firstActive.id;
182
+ }
183
+ const missingMandatory = [];
184
+ for (const field of layout.fields ?? []) {
185
+ if (field.isMandatory) {
186
+ const inUdfFields = field.name in a.udfFields;
187
+ const inArgs = field.name in a;
188
+ const hasDefault = field.name in defaults;
189
+ if (!inUdfFields && !inArgs && !hasDefault) {
190
+ missingMandatory.push({
191
+ name: field.name,
192
+ label: field.label,
193
+ fieldType: field.fieldTypeName
194
+ });
195
+ }
196
+ }
197
+ }
198
+ if (missingMandatory.length > 0) {
199
+ return {
200
+ content: [
201
+ {
202
+ success: false,
203
+ type: "text",
204
+ text: JSON.stringify(
205
+ {
206
+ success: false,
207
+ code: "PREFLIGHT.MANDATORY_UDF_MISSING",
208
+ message: `Cannot create test case. The following mandatory UDF fields have no value and no configured default: ${missingMandatory.map((f) => `${f.label} (${f.fieldType})`).join(", ")}. Ask the user to provide values for these fields, then retry.`,
209
+ missingFields: missingMandatory
210
+ },
211
+ null,
212
+ 2
213
+ )
214
+ }
215
+ ]
216
+ };
217
+ }
218
+ } catch {
219
+ }
220
+ }
221
+ if (tool.handler === QMetryToolsHandlers.CREATE_TEST_SUITE) {
222
+ try {
223
+ const projectInfoForDate = await getProjectInfo(
224
+ this.getToken(),
225
+ baseUrl,
226
+ projectKey
227
+ );
228
+ const { scopeId: freshScopeId, orgCode: freshOrgCode } = extractProjectContext(projectInfoForDate);
229
+ const layout = await fetchUdfLayout(
230
+ this.getToken(),
231
+ baseUrl,
232
+ projectKey,
233
+ {
234
+ entityType: "TS",
235
+ pageName: "ADD",
236
+ ...freshScopeId !== void 0 ? { scopeId: freshScopeId } : {},
237
+ ...freshOrgCode !== void 0 ? { orgCode: freshOrgCode } : {}
238
+ }
239
+ );
240
+ const defaults = layout.defaultValues ?? {};
241
+ if (!a.udfFields) a.udfFields = {};
242
+ const systemFieldMapTS = new Map(
243
+ (layout.systemFields ?? []).map((f) => [
244
+ f.name,
245
+ f.fieldTypeName
246
+ ])
247
+ );
248
+ for (const [fieldName, defVal] of Object.entries(defaults)) {
249
+ const isSystemField = systemFieldMapTS.has(fieldName);
250
+ if (isSystemField) {
251
+ if (!(fieldName in a)) {
252
+ const fieldType = systemFieldMapTS.get(fieldName);
253
+ a[fieldName] = fieldType === "MULTILOOKUPLIST" && !Array.isArray(defVal) ? [defVal] : defVal;
254
+ }
255
+ } else {
256
+ if (!(fieldName in a.udfFields) && !(fieldName in a)) {
257
+ a.udfFields[fieldName] = defVal;
258
+ }
259
+ }
260
+ }
261
+ const targetDateFormat = resolveProjectDateFormat(projectInfoForDate);
262
+ const datetimePickers = extractDatetimePickerFieldNames(layout);
263
+ normalizeDateFieldsInArgs(a, datetimePickers, targetDateFormat);
264
+ if (!a.testSuiteState) {
265
+ const stateOptions = layout.listOptions?.testSuiteState ?? [];
266
+ const firstActive = stateOptions.find(
267
+ (s) => !s.isArchived
268
+ );
269
+ if (firstActive) a.testSuiteState = firstActive.id;
270
+ }
271
+ const missingMandatory = [];
272
+ for (const field of layout.fields ?? []) {
273
+ if (field.isMandatory) {
274
+ const inUdfFields = field.name in a.udfFields;
275
+ const inArgs = field.name in a;
276
+ const hasDefault = field.name in defaults;
277
+ if (!inUdfFields && !inArgs && !hasDefault) {
278
+ missingMandatory.push({
279
+ name: field.name,
280
+ label: field.label,
281
+ fieldType: field.fieldTypeName
282
+ });
283
+ }
284
+ }
285
+ }
286
+ const TS_SYSTEM_FIELD_TO_ARG = {
287
+ name: "name",
288
+ associatedReleasesCycles: "releaseCycleMapping",
289
+ testsuiteOwner: "testsuiteOwner",
290
+ testSuiteState: "testSuiteState",
291
+ description: "description"
292
+ };
293
+ for (const sysField of layout.systemFields ?? []) {
294
+ if (!sysField.isMandatory) continue;
295
+ if (sysField.name === "name") continue;
296
+ if (sysField.name === "testSuiteState" && a.testSuiteState)
297
+ continue;
298
+ const argKey = TS_SYSTEM_FIELD_TO_ARG[sysField.name] ?? sysField.name;
299
+ const val = a[argKey];
300
+ const hasVal = Array.isArray(val) ? val.length > 0 : val != null && val !== "";
301
+ if (!hasVal) {
302
+ missingMandatory.push({
303
+ name: sysField.name,
304
+ label: sysField.label,
305
+ fieldType: sysField.fieldTypeName
306
+ });
307
+ }
308
+ }
309
+ if (missingMandatory.length > 0) {
310
+ return {
311
+ content: [
312
+ {
313
+ success: false,
314
+ type: "text",
315
+ text: JSON.stringify(
316
+ {
317
+ success: false,
318
+ code: "PREFLIGHT.MANDATORY_FIELDS_MISSING",
319
+ message: `Cannot create test suite. The following mandatory fields have no value and no configured default: ${missingMandatory.map((f) => `${f.label} (${f.fieldType})`).join(", ")}. Ask the user to provide values for these fields, then retry.`,
320
+ missingFields: missingMandatory
321
+ },
322
+ null,
323
+ 2
324
+ )
325
+ }
326
+ ]
327
+ };
328
+ }
329
+ } catch {
330
+ }
331
+ }
332
+ const UDF_DATE_PREFLIGHT_ENTITY_MAP = {
333
+ [QMetryToolsHandlers.UPDATE_TEST_CASE]: "TC",
334
+ [QMetryToolsHandlers.UPDATE_TEST_SUITE]: "TS",
335
+ [QMetryToolsHandlers.CREATE_ISSUE]: "IS",
336
+ [QMetryToolsHandlers.UPDATE_ISSUE]: "IS"
337
+ };
338
+ const entityTypeForDate = UDF_DATE_PREFLIGHT_ENTITY_MAP[tool.handler];
339
+ if (entityTypeForDate) {
340
+ try {
341
+ const dateProjectInfo = await getProjectInfo(
342
+ this.getToken(),
343
+ baseUrl,
344
+ projectKey
345
+ );
346
+ const { scopeId: freshScopeId, orgCode: freshOrgCode } = extractProjectContext(dateProjectInfo);
347
+ const dateLayout = await fetchUdfLayout(
348
+ this.getToken(),
349
+ baseUrl,
350
+ projectKey,
351
+ {
352
+ entityType: entityTypeForDate,
353
+ pageName: "ADD",
354
+ ...freshScopeId !== void 0 ? { scopeId: freshScopeId } : {},
355
+ ...freshOrgCode !== void 0 ? { orgCode: freshOrgCode } : {}
356
+ }
357
+ );
358
+ const targetDateFormat = resolveProjectDateFormat(dateProjectInfo);
359
+ const datetimePickers = extractDatetimePickerFieldNames(dateLayout);
360
+ normalizeDateFieldsInArgs(a, datetimePickers, targetDateFormat);
361
+ } catch {
362
+ }
363
+ }
131
364
  const { projectKey: _, baseUrl: __, ...cleanArgs } = a;
132
365
  const SCOPE_AWARE_HANDLERS = /* @__PURE__ */ new Set([
133
366
  QMetryToolsHandlers.FETCH_TESTCASE_RUNS_BY_TESTSUITE_RUN,
134
367
  QMetryToolsHandlers.BULK_UPDATE_TEST_RUN_UDFS,
135
368
  QMetryToolsHandlers.FETCH_TEST_RUN_UDF_METADATA,
136
369
  QMetryToolsHandlers.FETCH_TEST_RUN_UDF_VALUES,
137
- QMetryToolsHandlers.FETCH_CASCADE_CHILD_VALUES
370
+ QMetryToolsHandlers.FETCH_CASCADE_CHILD_VALUES,
371
+ QMetryToolsHandlers.FETCH_ISSUE_DETAILS,
372
+ QMetryToolsHandlers.FETCH_UDF_LAYOUT
138
373
  ]);
139
374
  const isScopeAware = SCOPE_AWARE_HANDLERS.has(tool.handler);
140
375
  const enrichedArgs = {
@@ -67,6 +67,7 @@ const QMetryToolsHandlers = {
67
67
  FETCH_TEST_CASE_DETAILS: "getTestCaseDetails",
68
68
  FETCH_TEST_CASE_VERSION_DETAILS: "getTestCaseVersionDetails",
69
69
  FETCH_TEST_CASE_STEPS: "getTestCaseSteps",
70
+ FETCH_TEST_CASE_STEPS_WITH_UDF: "getTestCaseStepsWithUdf",
70
71
  FETCH_TEST_CASE_EXECUTIONS: "getTestCaseExecutions",
71
72
  LINK_REQUIREMENT_TO_TESTCASE: "linkRequirementToTestCase",
72
73
  FETCH_REQUIREMENTS: "getRequirements",
@@ -104,7 +105,10 @@ const QMetryToolsHandlers = {
104
105
  FETCH_CASCADE_CHILD_VALUES: "fetchCascadeChildValues",
105
106
  FETCH_GATE_CONFIGURATION: "getGateConfiguration",
106
107
  EXECUTE_GATE_REPORT: "executeGateReport",
107
- EXPORT_HTML_REPORT: "exportHtmlReport"
108
+ EXPORT_HTML_REPORT: "exportHtmlReport",
109
+ FETCH_UDF_LAYOUT: "fetchUdfLayout",
110
+ FETCH_TEST_SUITE_DETAILS: "fetchTestSuiteDetails",
111
+ FETCH_ISSUE_DETAILS: "fetchIssueDetails"
108
112
  };
109
113
  export {
110
114
  QMETRY_DEFAULTS,
@@ -14,6 +14,7 @@ const QMETRY_PATHS = {
14
14
  GET_TC_DETAILS: "/rest/testcases/getVersionDetail",
15
15
  GET_TC_DETAILS_BY_VERSION: "/rest/testcases/list",
16
16
  GET_TC_STEPS: "/rest/testcases/steps/list",
17
+ GET_TC_STEPS_WITH_UDF: "/rest/testcases/tcStep/list/viewColumns",
17
18
  GET_TC_EXECUTIONS: "/rest/testcases/execution",
18
19
  GET_TC_LINKED_TO_RQ: "/rest/testcases/list/forRQ",
19
20
  CREATE_UPDATE_TC: "/rest/testcases",
@@ -34,14 +35,16 @@ const QMETRY_PATHS = {
34
35
  GET_TESTCASE_RUNS_BY_TESTSUITE_RUN: "/rest/execution/list/viewColumns",
35
36
  GET_LINKED_ISSUES_BY_TESTCASE_RUN: "/rest/execution/issue/list/forTCRun",
36
37
  LINK_PLATFORMS_TO_TESTSUITE: "/rest/testsuites/link/platforms",
37
- BULK_UPDATE_EXECUTION_STATUS: "/rest/execution/runstatus/bulkupdate"
38
+ BULK_UPDATE_EXECUTION_STATUS: "/rest/execution/runstatus/bulkupdate",
39
+ GET_TS_DETAIL: "/rest/testsuites/latest/detail/data"
38
40
  },
39
41
  ISSUES: {
40
42
  GET_ISSUES_LIST: "/rest/issues/list/viewColumns",
41
43
  CREATE_UPDATE_ISSUE: "/rest/issues",
42
44
  GET_ISSUES_LINKED_TO_TC: "/rest/issues/list/ForTC",
43
45
  LINK_ISSUES_TO_TESTCASE_RUN: "/rest/execution/link/issue",
44
- GET_ISSUE_EXECUTIONS: "/rest/execution/getExecutionsForIssue"
46
+ GET_ISSUE_EXECUTIONS: "/rest/execution/getExecutionsForIssue",
47
+ GET_ISSUE_DETAIL: "/rest/issues/"
45
48
  },
46
49
  AUTOMATION: {
47
50
  IMPORT_RESULTS: "/rest/import/createandscheduletestresults/1",
@@ -50,7 +53,8 @@ const QMETRY_PATHS = {
50
53
  UDF: {
51
54
  BULK_UPDATE_TEST_RUN_UDFS: "/rest/execution/udf/bulkupdate",
52
55
  TEST_RUN_UDF_METADATA: "/rest/admin/udf/metadata",
53
- FETCH_CASCADE_CHILD_VALUES: "/rest/admin/udf/cascade/childValue"
56
+ FETCH_CASCADE_CHILD_VALUES: "/rest/admin/udf/cascade/childValue",
57
+ GET_LAYOUT: "/rest/admin/newlayout"
54
58
  },
55
59
  AI_AGENT: {
56
60
  GET_GATE_CONFIG: "/rest/aiagent/project/:projectId/gate-config",