|
36 | 36 | " Must be either Unix timestamp or RFC3339. Defaults to 5m ago."),
|
37 | 37 | ),
|
38 | 38 | mcp.WithString("end_time",
|
39 |
| - mcp.Required(), |
40 | 39 | mcp.Description("[Optional] End timestamp for the query to be executed at."+
|
41 | 40 | " Must be either Unix timestamp or RFC3339. Defaults to current time."),
|
42 | 41 | ),
|
|
57 | 56 | " Must be either Unix timestamp or RFC3339. Defaults to 5m ago."),
|
58 | 57 | ),
|
59 | 58 | mcp.WithString("end_time",
|
60 |
| - mcp.Required(), |
61 | 59 | mcp.Description("[Optional] End timestamp for the query to be executed at."+
|
62 | 60 | " Must be either Unix timestamp or RFC3339. Defaults to current time."),
|
63 | 61 | ),
|
|
74 | 72 | " Must be either Unix timestamp or RFC3339. Defaults to 5m ago."),
|
75 | 73 | ),
|
76 | 74 | mcp.WithString("end_time",
|
| 75 | + mcp.Description("[Optional] End timestamp for the query to be executed at."+ |
| 76 | + " Must be either Unix timestamp or RFC3339. Defaults to current time."), |
| 77 | + ), |
| 78 | + ) |
| 79 | + |
| 80 | + labelValuesTool = mcp.NewTool("label_values", |
| 81 | + mcp.WithDescription("Performs a query for the values of the given label, time range and matchers"), |
| 82 | + mcp.WithString("label", |
77 | 83 | mcp.Required(),
|
| 84 | + mcp.Description("The label to query values for"), |
| 85 | + ), |
| 86 | + mcp.WithArray("matchers", |
| 87 | + mcp.Required(), |
| 88 | + mcp.Description("Label matchers"), |
| 89 | + ), |
| 90 | + mcp.WithString("start_time", |
| 91 | + mcp.Description("[Optional] Start timestamp for the query to be executed at."+ |
| 92 | + " Must be either Unix timestamp or RFC3339. Defaults to 5m ago."), |
| 93 | + ), |
| 94 | + mcp.WithString("end_time", |
78 | 95 | mcp.Description("[Optional] End timestamp for the query to be executed at."+
|
79 | 96 | " Must be either Unix timestamp or RFC3339. Defaults to current time."),
|
80 | 97 | ),
|
@@ -261,6 +278,49 @@ func labelNamesToolHandler(ctx context.Context, request mcp.CallToolRequest) (*m
|
261 | 278 | return mcp.NewToolResultText(data), err
|
262 | 279 | }
|
263 | 280 |
|
| 281 | +// LabelValues performs a query for the values of the given label, time range and matchers. |
| 282 | +func labelValuesToolHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 283 | + arguments := request.Params.Arguments |
| 284 | + label, ok := arguments["label"].(string) |
| 285 | + if !ok { |
| 286 | + return nil, errors.New("label must be a string") |
| 287 | + } |
| 288 | + |
| 289 | + argMatchers, ok := arguments["matchers"].([]any) |
| 290 | + if !ok { |
| 291 | + return nil, errors.New("matchers must be an array") |
| 292 | + } |
| 293 | + |
| 294 | + matchers := make([]string, len(argMatchers)) |
| 295 | + for i, m := range argMatchers { |
| 296 | + matchers[i] = m.(string) |
| 297 | + } |
| 298 | + |
| 299 | + endTs := time.Now() |
| 300 | + startTs := endTs.Add(DefaultLookbackDelta) |
| 301 | + |
| 302 | + if argEndTime, ok := arguments["end_time"].(string); ok { |
| 303 | + parsedEndTime, err := mcpProm.ParseTimestamp(argEndTime) |
| 304 | + if err != nil { |
| 305 | + return nil, fmt.Errorf("failed to parse end_time %s from args: %w", argEndTime, err) |
| 306 | + } |
| 307 | + |
| 308 | + endTs = parsedEndTime |
| 309 | + } |
| 310 | + |
| 311 | + if argStartTime, ok := arguments["start_time"].(string); ok { |
| 312 | + parsedStartTime, err := mcpProm.ParseTimestamp(argStartTime) |
| 313 | + if err != nil { |
| 314 | + return nil, fmt.Errorf("failed to parse start_time %s from args: %w", argStartTime, err) |
| 315 | + } |
| 316 | + |
| 317 | + startTs = parsedStartTime |
| 318 | + } |
| 319 | + |
| 320 | + data, err := labelValuesApiCall(ctx, label, matchers, startTs, endTs) |
| 321 | + return mcp.NewToolResultText(data), err |
| 322 | +} |
| 323 | + |
264 | 324 | func listAlertsToolHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
265 | 325 | data, err := listAlertsApiCall(ctx)
|
266 | 326 | return mcp.NewToolResultText(data), err
|
|
0 commit comments