@@ -83,11 +83,11 @@ func updateDashboardWithPatches(ctx context.Context, args UpdateDashboardParams)
8383 for i , op := range args .Operations {
8484 switch op .Op {
8585 case "replace" , "add" :
86- if err := setValueAtPath (dashboardMap , op .Path , op .Value ); err != nil {
86+ if err := applyJSONPath (dashboardMap , op .Path , op .Value , false ); err != nil {
8787 return nil , fmt .Errorf ("operation %d (%s at %s): %w" , i , op .Op , op .Path , err )
8888 }
8989 case "remove" :
90- if err := removeValueAtPath (dashboardMap , op .Path ); err != nil {
90+ if err := applyJSONPath (dashboardMap , op .Path , nil , true ); err != nil {
9191 return nil , fmt .Errorf ("operation %d (%s at %s): %w" , i , op .Op , op .Path , err )
9292 }
9393 default :
@@ -365,16 +365,6 @@ var GetDashboardSummary = mcpgrafana.MustTool(
365365 mcp .WithReadOnlyHintAnnotation (true ),
366366)
367367
368- // Helper function to set a value at a JSONPath
369- func setValueAtPath (data map [string ]interface {}, path string , value interface {}) error {
370- return applyJSONPath (data , path , value , false )
371- }
372-
373- // Helper function to remove a value at a JSONPath
374- func removeValueAtPath (data map [string ]interface {}, path string ) error {
375- return applyJSONPath (data , path , nil , true )
376- }
377-
378368// applyJSONPath applies a value to a JSONPath or removes it if remove=true
379369func applyJSONPath (data map [string ]interface {}, path string , value interface {}, remove bool ) error {
380370 // Remove the leading "$." if present
0 commit comments