Skip to content

Commit 8c54225

Browse files
committed
remove 7-day cap on historical query window
1 parent 5583dc7 commit 8c54225

2 files changed

Lines changed: 7 additions & 29 deletions

File tree

internal/infra/mcp/tools/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ evaluated at `end`:
5757
| HTTP / network errors | `sum_over_time(metric[Ns]) / N` (rate per second) |
5858
| Inventory tools (clusters, nodes, workloads, pod_containers, cronjobs) | `max_over_time(metric[Ns]) > 0` (workloads with status=ready/desired/running drop the `> 0` guard) |
5959

60-
Validation rules (helper: `time_window.go`):
60+
Validation rules (helper: `utils.go`):
6161

6262
- `end` without `start` → error.
6363
- `start` without `end``end` defaults to now.
64+
- `end` in the future → clamped to now.
6465
- `end <= start` → error.
65-
- `end > now + 60s` → error (60 s grace for client clock skew).
66-
- `end - start > SYSDIG_MCP_MAX_INTERVAL` (default **168 h / 7 d**) → error.
6766

6867
Windowed queries carry a 60 s client-side PromQL `Timeout` to fail fast before the
6968
Sysdig edge proxy's own 80–90 s cut-off.

internal/infra/mcp/tools/utils.go

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package tools
33
import (
44
"fmt"
55
"log/slog"
6-
"os"
76
"time"
87

98
"github.com/mark3labs/mcp-go/mcp"
@@ -61,8 +60,6 @@ func RequiredPermissionsFromTool(tool mcp.Tool) []string {
6160
// --- Time-window support for k8s_list_* Monitor tools --------------------
6261

6362
const (
64-
maxIntervalEnvVar = "SYSDIG_MCP_MAX_INTERVAL"
65-
defaultMaxInterval = 168 * time.Hour // 7 days
6663
windowedQueryTimeout = "60s"
6764
timeParamStart = "start"
6865
timeParamEnd = "end"
@@ -115,12 +112,11 @@ func WithTimeWindowParams() mcp.ToolOption {
115112
// ParseTimeWindow reads "start" and "end" from the request, validates them, and returns
116113
// the resolved TimeWindow.
117114
//
118-
// - Both absent: returns zero-value TimeWindow, nil error.
119-
// - end without start: error ("end requires start").
120-
// - start without end: end = clk.Now().
121-
// - invalid RFC3339: error naming the bad field.
122-
// - end <= start: error.
123-
// - end - start > maxInterval(): error referencing SYSDIG_MCP_MAX_INTERVAL.
115+
// - Both absent: returns zero-value TimeWindow, nil error.
116+
// - end without start: error ("end requires start").
117+
// - start without end: end = clk.Now().
118+
// - invalid RFC3339: error naming the bad field.
119+
// - end <= start: error.
124120
func ParseTimeWindow(request mcp.CallToolRequest, clk clock.Clock) (TimeWindow, error) {
125121
startStr := mcp.ParseString(request, timeParamStart, "")
126122
endStr := mcp.ParseString(request, timeParamEnd, "")
@@ -158,26 +154,9 @@ func ParseTimeWindow(request mcp.CallToolRequest, clk clock.Clock) (TimeWindow,
158154
return TimeWindow{}, fmt.Errorf("end (%s) must be after start (%s)", end.Format(time.RFC3339), start.Format(time.RFC3339))
159155
}
160156

161-
window := end.Sub(start)
162-
if max := maxInterval(); window > max {
163-
return TimeWindow{}, fmt.Errorf("requested window (%s) exceeds maximum allowed (%s); set %s to raise the cap", window, max, maxIntervalEnvVar)
164-
}
165-
166157
return TimeWindow{Start: start, End: end}, nil
167158
}
168159

169-
// maxInterval returns the configured maximum window duration. The SYSDIG_MCP_MAX_INTERVAL
170-
// env var is read on every call (not cached) so tests can override it via t.Setenv without
171-
// bumping into sync.Once-style staleness.
172-
func maxInterval() time.Duration {
173-
if v := os.Getenv(maxIntervalEnvVar); v != "" {
174-
if d, err := time.ParseDuration(v); err == nil && d > 0 {
175-
return d
176-
}
177-
}
178-
return defaultMaxInterval
179-
}
180-
181160
// requestHasArg reports whether the caller explicitly supplied the named argument
182161
// (distinguishes "user passed empty string" from "user didn't pass the key at all").
183162
func requestHasArg(request mcp.CallToolRequest, name string) bool {

0 commit comments

Comments
 (0)