@@ -28,16 +28,29 @@ function configureWorkTools(
2828 timeframe : z . enum ( [ "current" ] ) . optional ( ) . describe ( "The timeframe for which to retrieve iterations. Currently, only 'current' is supported." ) ,
2929 } ,
3030 async ( { project, team, timeframe } ) => {
31- const connection = await connectionProvider ( ) ;
32- const workApi = await connection . getWorkApi ( ) ;
33- const iterations = await workApi . getTeamIterations (
34- { project, team } ,
35- timeframe
36- ) ;
31+ try {
32+ const connection = await connectionProvider ( ) ;
33+ const workApi = await connection . getWorkApi ( ) ;
34+ const iterations = await workApi . getTeamIterations (
35+ { project, team } ,
36+ timeframe
37+ ) ;
38+
39+ if ( ! iterations ) {
40+ return { content : [ { type : "text" , text : "No iterations found" } ] , isError : true } ;
41+ }
3742
38- return {
39- content : [ { type : "text" , text : JSON . stringify ( iterations , null , 2 ) } ] ,
40- } ;
43+ return {
44+ content : [ { type : "text" , text : JSON . stringify ( iterations , null , 2 ) } ] ,
45+ } ;
46+ } catch ( error ) {
47+ const errorMessage = error instanceof Error ? error . message : 'Unknown error occurred' ;
48+
49+ return {
50+ content : [ { type : "text" , text : `Error fetching team iterations: ${ errorMessage } ` } ] ,
51+ isError : true
52+ } ;
53+ }
4154 }
4255 ) ;
4356
@@ -53,29 +66,45 @@ function configureWorkTools(
5366 } ) ) . describe ( "An array of iterations to create. Each iteration must have a name and can optionally have start and finish dates in ISO format." )
5467 } ,
5568 async ( { project, iterations } ) => {
56- const connection = await connectionProvider ( ) ;
57- const workItemTrackingApi = await connection . getWorkItemTrackingApi ( ) ;
69+ try {
70+ const connection = await connectionProvider ( ) ;
71+ const workItemTrackingApi = await connection . getWorkItemTrackingApi ( ) ;
72+ const results = [ ] ;
5873
59- const results = [ ] ;
60- for ( const { iterationName , startDate , finishDate } of iterations ) {
61- // Step 1: Create the iteration
62- const iteration = await workItemTrackingApi . createOrUpdateClassificationNode (
63- {
64- name : iterationName ,
65- attributes : {
66- startDate : startDate ? new Date ( startDate ) : undefined ,
67- finishDate : finishDate ? new Date ( finishDate ) : undefined ,
74+ for ( const { iterationName , startDate , finishDate } of iterations ) {
75+ // Step 1: Create the iteration
76+ const iteration = await workItemTrackingApi . createOrUpdateClassificationNode (
77+ {
78+ name : iterationName ,
79+ attributes : {
80+ startDate : startDate ? new Date ( startDate ) : undefined ,
81+ finishDate : finishDate ? new Date ( finishDate ) : undefined ,
82+ } ,
6883 } ,
69- } ,
70- project ,
71- TreeStructureGroup . Iterations
72- ) ;
73- results . push ( iteration ) ;
74- }
84+ project ,
85+ TreeStructureGroup . Iterations
86+ ) ;
87+
88+ if ( iteration ) {
89+ results . push ( iteration ) ;
90+ }
91+ }
92+
93+ if ( results . length === 0 ) {
94+ return { content : [ { type : "text" , text : "No iterations were created" } ] , isError : true } ;
95+ }
7596
76- return {
77- content : [ { type : "text" , text : JSON . stringify ( results , null , 2 ) } ] ,
78- } ;
97+ return {
98+ content : [ { type : "text" , text : JSON . stringify ( results , null , 2 ) } ] ,
99+ } ;
100+ } catch ( error ) {
101+ const errorMessage = error instanceof Error ? error . message : 'Unknown error occurred' ;
102+
103+ return {
104+ content : [ { type : "text" , text : `Error creating iterations: ${ errorMessage } ` } ] ,
105+ isError : true
106+ } ;
107+ }
79108 }
80109 ) ;
81110
@@ -91,24 +120,38 @@ function configureWorkTools(
91120 } ) ) . describe ( "An array of iterations to assign. Each iteration must have an identifier and a path." ) ,
92121 } ,
93122 async ( { project, team, iterations } ) => {
94- const connection = await connectionProvider ( ) ;
95- const workApi = await connection . getWorkApi ( ) ;
123+ try {
124+ const connection = await connectionProvider ( ) ;
125+ const workApi = await connection . getWorkApi ( ) ;
126+ const teamContext = { project, team } ;
127+ const results = [ ] ;
128+
129+ for ( const { identifier, path } of iterations ) {
130+ const assignment = await workApi . postTeamIteration (
131+ { path : path , id : identifier } ,
132+ teamContext
133+ ) ;
96134
97- const teamContext = { project , team } ;
98- const results = [ ] ;
99-
100- for ( const { identifier , path } of iterations ) {
101- const assignment = await workApi . postTeamIteration (
102- { path : path , id : identifier } ,
103- teamContext
104- ) ;
135+ if ( assignment ) {
136+ results . push ( assignment ) ;
137+ }
138+ }
139+
140+ if ( results . length === 0 ) {
141+ return { content : [ { type : "text" , text : "No iterations were assigned to the team" } ] , isError : true } ;
142+ }
105143
106- results . push ( assignment ) ;
144+ return {
145+ content : [ { type : "text" , text : JSON . stringify ( results , null , 2 ) } ] ,
146+ } ;
147+ } catch ( error ) {
148+ const errorMessage = error instanceof Error ? error . message : 'Unknown error occurred' ;
149+
150+ return {
151+ content : [ { type : "text" , text : `Error assigning iterations: ${ errorMessage } ` } ] ,
152+ isError : true
153+ } ;
107154 }
108-
109- return {
110- content : [ { type : "text" , text : JSON . stringify ( results , null , 2 ) } ] ,
111- } ;
112155 }
113156 ) ;
114157
0 commit comments