@smartbear/mcp 0.32.0 → 0.34.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,20 +1,64 @@
1
- function deepMerge(baseObject, objectWithUpdates) {
2
- const result = { ...baseObject };
3
- for (const key in objectWithUpdates) {
4
- if (objectWithUpdates[key] === void 0) {
5
- continue;
6
- }
7
- if (objectsCanBeMerged(baseObject, objectWithUpdates, key)) {
8
- result[key] = deepMerge(baseObject[key], objectWithUpdates[key]);
9
- } else {
10
- result[key] = objectWithUpdates[key];
1
+ import { z } from "zod";
2
+ function deepMerge(baseObject, objectWithUpdates, targetSchema) {
3
+ const merged = mergeValues(baseObject, objectWithUpdates);
4
+ return deepStrip(targetSchema).parse(merged);
5
+ }
6
+ function mergeValues(base, updated) {
7
+ if (updated === void 0) {
8
+ return base;
9
+ }
10
+ if (isPlainObject(base) && isPlainObject(updated)) {
11
+ const result = { ...base };
12
+ for (const key of Object.keys(updated)) {
13
+ if (updated[key] === void 0) {
14
+ continue;
15
+ }
16
+ result[key] = mergeValues(base[key], updated[key]);
11
17
  }
18
+ return result;
19
+ }
20
+ return updated;
21
+ }
22
+ function isPlainObject(value) {
23
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
24
+ return false;
12
25
  }
13
- return result;
26
+ const proto = Object.getPrototypeOf(value);
27
+ return proto === Object.prototype || proto === null;
28
+ }
29
+ function deepStrip(schema) {
30
+ return stripNode(schema);
14
31
  }
15
- function objectsCanBeMerged(baseObject, objectWithUpdates, key) {
16
- return objectWithUpdates[key] && typeof objectWithUpdates[key] === "object" && !Array.isArray(objectWithUpdates[key]) && baseObject[key] && typeof baseObject[key] === "object" && !Array.isArray(baseObject[key]);
32
+ function stripNode(schema) {
33
+ const def = schema.def;
34
+ switch (def.type) {
35
+ case "object": {
36
+ const shape = def.shape;
37
+ const strippedShape = {};
38
+ for (const key of Object.keys(shape)) {
39
+ strippedShape[key] = stripNode(shape[key]);
40
+ }
41
+ return z.object(strippedShape);
42
+ }
43
+ case "array":
44
+ return z.array(stripNode(def.element));
45
+ case "optional":
46
+ return z.optional(stripNode(def.innerType));
47
+ case "nullable":
48
+ return z.nullable(stripNode(def.innerType));
49
+ case "default":
50
+ return stripNode(def.innerType).default(def.defaultValue);
51
+ case "record":
52
+ return z.record(def.keyType, stripNode(def.valueType));
53
+ case "union":
54
+ return z.union(
55
+ def.options.map((option) => stripNode(option))
56
+ );
57
+ default:
58
+ return schema;
59
+ }
17
60
  }
18
61
  export {
19
- deepMerge
62
+ deepMerge,
63
+ deepStrip
20
64
  };
@@ -1,6 +1,12 @@
1
+ import { z } from "zod";
1
2
  import { Tool } from "../../../common/tools.js";
2
- import { UpdateTestCaseParams, UpdateTestCaseBody } from "../../common/rest-api-schemas.js";
3
+ import { UpdateTestCaseBody, updateTestCaseBodyOwnerAccountIdRegExp, UpdateTestCaseParams } from "../../common/rest-api-schemas.js";
3
4
  import { deepMerge } from "../../common/utils.js";
5
+ const UpdateTestCaseBodyToolInput = UpdateTestCaseBody.extend({
6
+ folder: z.number().min(1).nullish().describe("The ID of the folder to move the test case into."),
7
+ component: z.number().min(1).nullish().describe("The ID of the Jira component to associate."),
8
+ owner: z.string().regex(updateTestCaseBodyOwnerAccountIdRegExp).nullish().describe("Atlassian Account ID of the Jira user to set as owner.")
9
+ }).partial();
4
10
  class UpdateTestCase extends Tool {
5
11
  specification = {
6
12
  title: "Update Test Case",
@@ -8,7 +14,7 @@ class UpdateTestCase extends Tool {
8
14
  summary: 'Update an existing Test Case in Zephyr. This operation fetches the current test case and merges your updates with it to prevent accidental property deletion. Properties which are not included in the tool call will be left unchanged. To remove a property, set it to null explicitly. For fields that accept multiple values, such as `labels`, if the field is provided, it will override the previous values. For example, if `labels` is provided with the values `["label1", "label2"]`, the Test Case will now only have those two labels, and any previous labels will be removed. If you want to add a label, you would need to specify in the prompt the intention to add a label.',
9
15
  readOnly: false,
10
16
  idempotent: true,
11
- inputSchema: UpdateTestCaseParams.and(UpdateTestCaseBody.partial()),
17
+ inputSchema: UpdateTestCaseParams.and(UpdateTestCaseBodyToolInput),
12
18
  examples: [
13
19
  {
14
20
  description: "Update the name of the test case 'SA-T10' to 'Check axial pump' and objective to 'To ensure the axial pump can be enabled'",
@@ -70,34 +76,44 @@ class UpdateTestCase extends Tool {
70
76
  ]
71
77
  };
72
78
  handle = async (args) => {
73
- const parsed = UpdateTestCaseParams.and(UpdateTestCaseBody.partial()).parse(
79
+ const parsed = UpdateTestCaseParams.and(UpdateTestCaseBodyToolInput).parse(
74
80
  args
75
81
  );
76
- const { testCaseKey, ...rawUpdates } = parsed;
77
- const nullValuesObject = {};
78
- if (rawUpdates.folder) {
79
- nullValuesObject.folder = { id: rawUpdates.folder };
80
- }
81
- if (rawUpdates.owner) {
82
- nullValuesObject.owner = { accountId: rawUpdates.owner };
83
- }
84
- if (rawUpdates.component) {
85
- nullValuesObject.component = { id: rawUpdates.component };
86
- }
87
- const updates = {
88
- ...rawUpdates,
89
- ...nullValuesObject
90
- };
82
+ const { testCaseKey, ...updatesFromToolInput } = parsed;
83
+ const updatesForRestApi = this.toRestApiUpdates(updatesFromToolInput);
91
84
  const existingTestCase = await this.client.getApiClient().get(`/testcases/${testCaseKey}`);
92
- const mergedBody = deepMerge(existingTestCase, updates);
93
- delete mergedBody.createdOn;
94
- delete mergedBody.links;
85
+ const mergedBody = deepMerge(
86
+ existingTestCase,
87
+ updatesForRestApi,
88
+ UpdateTestCaseBody.partial()
89
+ );
95
90
  await this.client.getApiClient().put(`/testcases/${testCaseKey}`, mergedBody);
96
91
  return {
97
92
  structuredContent: {},
98
93
  content: []
99
94
  };
100
95
  };
96
+ // Convert the tool input into updates compatible with the REST API by
97
+ // expanding the primitive folder/component/owner IDs back into the `{ id }` /
98
+ // `{ accountId }` objects the REST API's UpdateTestCaseBody shape expects.
99
+ toRestApiUpdates(updatesFromToolInput) {
100
+ const restApiCompatibleFields = {};
101
+ if (updatesFromToolInput.folder) {
102
+ restApiCompatibleFields.folder = { id: updatesFromToolInput.folder };
103
+ }
104
+ if (updatesFromToolInput.owner) {
105
+ restApiCompatibleFields.owner = { accountId: updatesFromToolInput.owner };
106
+ }
107
+ if (updatesFromToolInput.component) {
108
+ restApiCompatibleFields.component = {
109
+ id: updatesFromToolInput.component
110
+ };
111
+ }
112
+ return {
113
+ ...updatesFromToolInput,
114
+ ...restApiCompatibleFields
115
+ };
116
+ }
101
117
  }
102
118
  export {
103
119
  UpdateTestCase
@@ -1,6 +1,12 @@
1
+ import { z } from "zod";
1
2
  import { Tool } from "../../../common/tools.js";
2
- import { UpdateTestCycleParams, UpdateTestCycleBody } from "../../common/rest-api-schemas.js";
3
+ import { UpdateTestCycleBody, updateTestCycleBodyOwnerAccountIdRegExp, UpdateTestCycleParams } from "../../common/rest-api-schemas.js";
3
4
  import { deepMerge } from "../../common/utils.js";
5
+ const UpdateTestCycleBodyToolInput = UpdateTestCycleBody.extend({
6
+ folder: z.number().min(1).nullish().describe("The ID of the folder to move the test cycle into."),
7
+ jiraProjectVersion: z.number().min(1).nullish().describe("The ID of the Jira project version (release) to associate."),
8
+ owner: z.string().regex(updateTestCycleBodyOwnerAccountIdRegExp).nullish().describe("Atlassian Account ID of the Jira user to set as owner.")
9
+ }).partial();
4
10
  class UpdateTestCycle extends Tool {
5
11
  specification = {
6
12
  title: "Update Test Cycle",
@@ -8,7 +14,7 @@ class UpdateTestCycle extends Tool {
8
14
  summary: "Update an existing Test Cycle in Zephyr. This operation fetches the current test cycle and merges your updates with it to prevent accidental property deletion. To remove a property, set it to null explicitly. The plannedStartDate and plannedEndDate fields cannot be cleared",
9
15
  readOnly: false,
10
16
  idempotent: true,
11
- inputSchema: UpdateTestCycleParams.and(UpdateTestCycleBody.partial()),
17
+ inputSchema: UpdateTestCycleParams.and(UpdateTestCycleBodyToolInput),
12
18
  examples: [
13
19
  {
14
20
  description: "Update the name of the test cycle 'SA-R40' to 'Sprint 1 Regression - Updated' and set description.",
@@ -32,7 +38,7 @@ class UpdateTestCycle extends Tool {
32
38
  description: "Change folder and status for test cycle 'SA-R40' by setting folder id and status id.",
33
39
  parameters: {
34
40
  testCycleIdOrKey: "SA-R40",
35
- folder: { id: 100006 },
41
+ folder: 100006,
36
42
  status: { id: 1e4 }
37
43
  },
38
44
  expectedOutput: "The test cycle should be updated, but no output is expected."
@@ -71,36 +77,46 @@ class UpdateTestCycle extends Tool {
71
77
  };
72
78
  handle = async (args) => {
73
79
  const parsed = UpdateTestCycleParams.and(
74
- UpdateTestCycleBody.partial()
80
+ UpdateTestCycleBodyToolInput
75
81
  ).parse(args);
76
- const { testCycleIdOrKey, ...rawUpdates } = parsed;
77
- const nullValuesObject = {};
78
- if (rawUpdates.folder) {
79
- nullValuesObject.folder = { id: rawUpdates.folder };
80
- }
81
- if (rawUpdates.owner) {
82
- nullValuesObject.owner = { accountId: rawUpdates.owner };
83
- }
84
- if (rawUpdates.jiraProjectVersion) {
85
- nullValuesObject.jiraProjectVersion = {
86
- id: rawUpdates.jiraProjectVersion
87
- };
88
- }
89
- const updates = {
90
- ...rawUpdates,
91
- ...nullValuesObject
92
- };
93
- if (updates.plannedStartDate === null) delete updates.plannedStartDate;
94
- if (updates.plannedEndDate === null) delete updates.plannedEndDate;
82
+ const { testCycleIdOrKey, ...updatesFromToolInput } = parsed;
83
+ const updatesForRestApi = this.toRestApiUpdates(updatesFromToolInput);
95
84
  const existingTestCycle = await this.client.getApiClient().get(`/testcycles/${testCycleIdOrKey}`);
96
- const mergedBody = deepMerge(existingTestCycle, updates);
97
- delete mergedBody.links;
85
+ const mergedBody = deepMerge(
86
+ existingTestCycle,
87
+ updatesForRestApi,
88
+ UpdateTestCycleBody.partial()
89
+ );
98
90
  await this.client.getApiClient().put(`/testcycles/${testCycleIdOrKey}`, mergedBody);
99
91
  return {
100
92
  structuredContent: {},
101
93
  content: []
102
94
  };
103
95
  };
96
+ // Convert the tool input into updates compatible with the REST API by
97
+ // expanding the primitive folder/jiraProjectVersion/owner IDs back into the
98
+ // `{ id }` / `{ accountId }` objects the REST API's UpdateTestCycleBody shape
99
+ // expects. A null plannedStartDate/plannedEndDate is passed through as-is: the
100
+ // API treats null on those fields as "leave unchanged", so no special handling
101
+ // is needed here.
102
+ toRestApiUpdates(updatesFromToolInput) {
103
+ const restApiCompatibleFields = {};
104
+ if (updatesFromToolInput.folder) {
105
+ restApiCompatibleFields.folder = { id: updatesFromToolInput.folder };
106
+ }
107
+ if (updatesFromToolInput.owner) {
108
+ restApiCompatibleFields.owner = { accountId: updatesFromToolInput.owner };
109
+ }
110
+ if (updatesFromToolInput.jiraProjectVersion) {
111
+ restApiCompatibleFields.jiraProjectVersion = {
112
+ id: updatesFromToolInput.jiraProjectVersion
113
+ };
114
+ }
115
+ return {
116
+ ...updatesFromToolInput,
117
+ ...restApiCompatibleFields
118
+ };
119
+ }
104
120
  }
105
121
  export {
106
122
  UpdateTestCycle
@@ -0,0 +1,65 @@
1
+ import { Tool } from "../../../common/tools.js";
2
+ import { ListTestPlansCursorPaginated200Response, ListTestPlansCursorPaginatedQueryParams } from "../../common/rest-api-schemas.js";
3
+ class GetTestPlans extends Tool {
4
+ specification = {
5
+ title: "Get Test Plans",
6
+ toolset: "Test Plans",
7
+ summary: "Get details of Test Plans in Zephyr",
8
+ readOnly: true,
9
+ idempotent: true,
10
+ inputSchema: ListTestPlansCursorPaginatedQueryParams,
11
+ outputSchema: ListTestPlansCursorPaginated200Response,
12
+ examples: [
13
+ {
14
+ description: "Get the first 10 Test Plans",
15
+ parameters: {
16
+ limit: 10,
17
+ startAtId: 0
18
+ },
19
+ expectedOutput: "The first 10 Test Plans with their details"
20
+ },
21
+ {
22
+ description: "Get any Test Plan",
23
+ parameters: {
24
+ limit: 1
25
+ },
26
+ expectedOutput: "One Test Plan with its details"
27
+ },
28
+ {
29
+ description: "Get five Test Plans starting from the ID 123",
30
+ parameters: {
31
+ limit: 5,
32
+ startAtId: 123
33
+ },
34
+ expectedOutput: "Five Test Plans starting from the ID 123 with their details"
35
+ },
36
+ {
37
+ description: "Get one Test Plan from the project PROJ",
38
+ parameters: {
39
+ projectKey: "PROJ",
40
+ limit: 1
41
+ },
42
+ expectedOutput: "One Test Plan from project PROJ with its details"
43
+ },
44
+ {
45
+ description: "Get Test Plans updated after a given time",
46
+ parameters: {
47
+ updatedAfter: "2024-01-01T00:00:00Z",
48
+ limit: 10
49
+ },
50
+ expectedOutput: "Up to 10 Test Plans updated after 2024-01-01 with their details"
51
+ }
52
+ ]
53
+ };
54
+ handle = async (args) => {
55
+ const parsedArgs = ListTestPlansCursorPaginatedQueryParams.parse(args);
56
+ const response = await this.client.getApiClient().get("/testplans/nextgen", parsedArgs);
57
+ return {
58
+ structuredContent: response,
59
+ content: []
60
+ };
61
+ };
62
+ }
63
+ export {
64
+ GetTestPlans
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartbear/mcp",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "MCP server for interacting SmartBear Products",
5
5
  "keywords": [
6
6
  "smartbear",