@@ -57,8 +57,6 @@ func RequiredPermissionsFromTool(tool mcp.Tool) []string {
5757 return requiredPermissions
5858}
5959
60- // --- Time-window support for k8s_list_* Monitor tools --------------------
61-
6260const (
6361 windowedQueryTimeout = "60s"
6462 timeParamStart = "start"
@@ -67,32 +65,23 @@ const (
6765 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."
6866)
6967
70- // TimeWindow is a resolved, validated [Start, End] pair for a historical PromQL query.
71- // A zero-value TimeWindow means no window was requested — the caller should emit its
72- // existing instant query and leave GetQueryV1Params.Time nil.
7368type TimeWindow struct {
7469 Start time.Time
7570 End time.Time
7671}
7772
78- // IsZero reports whether no time window was requested.
7973func (w TimeWindow ) IsZero () bool {
8074 return w .Start .IsZero () && w .End .IsZero ()
8175}
8276
83- // RangeSelector returns the PromQL range-selector literal for this window, e.g. "[3600s]".
8477func (w TimeWindow ) RangeSelector () string {
8578 return fmt .Sprintf ("[%ds]" , int64 (w .End .Sub (w .Start ).Seconds ()))
8679}
8780
88- // WindowSeconds returns the duration of the window in whole seconds.
8981func (w TimeWindow ) WindowSeconds () int64 {
9082 return int64 (w .End .Sub (w .Start ).Seconds ())
9183}
9284
93- // EvalTime returns a *sysdig.Time suitable for GetQueryV1Params.Time. The value is
94- // the End instant as unix seconds — the native format accepted by Sysdig's internal
95- // PromQL stack (confirmed against backend PrometheusFacadeController.java:113).
9685func (w TimeWindow ) EvalTime () (* sysdig.Time , error ) {
9786 if w .IsZero () {
9887 return nil , nil
@@ -104,9 +93,6 @@ func (w TimeWindow) EvalTime() (*sysdig.Time, error) {
10493 return & qt , nil
10594}
10695
107- // ApplyToParams sets Time and, for windowed queries, Timeout on params.
108- // It consolidates the three-step boilerplate (EvalTime, set Time, set Timeout)
109- // that every k8s_list_* handler would otherwise repeat.
11096func (w TimeWindow ) ApplyToParams (params * sysdig.GetQueryV1Params ) error {
11197 evalTime , err := w .EvalTime ()
11298 if err != nil {
@@ -120,23 +106,15 @@ func (w TimeWindow) ApplyToParams(params *sysdig.GetQueryV1Params) error {
120106 return nil
121107}
122108
123- // WithTimeWindowParams returns a ToolOption that declares the shared "start" and "end"
124- // RFC3339 parameters on a tool.
125109func WithTimeWindowParams () mcp.ToolOption {
126110 return func (t * mcp.Tool ) {
127111 mcp .WithString (timeParamStart , mcp .Description (startParamDescription ))(t )
128112 mcp .WithString (timeParamEnd , mcp .Description (endParamDescription ))(t )
129113 }
130114}
131115
132- // ParseTimeWindow reads "start" and "end" from the request, validates them, and returns
133- // the resolved TimeWindow.
134- //
135- // - Both absent: returns zero-value TimeWindow, nil error.
136- // - end without start: error ("end requires start").
137- // - start without end: end = clk.Now().
138- // - invalid RFC3339: error naming the bad field.
139- // - end <= start: error.
116+ // Reads "start" and "end" from the request, validates them, and return the resolved TimeWindow.
117+
140118func ParseTimeWindow (request mcp.CallToolRequest , clk clock.Clock ) (TimeWindow , error ) {
141119 startStr := mcp .ParseString (request , timeParamStart , "" )
142120 endStr := mcp .ParseString (request , timeParamEnd , "" )
0 commit comments