Skip to content

Commit bd0fd20

Browse files
committed
end in the future → clamped to now, query proceeds normally
1 parent 9883a6c commit bd0fd20

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

internal/infra/mcp/tools/utils.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ func RequiredPermissionsFromTool(tool mcp.Tool) []string {
6363
const (
6464
maxIntervalEnvVar = "SYSDIG_MCP_MAX_INTERVAL"
6565
defaultMaxInterval = 168 * time.Hour // 7 days
66-
futureClockSkewGrace = 60 * time.Second
6766
windowedQueryTimeout = "60s"
6867
timeParamStart = "start"
6968
timeParamEnd = "end"
7069
startParamDescription = "Start of the query window as an RFC3339 timestamp (e.g. 2026-04-01T00:00:00Z). When omitted, the tool returns an instant snapshot (current behavior). When provided without end, end defaults to now."
71-
endParamDescription = "End of the query window as an RFC3339 timestamp (e.g. 2026-04-01T01:00:00Z). Requires start. Must not be more than 60s in the future."
70+
endParamDescription = "End of the query window as an RFC3339 timestamp (e.g. 2026-04-01T01:00:00Z). Requires start. If in the future, clamped to now."
7271
)
7372

7473
// TimeWindow is a resolved, validated [Start, End] pair for a historical PromQL query.
@@ -121,7 +120,6 @@ func WithTimeWindowParams() mcp.ToolOption {
121120
// - start without end: end = clk.Now().
122121
// - invalid RFC3339: error naming the bad field.
123122
// - end <= start: error.
124-
// - end > clk.Now() + 60s: error (generous grace for client clock skew).
125123
// - end - start > maxInterval(): error referencing SYSDIG_MCP_MAX_INTERVAL.
126124
func ParseTimeWindow(request mcp.CallToolRequest, clk clock.Clock) (TimeWindow, error) {
127125
startStr := mcp.ParseString(request, timeParamStart, "")
@@ -152,12 +150,12 @@ func ParseTimeWindow(request mcp.CallToolRequest, clk clock.Clock) (TimeWindow,
152150
}
153151
}
154152

155-
if !end.After(start) {
156-
return TimeWindow{}, fmt.Errorf("end (%s) must be after start (%s)", end.Format(time.RFC3339), start.Format(time.RFC3339))
153+
if end.After(now) {
154+
end = now
157155
}
158156

159-
if end.After(now.Add(futureClockSkewGrace)) {
160-
return TimeWindow{}, fmt.Errorf("end (%s) must not be more than %s in the future (server time: %s)", end.Format(time.RFC3339), futureClockSkewGrace, now.Format(time.RFC3339))
157+
if !end.After(start) {
158+
return TimeWindow{}, fmt.Errorf("end (%s) must be after start (%s)", end.Format(time.RFC3339), start.Format(time.RFC3339))
161159
}
162160

163161
window := end.Sub(start)

0 commit comments

Comments
 (0)