@@ -284,3 +284,89 @@ func getAccountID(config *config.Config, request mcp.CallToolRequest) (string, e
284
284
}
285
285
return "" , fmt .Errorf ("Account ID is required" )
286
286
}
287
+
288
+ func FetchCommitmentCoverageTool (config * config.Config , client * client.CloudCostManagementService ) (tool mcp.Tool , handler server.ToolHandlerFunc ) {
289
+ return mcp .NewTool ("get_ccm_commitment_coverage" ,
290
+ mcp .WithDescription ("Get commitment coverage information for an account in Harness Cloud Cost Management" ),
291
+ mcp .WithString ("start_date" ,
292
+ mcp .Required (),
293
+ mcp .Description ("Start date to filter commitment coverage" ),
294
+ ),
295
+ mcp .WithString ("end_date" ,
296
+ mcp .Required (),
297
+ mcp .Description ("End date to filter commitment coverage" ),
298
+ ),
299
+ mcp .WithString ("service" ,
300
+ mcp .Description ("Optional service to filter commitment coverage" ),
301
+ ),
302
+ mcp .WithArray ("cloud_account_ids" ,
303
+ mcp .Description ("Optional cloud account IDs to filter commitment coverage" ),
304
+ mcp .Items (map [string ]any {
305
+ "type" : "string" ,
306
+ }),
307
+ ),
308
+ WithScope (config , false ),
309
+ ),
310
+ func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
311
+ accountId , err := getAccountID (config , request )
312
+ if err != nil {
313
+ return mcp .NewToolResultError (err .Error ()), nil
314
+ }
315
+
316
+ params := & dto.CCMCommitmentOptions {}
317
+ params .AccountIdentifier = & accountId
318
+
319
+ // Handle service parameter
320
+ service , ok , err := OptionalParamOK [string ](request , "service" )
321
+ if err != nil {
322
+ return mcp .NewToolResultError (err .Error ()), nil
323
+ }
324
+ if ok && service != "" {
325
+ params .Service = & service
326
+ }
327
+
328
+ // Handle cloud account IDs parameter
329
+ cloudAccountIDs , ok , err := OptionalParamOK [[]string ](request , "cloud_account_ids" )
330
+ if err != nil {
331
+ return mcp .NewToolResultError (err .Error ()), nil
332
+ }
333
+ if ok && len (cloudAccountIDs ) > 0 {
334
+ params .CloudAccountIDs = cloudAccountIDs
335
+ }
336
+
337
+ // Handle start date parameter
338
+ startDate , ok , err := OptionalParamOK [string ](request , "start_date" )
339
+ if err != nil {
340
+ return mcp .NewToolResultError (err .Error ()), nil
341
+ }
342
+ if ok && startDate != "" {
343
+ params .StartDate = & startDate
344
+ }
345
+
346
+ // Handle end date parameter
347
+ endDate , ok , err := OptionalParamOK [string ](request , "end_date" )
348
+ if err != nil {
349
+ return mcp .NewToolResultError (err .Error ()), nil
350
+ }
351
+ if ok && endDate != "" {
352
+ params .EndDate = & endDate
353
+ }
354
+
355
+ scope , err := fetchScope (config , request , false )
356
+ if err != nil {
357
+ return mcp .NewToolResultError (err .Error ()), nil
358
+ }
359
+
360
+ data , err := client .GetComputeCoverage (ctx , scope , params )
361
+ if err != nil {
362
+ return nil , fmt .Errorf ("failed to get commitment coverage: %w" , err )
363
+ }
364
+
365
+ r , err := json .Marshal (data )
366
+ if err != nil {
367
+ return nil , fmt .Errorf ("failed to marshal commitment coverage: %w" , err )
368
+ }
369
+
370
+ return mcp .NewToolResultText (string (r )), nil
371
+ }
372
+ }
0 commit comments