@@ -36,7 +36,7 @@ func promClientFromContext(ctx context.Context, uid string) (promv1.API, error)
36
36
}
37
37
38
38
type ListPrometheusMetricMetadataParams struct {
39
- DatasourceUID string `json:"datasourceUid" jsonschema:"description=The UID of the datasource to query"`
39
+ DatasourceUID string `json:"datasourceUid" jsonschema:"required, description=The UID of the datasource to query"`
40
40
Limit int `json:"limit" jsonschema:"description=The maximum number of metrics to return"`
41
41
LimitPerMetric int `json:"limitPerMetric" jsonschema:"description=The maximum number of metrics to return per metric"`
42
42
Metric string `json:"metric" jsonschema:"description=The metric to query"`
@@ -71,9 +71,9 @@ var ListPrometheusMetricMetadataTool, ListPrometheusMetricMetadataHandler = mcpg
71
71
)
72
72
73
73
type QueryPrometheusParams struct {
74
- DatasourceUID string `json:"datasourceUid" jsonschema:"description=The UID of the datasource to query"`
75
- Expr string `json:"expr" jsonschema:"description=The PromQL expression to query"`
76
- StartRFC3339 string `json:"startRfc3339" jsonschema:"description=The start time in RFC3339 format"`
74
+ DatasourceUID string `json:"datasourceUid" jsonschema:"required, description=The UID of the datasource to query"`
75
+ Expr string `json:"expr" jsonschema:"required, description=The PromQL expression to query"`
76
+ StartRFC3339 string `json:"startRfc3339" jsonschema:"required, description=The start time in RFC3339 format"`
77
77
EndRFC3339 string `json:"endRfc3339,omitempty" jsonschema:"description=The end time in RFC3339 format. Ignored if queryType is 'instant'"`
78
78
StepSeconds int `json:"stepSeconds,omitempty" jsonschema:"description=The time series step size in seconds. Ignored if queryType is 'instant'"`
79
79
QueryType string `json:"queryType,omitempty" jsonschema:"description=The type of query to use. Either 'range' or 'instant'"`
@@ -143,7 +143,7 @@ var QueryPrometheusTool, QueryPrometheusHandler = mcpgrafana.MustTool(
143
143
)
144
144
145
145
type ListPrometheusMetricNamesParams struct {
146
- DatasourceUID string `json:"datasourceUid" jsonschema:"description=The UID of the datasource to query"`
146
+ DatasourceUID string `json:"datasourceUid" jsonschema:"required, description=The UID of the datasource to query"`
147
147
Regex string `json:"regex" jsonschema:"description=The regex to match against the metric names"`
148
148
Limit int `json:"limit,omitempty" jsonschema:"description=The maximum number of results to return"`
149
149
Page int `json:"page,omitempty" jsonschema:"description=The page number to return"`
@@ -171,15 +171,20 @@ func ListPrometheusMetricNames(ctx context.Context, args ListPrometheusMetricNam
171
171
return nil , fmt .Errorf ("listing Prometheus metric names: %w" , err )
172
172
}
173
173
174
- // Filter by regex
175
- re , err := regexp .Compile (args .Regex )
176
- if err != nil {
177
- return nil , fmt .Errorf ("compiling regex: %w" , err )
178
- }
179
-
180
- var matches []string
181
- for _ , val := range labelValues {
182
- if re .MatchString (string (val )) {
174
+ // Filter by regex if provided
175
+ matches := []string {}
176
+ if args .Regex != "" {
177
+ re , err := regexp .Compile (args .Regex )
178
+ if err != nil {
179
+ return nil , fmt .Errorf ("compiling regex: %w" , err )
180
+ }
181
+ for _ , val := range labelValues {
182
+ if re .MatchString (string (val )) {
183
+ matches = append (matches , string (val ))
184
+ }
185
+ }
186
+ } else {
187
+ for _ , val := range labelValues {
183
188
matches = append (matches , string (val ))
184
189
}
185
190
}
@@ -232,7 +237,7 @@ func (s Selector) String() string {
232
237
}
233
238
234
239
type ListPrometheusLabelNamesParams struct {
235
- DatasourceUID string `json:"datasourceUid" jsonschema:"description=The UID of the datasource to query"`
240
+ DatasourceUID string `json:"datasourceUid" jsonschema:"required, description=The UID of the datasource to query"`
236
241
Matches []Selector `json:"matches,omitempty" jsonschema:"description=Optionally, a list of label matchers to filter the results by"`
237
242
StartRFC3339 string `json:"startRfc3339,omitempty" jsonschema:"description=Optionally, the start time of the time range to filter the results by"`
238
243
EndRFC3339 string `json:"endRfc3339,omitempty" jsonschema:"description=Optionally, the end time of the time range to filter the results by"`
@@ -291,8 +296,8 @@ var ListPrometheusLabelNamesTool, ListPrometheusLabelNamesHandler = mcpgrafana.M
291
296
)
292
297
293
298
type ListPrometheusLabelValuesParams struct {
294
- DatasourceUID string `json:"datasourceUid" jsonschema:"description=The UID of the datasource to query"`
295
- LabelName string `json:"labelName" jsonschema:"description=The name of the label to query"`
299
+ DatasourceUID string `json:"datasourceUid" jsonschema:"required, description=The UID of the datasource to query"`
300
+ LabelName string `json:"labelName" jsonschema:"required, description=The name of the label to query"`
296
301
Matches []Selector `json:"matches,omitempty" jsonschema:"description=Optionally, a list of selectors to filter the results by"`
297
302
StartRFC3339 string `json:"startRfc3339,omitempty" jsonschema:"description=Optionally, the start time of the query"`
298
303
EndRFC3339 string `json:"endRfc3339,omitempty" jsonschema:"description=Optionally, the end time of the query"`
0 commit comments