@azure-devops/mcp 2.2.2 → 2.3.0-nightly.20251204

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,5 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
+ import { SuiteExpand } from "azure-devops-node-api/interfaces/TestPlanInterfaces.js";
3
4
  import { z } from "zod";
4
5
  const Test_Plan_Tools = {
5
6
  create_test_plan: "testplan_create_test_plan",
@@ -9,6 +10,7 @@ const Test_Plan_Tools = {
9
10
  test_results_from_build_id: "testplan_show_test_results_from_build_id",
10
11
  list_test_cases: "testplan_list_test_cases",
11
12
  list_test_plans: "testplan_list_test_plans",
13
+ list_test_suites: "testplan_list_test_suites",
12
14
  create_test_suite: "testplan_create_test_suite",
13
15
  };
14
16
  function configureTestPlanTools(server, _, connectionProvider) {
@@ -18,13 +20,22 @@ function configureTestPlanTools(server, _, connectionProvider) {
18
20
  includePlanDetails: z.boolean().default(false).describe("Include detailed information about each test plan."),
19
21
  continuationToken: z.string().optional().describe("Token to continue fetching test plans from a previous request."),
20
22
  }, async ({ project, filterActivePlans, includePlanDetails, continuationToken }) => {
21
- const owner = ""; //making owner an empty string untill we can figure out how to get owner id
22
- const connection = await connectionProvider();
23
- const testPlanApi = await connection.getTestPlanApi();
24
- const testPlans = await testPlanApi.getTestPlans(project, owner, continuationToken, includePlanDetails, filterActivePlans);
25
- return {
26
- content: [{ type: "text", text: JSON.stringify(testPlans, null, 2) }],
27
- };
23
+ try {
24
+ const owner = ""; //making owner an empty string untill we can figure out how to get owner id
25
+ const connection = await connectionProvider();
26
+ const testPlanApi = await connection.getTestPlanApi();
27
+ const testPlans = await testPlanApi.getTestPlans(project, owner, continuationToken, includePlanDetails, filterActivePlans);
28
+ return {
29
+ content: [{ type: "text", text: JSON.stringify(testPlans, null, 2) }],
30
+ };
31
+ }
32
+ catch (error) {
33
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
34
+ return {
35
+ content: [{ type: "text", text: `Error listing test plans: ${errorMessage}` }],
36
+ isError: true,
37
+ };
38
+ }
28
39
  });
29
40
  server.tool(Test_Plan_Tools.create_test_plan, "Creates a new test plan in the project.", {
30
41
  project: z.string().describe("The unique identifier (ID or name) of the Azure DevOps project where the test plan will be created."),
@@ -35,20 +46,29 @@ function configureTestPlanTools(server, _, connectionProvider) {
35
46
  endDate: z.string().optional().describe("The end date of the test plan"),
36
47
  areaPath: z.string().optional().describe("The area path for the test plan"),
37
48
  }, async ({ project, name, iteration, description, startDate, endDate, areaPath }) => {
38
- const connection = await connectionProvider();
39
- const testPlanApi = await connection.getTestPlanApi();
40
- const testPlanToCreate = {
41
- name,
42
- iteration,
43
- description,
44
- startDate: startDate ? new Date(startDate) : undefined,
45
- endDate: endDate ? new Date(endDate) : undefined,
46
- areaPath,
47
- };
48
- const createdTestPlan = await testPlanApi.createTestPlan(testPlanToCreate, project);
49
- return {
50
- content: [{ type: "text", text: JSON.stringify(createdTestPlan, null, 2) }],
51
- };
49
+ try {
50
+ const connection = await connectionProvider();
51
+ const testPlanApi = await connection.getTestPlanApi();
52
+ const testPlanToCreate = {
53
+ name,
54
+ iteration,
55
+ description,
56
+ startDate: startDate ? new Date(startDate) : undefined,
57
+ endDate: endDate ? new Date(endDate) : undefined,
58
+ areaPath,
59
+ };
60
+ const createdTestPlan = await testPlanApi.createTestPlan(testPlanToCreate, project);
61
+ return {
62
+ content: [{ type: "text", text: JSON.stringify(createdTestPlan, null, 2) }],
63
+ };
64
+ }
65
+ catch (error) {
66
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
67
+ return {
68
+ content: [{ type: "text", text: `Error creating test plan: ${errorMessage}` }],
69
+ isError: true,
70
+ };
71
+ }
52
72
  });
53
73
  server.tool(Test_Plan_Tools.create_test_suite, "Creates a new test suite in a test plan.", {
54
74
  project: z.string().describe("Project ID or project name"),
@@ -56,20 +76,29 @@ function configureTestPlanTools(server, _, connectionProvider) {
56
76
  parentSuiteId: z.number().describe("ID of the parent suite under which the new suite will be created, if not given by user this can be id of a root suite of the test plan"),
57
77
  name: z.string().describe("Name of the child test suite"),
58
78
  }, async ({ project, planId, parentSuiteId, name }) => {
59
- const connection = await connectionProvider();
60
- const testPlanApi = await connection.getTestPlanApi();
61
- const testSuiteToCreate = {
62
- name,
63
- parentSuite: {
64
- id: parentSuiteId,
65
- name: "",
66
- },
67
- suiteType: 2,
68
- };
69
- const createdTestSuite = await testPlanApi.createTestSuite(testSuiteToCreate, project, planId);
70
- return {
71
- content: [{ type: "text", text: JSON.stringify(createdTestSuite, null, 2) }],
72
- };
79
+ try {
80
+ const connection = await connectionProvider();
81
+ const testPlanApi = await connection.getTestPlanApi();
82
+ const testSuiteToCreate = {
83
+ name,
84
+ parentSuite: {
85
+ id: parentSuiteId,
86
+ name: "",
87
+ },
88
+ suiteType: 2,
89
+ };
90
+ const createdTestSuite = await testPlanApi.createTestSuite(testSuiteToCreate, project, planId);
91
+ return {
92
+ content: [{ type: "text", text: JSON.stringify(createdTestSuite, null, 2) }],
93
+ };
94
+ }
95
+ catch (error) {
96
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
97
+ return {
98
+ content: [{ type: "text", text: `Error creating test suite: ${errorMessage}` }],
99
+ isError: true,
100
+ };
101
+ }
73
102
  });
74
103
  server.tool(Test_Plan_Tools.add_test_cases_to_suite, "Adds existing test cases to a test suite.", {
75
104
  project: z.string().describe("The unique identifier (ID or name) of the Azure DevOps project."),
@@ -77,14 +106,23 @@ function configureTestPlanTools(server, _, connectionProvider) {
77
106
  suiteId: z.number().describe("The ID of the test suite."),
78
107
  testCaseIds: z.string().or(z.array(z.string())).describe("The ID(s) of the test case(s) to add. "),
79
108
  }, async ({ project, planId, suiteId, testCaseIds }) => {
80
- const connection = await connectionProvider();
81
- const testApi = await connection.getTestApi();
82
- // If testCaseIds is an array, convert it to comma-separated string
83
- const testCaseIdsString = Array.isArray(testCaseIds) ? testCaseIds.join(",") : testCaseIds;
84
- const addedTestCases = await testApi.addTestCasesToSuite(project, planId, suiteId, testCaseIdsString);
85
- return {
86
- content: [{ type: "text", text: JSON.stringify(addedTestCases, null, 2) }],
87
- };
109
+ try {
110
+ const connection = await connectionProvider();
111
+ const testApi = await connection.getTestApi();
112
+ // If testCaseIds is an array, convert it to comma-separated string
113
+ const testCaseIdsString = Array.isArray(testCaseIds) ? testCaseIds.join(",") : testCaseIds;
114
+ const addedTestCases = await testApi.addTestCasesToSuite(project, planId, suiteId, testCaseIdsString);
115
+ return {
116
+ content: [{ type: "text", text: JSON.stringify(addedTestCases, null, 2) }],
117
+ };
118
+ }
119
+ catch (error) {
120
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
121
+ return {
122
+ content: [{ type: "text", text: `Error adding test cases to suite: ${errorMessage}` }],
123
+ isError: true,
124
+ };
125
+ }
88
126
  });
89
127
  server.tool(Test_Plan_Tools.create_test_case, "Creates a new test case work item.", {
90
128
  project: z.string().describe("The unique identifier (ID or name) of the Azure DevOps project."),
@@ -98,61 +136,70 @@ function configureTestPlanTools(server, _, connectionProvider) {
98
136
  iterationPath: z.string().optional().describe("The iteration path for the test case."),
99
137
  testsWorkItemId: z.number().optional().describe("Optional work item id that will be set as a Microsoft.VSTS.Common.TestedBy-Reverse link to the test case."),
100
138
  }, async ({ project, title, steps, priority, areaPath, iterationPath, testsWorkItemId }) => {
101
- const connection = await connectionProvider();
102
- const witClient = await connection.getWorkItemTrackingApi();
103
- let stepsXml;
104
- if (steps) {
105
- stepsXml = convertStepsToXml(steps);
106
- }
107
- // Create JSON patch document for work item
108
- const patchDocument = [];
109
- patchDocument.push({
110
- op: "add",
111
- path: "/fields/System.Title",
112
- value: title,
113
- });
114
- if (testsWorkItemId) {
139
+ try {
140
+ const connection = await connectionProvider();
141
+ const witClient = await connection.getWorkItemTrackingApi();
142
+ let stepsXml;
143
+ if (steps) {
144
+ stepsXml = convertStepsToXml(steps);
145
+ }
146
+ // Create JSON patch document for work item
147
+ const patchDocument = [];
115
148
  patchDocument.push({
116
149
  op: "add",
117
- path: "/relations/-",
118
- value: {
119
- rel: "Microsoft.VSTS.Common.TestedBy-Reverse",
120
- url: `${connection.serverUrl}/${project}/_apis/wit/workItems/${testsWorkItemId}`,
121
- },
150
+ path: "/fields/System.Title",
151
+ value: title,
122
152
  });
153
+ if (testsWorkItemId) {
154
+ patchDocument.push({
155
+ op: "add",
156
+ path: "/relations/-",
157
+ value: {
158
+ rel: "Microsoft.VSTS.Common.TestedBy-Reverse",
159
+ url: `${connection.serverUrl}/${project}/_apis/wit/workItems/${testsWorkItemId}`,
160
+ },
161
+ });
162
+ }
163
+ if (stepsXml) {
164
+ patchDocument.push({
165
+ op: "add",
166
+ path: "/fields/Microsoft.VSTS.TCM.Steps",
167
+ value: stepsXml,
168
+ });
169
+ }
170
+ if (priority) {
171
+ patchDocument.push({
172
+ op: "add",
173
+ path: "/fields/Microsoft.VSTS.Common.Priority",
174
+ value: priority,
175
+ });
176
+ }
177
+ if (areaPath) {
178
+ patchDocument.push({
179
+ op: "add",
180
+ path: "/fields/System.AreaPath",
181
+ value: areaPath,
182
+ });
183
+ }
184
+ if (iterationPath) {
185
+ patchDocument.push({
186
+ op: "add",
187
+ path: "/fields/System.IterationPath",
188
+ value: iterationPath,
189
+ });
190
+ }
191
+ const workItem = await witClient.createWorkItem({}, patchDocument, project, "Test Case");
192
+ return {
193
+ content: [{ type: "text", text: JSON.stringify(workItem, null, 2) }],
194
+ };
123
195
  }
124
- if (stepsXml) {
125
- patchDocument.push({
126
- op: "add",
127
- path: "/fields/Microsoft.VSTS.TCM.Steps",
128
- value: stepsXml,
129
- });
130
- }
131
- if (priority) {
132
- patchDocument.push({
133
- op: "add",
134
- path: "/fields/Microsoft.VSTS.Common.Priority",
135
- value: priority,
136
- });
137
- }
138
- if (areaPath) {
139
- patchDocument.push({
140
- op: "add",
141
- path: "/fields/System.AreaPath",
142
- value: areaPath,
143
- });
196
+ catch (error) {
197
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
198
+ return {
199
+ content: [{ type: "text", text: `Error creating test case: ${errorMessage}` }],
200
+ isError: true,
201
+ };
144
202
  }
145
- if (iterationPath) {
146
- patchDocument.push({
147
- op: "add",
148
- path: "/fields/System.IterationPath",
149
- value: iterationPath,
150
- });
151
- }
152
- const workItem = await witClient.createWorkItem({}, patchDocument, project, "Test Case");
153
- return {
154
- content: [{ type: "text", text: JSON.stringify(workItem, null, 2) }],
155
- };
156
203
  });
157
204
  server.tool(Test_Plan_Tools.update_test_case_steps, "Update an existing test case work item.", {
158
205
  id: z.number().describe("The ID of the test case work item to update."),
@@ -160,48 +207,134 @@ function configureTestPlanTools(server, _, connectionProvider) {
160
207
  .string()
161
208
  .describe("The steps to reproduce the test case. Make sure to format each step as '1. Step one|Expected result one\n2. Step two|Expected result two. USE '|' as the delimiter between step and expected result. DO NOT use '|' in the description of the step or expected result."),
162
209
  }, async ({ id, steps }) => {
163
- const connection = await connectionProvider();
164
- const witClient = await connection.getWorkItemTrackingApi();
165
- let stepsXml;
166
- if (steps) {
167
- stepsXml = convertStepsToXml(steps);
168
- }
169
- // Create JSON patch document for work item
170
- const patchDocument = [];
171
- if (stepsXml) {
172
- patchDocument.push({
173
- op: "add",
174
- path: "/fields/Microsoft.VSTS.TCM.Steps",
175
- value: stepsXml,
176
- });
210
+ try {
211
+ const connection = await connectionProvider();
212
+ const witClient = await connection.getWorkItemTrackingApi();
213
+ let stepsXml;
214
+ if (steps) {
215
+ stepsXml = convertStepsToXml(steps);
216
+ }
217
+ // Create JSON patch document for work item
218
+ const patchDocument = [];
219
+ if (stepsXml) {
220
+ patchDocument.push({
221
+ op: "add",
222
+ path: "/fields/Microsoft.VSTS.TCM.Steps",
223
+ value: stepsXml,
224
+ });
225
+ }
226
+ const workItem = await witClient.updateWorkItem({}, patchDocument, id);
227
+ return {
228
+ content: [{ type: "text", text: JSON.stringify(workItem, null, 2) }],
229
+ };
230
+ }
231
+ catch (error) {
232
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
233
+ return {
234
+ content: [{ type: "text", text: `Error updating test case steps: ${errorMessage}` }],
235
+ isError: true,
236
+ };
177
237
  }
178
- const workItem = await witClient.updateWorkItem({}, patchDocument, id);
179
- return {
180
- content: [{ type: "text", text: JSON.stringify(workItem, null, 2) }],
181
- };
182
238
  });
183
239
  server.tool(Test_Plan_Tools.list_test_cases, "Gets a list of test cases in the test plan.", {
184
240
  project: z.string().describe("The unique identifier (ID or name) of the Azure DevOps project."),
185
241
  planid: z.number().describe("The ID of the test plan."),
186
242
  suiteid: z.number().describe("The ID of the test suite."),
187
243
  }, async ({ project, planid, suiteid }) => {
188
- const connection = await connectionProvider();
189
- const coreApi = await connection.getTestPlanApi();
190
- const testcases = await coreApi.getTestCaseList(project, planid, suiteid);
191
- return {
192
- content: [{ type: "text", text: JSON.stringify(testcases, null, 2) }],
193
- };
244
+ try {
245
+ const connection = await connectionProvider();
246
+ const coreApi = await connection.getTestPlanApi();
247
+ const testcases = await coreApi.getTestCaseList(project, planid, suiteid);
248
+ return {
249
+ content: [{ type: "text", text: JSON.stringify(testcases, null, 2) }],
250
+ };
251
+ }
252
+ catch (error) {
253
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
254
+ return {
255
+ content: [{ type: "text", text: `Error listing test cases: ${errorMessage}` }],
256
+ isError: true,
257
+ };
258
+ }
194
259
  });
195
260
  server.tool(Test_Plan_Tools.test_results_from_build_id, "Gets a list of test results for a given project and build ID.", {
196
261
  project: z.string().describe("The unique identifier (ID or name) of the Azure DevOps project."),
197
262
  buildid: z.number().describe("The ID of the build."),
198
263
  }, async ({ project, buildid }) => {
199
- const connection = await connectionProvider();
200
- const coreApi = await connection.getTestResultsApi();
201
- const testResults = await coreApi.getTestResultDetailsForBuild(project, buildid);
202
- return {
203
- content: [{ type: "text", text: JSON.stringify(testResults, null, 2) }],
204
- };
264
+ try {
265
+ const connection = await connectionProvider();
266
+ const coreApi = await connection.getTestResultsApi();
267
+ const testResults = await coreApi.getTestResultDetailsForBuild(project, buildid);
268
+ return {
269
+ content: [{ type: "text", text: JSON.stringify(testResults, null, 2) }],
270
+ };
271
+ }
272
+ catch (error) {
273
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
274
+ return {
275
+ content: [{ type: "text", text: `Error fetching test results: ${errorMessage}` }],
276
+ isError: true,
277
+ };
278
+ }
279
+ });
280
+ server.tool(Test_Plan_Tools.list_test_suites, "Retrieve a paginated list of test suites from an Azure DevOps project and Test Plan Id.", {
281
+ project: z.string().describe("The unique identifier (ID or name) of the Azure DevOps project."),
282
+ planId: z.number().describe("The ID of the test plan."),
283
+ continuationToken: z.string().optional().describe("Token to continue fetching test plans from a previous request."),
284
+ }, async ({ project, planId, continuationToken }) => {
285
+ try {
286
+ const connection = await connectionProvider();
287
+ const testPlanApi = await connection.getTestPlanApi();
288
+ const expand = SuiteExpand.Children;
289
+ const testSuites = await testPlanApi.getTestSuitesForPlan(project, planId, expand, continuationToken);
290
+ // The API returns a flat list where the root suite is first, followed by all nested suites
291
+ // We need to build a proper hierarchy by creating a map and assembling the tree
292
+ // Create a map of all suites by ID for quick lookup
293
+ const suiteMap = new Map();
294
+ testSuites.forEach((suite) => {
295
+ suiteMap.set(suite.id, {
296
+ id: suite.id,
297
+ name: suite.name,
298
+ parentSuiteId: suite.parentSuite?.id,
299
+ children: [],
300
+ });
301
+ });
302
+ // Build the hierarchy by linking children to parents
303
+ const roots = [];
304
+ suiteMap.forEach((suite) => {
305
+ if (suite.parentSuiteId && suiteMap.has(suite.parentSuiteId)) {
306
+ // This is a child suite, add it to its parent's children array
307
+ const parent = suiteMap.get(suite.parentSuiteId);
308
+ parent.children.push(suite);
309
+ }
310
+ else {
311
+ // This is a root suite (no parent or parent not in map)
312
+ roots.push(suite);
313
+ }
314
+ });
315
+ // Clean up the output - remove parentSuiteId and empty children arrays
316
+ const cleanSuite = (suite) => {
317
+ const cleaned = {
318
+ id: suite.id,
319
+ name: suite.name,
320
+ };
321
+ if (suite.children && suite.children.length > 0) {
322
+ cleaned.children = suite.children.map((child) => cleanSuite(child));
323
+ }
324
+ return cleaned;
325
+ };
326
+ const result = roots.map((root) => cleanSuite(root));
327
+ return {
328
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
329
+ };
330
+ }
331
+ catch (error) {
332
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
333
+ return {
334
+ content: [{ type: "text", text: `Error listing test suites: ${errorMessage}` }],
335
+ isError: true,
336
+ };
337
+ }
205
338
  });
206
339
  }
207
340
  /*