Skip to content

Commit c38313e

Browse files
sd2kclaude
andauthored
docs: clarify UTC default for naive timestamps via server instructions (#755)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f53c6bc commit c38313e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cmd/mcp-grafana/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ Available Capabilities:
213213
- Rendering: Export dashboard panels or full dashboards as PNG images (requires Grafana Image Renderer plugin).
214214
- Proxied Tools: Access tools from external MCP servers (like Tempo) through dynamic discovery.
215215
216+
Timestamp parameters without a timezone offset are interpreted as UTC. Include an offset like '-05:00' or use relative syntax like 'now-1h' to query in a different timezone.
217+
216218
Note that some of these capabilities may be disabled. Do not try to use features that are not available via tools.
217219
`),
218220
server.WithHooks(hooks),

tools/time_helpers.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package tools
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
78
)
89

10+
// timeParamHint returns the canonical phrase appended to time-parameter parse
11+
// errors. It warns callers that naive timestamps (no timezone offset) are
12+
// interpreted as UTC by the server, and suggests including an explicit offset
13+
// like '-05:00' or using the relative 'now-Xh' syntax accepted by gtime.
14+
func timeParamHint() string {
15+
return "Timestamps without a timezone offset are interpreted as UTC; include an offset like '-05:00' or use relative syntax like 'now-1h'"
16+
}
17+
918
// parseStartTime parses start time strings in various formats.
1019
// Supports: "now", "now-Xs/m/h/d/w", RFC3339, ISO dates, and Unix timestamps.
1120
func parseStartTime(timeStr string) (time.Time, error) {
@@ -17,7 +26,11 @@ func parseStartTime(timeStr string) (time.Time, error) {
1726
From: timeStr,
1827
Now: time.Now(),
1928
}
20-
return tr.ParseFrom()
29+
t, err := tr.ParseFrom()
30+
if err != nil {
31+
return time.Time{}, fmt.Errorf("%w. %s", err, timeParamHint())
32+
}
33+
return t, nil
2134
}
2235

2336
// parseEndTime parses end time strings in various formats.
@@ -31,5 +44,9 @@ func parseEndTime(timeStr string) (time.Time, error) {
3144
To: timeStr,
3245
Now: time.Now(),
3346
}
34-
return tr.ParseTo()
47+
t, err := tr.ParseTo()
48+
if err != nil {
49+
return time.Time{}, fmt.Errorf("%w. %s", err, timeParamHint())
50+
}
51+
return t, nil
3552
}

0 commit comments

Comments
 (0)