@@ -110,32 +110,34 @@ export const listAnnotationsTool: ToolConfig<
110110 transformResponse : async ( response : Response ) => {
111111 const data = await response . json ( )
112112
113+ // Handle potential nested array structure
114+ const rawAnnotations = Array . isArray ( data ) ? data . flat ( ) : [ ]
115+
113116 return {
114117 success : true ,
115118 output : {
116- annotations : Array . isArray ( data )
117- ? data . map ( ( a : any ) => ( {
118- id : a . id ,
119- alertId : a . alertId ,
120- alertName : a . alertName ,
121- dashboardId : a . dashboardId ,
122- dashboardUID : a . dashboardUID ,
123- panelId : a . panelId ,
124- userId : a . userId ,
125- newState : a . newState ,
126- prevState : a . prevState ,
127- created : a . created ,
128- updated : a . updated ,
129- time : a . time ,
130- timeEnd : a . timeEnd ,
131- text : a . text ,
132- tags : a . tags || [ ] ,
133- login : a . login ,
134- email : a . email ,
135- avatarUrl : a . avatarUrl ,
136- data : a . data ,
137- } ) )
138- : [ ] ,
119+ annotations : rawAnnotations . map ( ( a : any ) => ( {
120+ id : a . id ,
121+ dashboardId : a . dashboardId ,
122+ dashboardUID : a . dashboardUID ,
123+ created : a . created ,
124+ updated : a . updated ,
125+ time : a . time ,
126+ timeEnd : a . timeEnd ,
127+ text : a . text ,
128+ tags : a . tags || [ ] ,
129+ login : a . login ,
130+ email : a . email ,
131+ avatarUrl : a . avatarUrl ,
132+ data : a . data || { } ,
133+ // Optional fields - only included if they exist in the response
134+ ...( a . alertId !== undefined && { alertId : a . alertId } ) ,
135+ ...( a . alertName !== undefined && { alertName : a . alertName } ) ,
136+ ...( a . panelId !== undefined && { panelId : a . panelId } ) ,
137+ ...( a . userId !== undefined && { userId : a . userId } ) ,
138+ ...( a . newState !== undefined && { newState : a . newState } ) ,
139+ ...( a . prevState !== undefined && { prevState : a . prevState } ) ,
140+ } ) ) ,
139141 } ,
140142 }
141143 } ,
@@ -148,12 +150,21 @@ export const listAnnotationsTool: ToolConfig<
148150 type : 'object' ,
149151 properties : {
150152 id : { type : 'number' , description : 'Annotation ID' } ,
151- text : { type : 'string' , description : 'Annotation text' } ,
152- tags : { type : 'array' , description : 'Annotation tags' } ,
153+ dashboardId : { type : 'number' , description : 'Dashboard ID' } ,
154+ dashboardUID : { type : 'string' , description : 'Dashboard UID' } ,
155+ created : { type : 'number' , description : 'Creation timestamp in epoch ms' } ,
156+ updated : { type : 'number' , description : 'Last update timestamp in epoch ms' } ,
153157 time : { type : 'number' , description : 'Start time in epoch ms' } ,
154158 timeEnd : { type : 'number' , description : 'End time in epoch ms' } ,
155- dashboardUID : { type : 'string' , description : 'Dashboard UID' } ,
156- panelId : { type : 'number' , description : 'Panel ID' } ,
159+ text : { type : 'string' , description : 'Annotation text' } ,
160+ tags : { type : 'array' , items : { type : 'string' } , description : 'Annotation tags' } ,
161+ login : { type : 'string' , description : 'Login of the user who created the annotation' } ,
162+ email : { type : 'string' , description : 'Email of the user who created the annotation' } ,
163+ avatarUrl : { type : 'string' , description : 'Avatar URL of the user' } ,
164+ data : {
165+ type : 'json' ,
166+ description : 'Additional annotation data object from Grafana' ,
167+ } ,
157168 } ,
158169 } ,
159170 } ,
0 commit comments