8
8
mcpgolang "github.com/metoro-io/mcp-golang"
9
9
"github.com/metoro-io/metoro-mcp-server/model"
10
10
"github.com/metoro-io/metoro-mcp-server/utils"
11
+ "slices"
12
+ "strings"
13
+ "time"
11
14
)
12
15
13
16
type GetAttributeKeysHandlerArgs struct {
@@ -26,6 +29,12 @@ func GetAttributeKeysHandler(ctx context.Context, arguments GetAttributeKeysHand
26
29
if arguments .MetricName == "" {
27
30
return nil , fmt .Errorf ("metricName is required when type is 'metric'" )
28
31
}
32
+
33
+ // Check whether the metric is valid. If not, return an error.
34
+ err = CheckMetric (ctx , arguments .MetricName )
35
+ if err != nil {
36
+ return nil , err
37
+ }
29
38
}
30
39
31
40
metricAttr := model.GetMetricAttributesRequest {
@@ -52,3 +61,27 @@ func GetAttributeKeysHandler(ctx context.Context, arguments GetAttributeKeysHand
52
61
53
62
return mcpgolang .NewToolResponse (mcpgolang .NewTextContent (fmt .Sprintf ("%s" , string (resp )))), nil
54
63
}
64
+
65
+ func CheckMetric (ctx context.Context , metricName string ) error {
66
+ now := time .Now ()
67
+ hourAgo := now .Add (- 30 * time .Minute )
68
+ request := model.FuzzyMetricsRequest {
69
+ StartTime : hourAgo .Unix (),
70
+ EndTime : now .Unix (),
71
+ MetricFuzzyMatch : "" , // This will return all the metric names.
72
+ }
73
+ metricNamesResp , err := getMetricNamesMetoroCall (ctx , request )
74
+
75
+ metricNames := model.GetMetricNamesResponse {}
76
+ err = json .Unmarshal (metricNamesResp , & metricNames )
77
+ if err != nil {
78
+ return fmt .Errorf ("error unmarshaling response: %v" , err )
79
+ }
80
+
81
+ metricNamesStr := strings .Join (metricNames .MetricNames , ", " )
82
+ if ! slices .Contains (metricNames .MetricNames , metricName ) {
83
+ return fmt .Errorf ("metricName '%s' is not valid. Valid metric names are: %s" , metricName , metricNamesStr )
84
+ }
85
+
86
+ return nil
87
+ }
0 commit comments