Skip to content

Commit 083fbdc

Browse files
committed
address feedbacks
we found huge response for list alerts was issue, even reducing time duration from 24h default to 5h default was giving huge data, now we have structured response which only include useful data reduce default duration from 24h to 5 hours for all durations increase apicall context timeout to 600s from 30s(as per signoz)
1 parent d34969f commit 083fbdc

File tree

5 files changed

+105
-43
lines changed

5 files changed

+105
-43
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ go.work.sum
2727
# env file
2828
.env
2929

30+
# MCP Registry tokens
31+
.mcpregistry_github_token
32+
.mcpregistry_registry_token
33+
3034
# Editor/IDE
3135
.idea/
3236
.vscode/

internal/client/client.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *SigNoz) ListMetricKeys(ctx context.Context) (json.RawMessage, error) {
4040
req.Header.Set(ContentType, "application/json")
4141
req.Header.Set(SignozApiKey, s.apiKey)
4242

43-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
43+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
4444
defer cancel()
4545
req = req.WithContext(ctx)
4646

@@ -79,7 +79,7 @@ func (s *SigNoz) SearchMetricKeys(ctx context.Context, searchText string) (json.
7979
req.Header.Set(ContentType, "application/json")
8080
req.Header.Set(SignozApiKey, s.apiKey)
8181

82-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
82+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
8383
defer cancel()
8484
req = req.WithContext(ctx)
8585

@@ -118,7 +118,7 @@ func (s *SigNoz) ListAlerts(ctx context.Context) (json.RawMessage, error) {
118118
req.Header.Set(ContentType, "application/json")
119119
req.Header.Set(SignozApiKey, s.apiKey)
120120

121-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
121+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
122122
defer cancel()
123123
req = req.WithContext(ctx)
124124

@@ -156,7 +156,7 @@ func (s *SigNoz) GetAlertByRuleID(ctx context.Context, ruleID string) (json.RawM
156156
req.Header.Set(ContentType, "application/json")
157157
req.Header.Set(SignozApiKey, s.apiKey)
158158

159-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
159+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
160160
defer cancel()
161161
req = req.WithContext(ctx)
162162

@@ -197,7 +197,7 @@ func (s *SigNoz) ListDashboards(ctx context.Context) (json.RawMessage, error) {
197197
req.Header.Set(ContentType, "application/json")
198198
req.Header.Set(SignozApiKey, s.apiKey)
199199

200-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
200+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
201201
defer cancel()
202202
req = req.WithContext(ctx)
203203

@@ -290,7 +290,7 @@ func (s *SigNoz) GetDashboard(ctx context.Context, uuid string) (json.RawMessage
290290
req.Header.Set(ContentType, "application/json")
291291
req.Header.Set(SignozApiKey, s.apiKey)
292292

293-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
293+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
294294
defer cancel()
295295
req = req.WithContext(ctx)
296296

@@ -338,7 +338,7 @@ func (s *SigNoz) ListServices(ctx context.Context, start, end string) (json.RawM
338338

339339
s.logger.Debug("Fetching services from SigNoz", zap.String("start", start), zap.String("end", end))
340340

341-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
341+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
342342
defer cancel()
343343
req = req.WithContext(ctx)
344344
resp, err := http.DefaultClient.Do(req)
@@ -385,7 +385,7 @@ func (s *SigNoz) GetServiceTopOperations(ctx context.Context, start, end, servic
385385

386386
s.logger.Debug("Fetching service top operations", zap.String("start", start), zap.String("end", end), zap.String("service", service))
387387

388-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
388+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
389389
defer cancel()
390390
req = req.WithContext(ctx)
391391
resp, err := http.DefaultClient.Do(req)
@@ -422,7 +422,7 @@ func (s *SigNoz) QueryBuilderV5(ctx context.Context, body []byte) (json.RawMessa
422422
req.Header.Set(ContentType, "application/json")
423423
req.Header.Set(SignozApiKey, s.apiKey)
424424

425-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
425+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
426426
defer cancel()
427427
req = req.WithContext(ctx)
428428

@@ -467,7 +467,7 @@ func (s *SigNoz) GetAlertHistory(ctx context.Context, ruleID string, req types.A
467467

468468
s.logger.Debug("sending request", zap.String("url", url), zap.ByteString("body", reqBody))
469469

470-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
470+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
471471
defer cancel()
472472
httpReq = httpReq.WithContext(ctx)
473473

@@ -510,7 +510,7 @@ func (s *SigNoz) ListLogViews(ctx context.Context) (json.RawMessage, error) {
510510
req.Header.Set(ContentType, "application/json")
511511
req.Header.Set(SignozApiKey, s.apiKey)
512512

513-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
513+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
514514
defer cancel()
515515
req = req.WithContext(ctx)
516516

@@ -550,7 +550,7 @@ func (s *SigNoz) GetLogView(ctx context.Context, viewID string) (json.RawMessage
550550
req.Header.Set(ContentType, "application/json")
551551
req.Header.Set(SignozApiKey, s.apiKey)
552552

553-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
553+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
554554
defer cancel()
555555
req = req.WithContext(ctx)
556556

@@ -590,7 +590,7 @@ func (s *SigNoz) GetTraceFieldValues(ctx context.Context, fieldName string, sear
590590
req.Header.Set(ContentType, "application/json")
591591
req.Header.Set(SignozApiKey, s.apiKey)
592592

593-
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
593+
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
594594
defer cancel()
595595
req = req.WithContext(ctx)
596596

internal/handler/tools/handler.go

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (h *Handler) RegisterAlertsHandlers(s *server.MCPServer) {
113113
h.logger.Debug("Registering alerts handlers")
114114

115115
alertsTool := mcp.NewTool("list_alerts",
116-
mcp.WithDescription("List active alerts from SigNoz"),
116+
mcp.WithDescription("List active alerts from SigNoz. Returns list of alert with: alert name, rule ID, severity, start time, end time, and state."),
117117
)
118118
s.AddTool(alertsTool, func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
119119
h.logger.Debug("Tool called: list_alerts")
@@ -123,7 +123,33 @@ func (h *Handler) RegisterAlertsHandlers(s *server.MCPServer) {
123123
h.logger.Error("Failed to list alerts", zap.Error(err))
124124
return mcp.NewToolResultError(err.Error()), nil
125125
}
126-
return mcp.NewToolResultText(string(alerts)), nil
126+
127+
var apiResponse types.APIAlertsResponse
128+
if err := json.Unmarshal(alerts, &apiResponse); err != nil {
129+
h.logger.Error("Failed to parse alerts response", zap.Error(err), zap.String("response", string(alerts)))
130+
return mcp.NewToolResultError("failed to parse alerts response: " + err.Error()), nil
131+
}
132+
133+
// takes only meaningful data
134+
alertsList := make([]types.Alert, 0, len(apiResponse.Data))
135+
for _, apiAlert := range apiResponse.Data {
136+
alertsList = append(alertsList, types.Alert{
137+
Alertname: apiAlert.Labels.Alertname,
138+
RuleID: apiAlert.Labels.RuleID,
139+
Severity: apiAlert.Labels.Severity,
140+
StartsAt: apiAlert.StartsAt,
141+
EndsAt: apiAlert.EndsAt,
142+
State: apiAlert.Status.State,
143+
})
144+
}
145+
146+
alertsJSON, err := json.Marshal(alertsList)
147+
if err != nil {
148+
h.logger.Error("Failed to marshal alerts", zap.Error(err))
149+
return mcp.NewToolResultError("failed to marshal alerts: " + err.Error()), nil
150+
}
151+
152+
return mcp.NewToolResultText(string(alertsJSON)), nil
127153
})
128154

129155
getAlertTool := mcp.NewTool("get_alert",
@@ -153,10 +179,10 @@ func (h *Handler) RegisterAlertsHandlers(s *server.MCPServer) {
153179
})
154180

155181
alertHistoryTool := mcp.NewTool("get_alert_history",
156-
mcp.WithDescription("Get alert history timeline for a specific rule. Defaults to last 24 hours if no time specified."),
182+
mcp.WithDescription("Get alert history timeline for a specific rule. Defaults to last 5 hours if no time specified."),
157183
mcp.WithString("ruleId", mcp.Required(), mcp.Description("Alert rule ID")),
158-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
159-
mcp.WithString("start", mcp.Description("Start timestamp in milliseconds (optional, defaults to 24 hours ago)")),
184+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
185+
mcp.WithString("start", mcp.Description("Start timestamp in milliseconds (optional, defaults to 5 hours ago)")),
160186
mcp.WithString("end", mcp.Description("End timestamp in milliseconds (optional, defaults to now)")),
161187
mcp.WithString("offset", mcp.Description("Offset for pagination (default: 0)")),
162188
mcp.WithString("limit", mcp.Description("Limit number of results (default: 20)")),
@@ -290,9 +316,9 @@ func (h *Handler) RegisterServiceHandlers(s *server.MCPServer) {
290316
h.logger.Debug("Registering service handlers")
291317

292318
listTool := mcp.NewTool("list_services",
293-
mcp.WithDescription("List all services in SigNoz. Defaults to last 24 hours if no time specified."),
294-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
295-
mcp.WithString("start", mcp.Description("Start time in nanoseconds (optional, defaults to 24 hours ago)")),
319+
mcp.WithDescription("List all services in SigNoz. Defaults to last 5 hours if no time specified."),
320+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
321+
mcp.WithString("start", mcp.Description("Start time in nanoseconds (optional, defaults to 5 hours ago)")),
296322
mcp.WithString("end", mcp.Description("End time in nanoseconds (optional, defaults to now)")),
297323
)
298324

@@ -312,10 +338,10 @@ func (h *Handler) RegisterServiceHandlers(s *server.MCPServer) {
312338
})
313339

314340
getOpsTool := mcp.NewTool("get_service_top_operations",
315-
mcp.WithDescription("Get top operations for a specific service. Defaults to last 24 hours if no time specified."),
341+
mcp.WithDescription("Get top operations for a specific service. Defaults to last 5 hours if no time specified."),
316342
mcp.WithString("service", mcp.Required(), mcp.Description("Service name")),
317-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
318-
mcp.WithString("start", mcp.Description("Start time in nanoseconds (optional, defaults to 24 hours ago)")),
343+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
344+
mcp.WithString("start", mcp.Description("Start time in nanoseconds (optional, defaults to 5 hours ago)")),
319345
mcp.WithString("end", mcp.Description("End time in nanoseconds (optional, defaults to now)")),
320346
mcp.WithString("tags", mcp.Description("Optional tags JSON array")),
321347
)
@@ -574,9 +600,9 @@ func (h *Handler) RegisterLogsHandlers(s *server.MCPServer) {
574600
})
575601

576602
getErrorLogsTool := mcp.NewTool("get_error_logs",
577-
mcp.WithDescription("Get logs with ERROR or FATAL severity. Defaults to last 24 hours if no time specified."),
578-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
579-
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 24 hours ago)")),
603+
mcp.WithDescription("Get logs with ERROR or FATAL severity. Defaults to last 5 hours if no time specified."),
604+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
605+
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 5 hours ago)")),
580606
mcp.WithString("end", mcp.Description("End time in milliseconds (optional, defaults to now)")),
581607
mcp.WithString("service", mcp.Description("Optional service name to filter by")),
582608
mcp.WithString("limit", mcp.Description("Maximum number of logs to return (default: 100)")),
@@ -628,10 +654,10 @@ func (h *Handler) RegisterLogsHandlers(s *server.MCPServer) {
628654
})
629655

630656
searchLogsByServiceTool := mcp.NewTool("search_logs_by_service",
631-
mcp.WithDescription("Search logs for a specific service. Defaults to last 24 hours if no time specified."),
657+
mcp.WithDescription("Search logs for a specific service. Defaults to last 5 hours if no time specified."),
632658
mcp.WithString("service", mcp.Required(), mcp.Description("Service name to search logs for")),
633-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
634-
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 24 hours ago)")),
659+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
660+
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 5 hours ago)")),
635661
mcp.WithString("end", mcp.Description("End time in milliseconds (optional, defaults to now)")),
636662
mcp.WithString("severity", mcp.Description("Log severity filter (DEBUG, INFO, WARN, ERROR, FATAL)")),
637663
mcp.WithString("searchText", mcp.Description("Text to search for in log body")),
@@ -726,10 +752,10 @@ func (h *Handler) RegisterTracesHandlers(s *server.MCPServer) {
726752
})
727753

728754
searchTracesByServiceTool := mcp.NewTool("search_traces_by_service",
729-
mcp.WithDescription("Search traces for a specific service. Defaults to last 24 hours if no time specified."),
755+
mcp.WithDescription("Search traces for a specific service. Defaults to last 5 hours if no time specified."),
730756
mcp.WithString("service", mcp.Required(), mcp.Description("Service name to search traces for")),
731-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
732-
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 24 hours ago)")),
757+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
758+
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 5 hours ago)")),
733759
mcp.WithString("end", mcp.Description("End time in milliseconds (optional, defaults to now)")),
734760
mcp.WithString("operation", mcp.Description("Operation name to filter by")),
735761
mcp.WithString("error", mcp.Description("Filter by error status (true/false)")),
@@ -804,10 +830,10 @@ func (h *Handler) RegisterTracesHandlers(s *server.MCPServer) {
804830
})
805831

806832
getTraceDetailsTool := mcp.NewTool("get_trace_details",
807-
mcp.WithDescription("Get comprehensive trace information including all spans and metadata. Defaults to last 24 hours if no time specified."),
833+
mcp.WithDescription("Get comprehensive trace information including all spans and metadata. Defaults to last 5 hours if no time specified."),
808834
mcp.WithString("traceId", mcp.Required(), mcp.Description("Trace ID to get details for")),
809-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
810-
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 24 hours ago)")),
835+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
836+
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 5 hours ago)")),
811837
mcp.WithString("end", mcp.Description("End time in milliseconds (optional, defaults to now)")),
812838
mcp.WithString("includeSpans", mcp.Description("Include detailed span information (true/false, default: true)")),
813839
)
@@ -845,9 +871,9 @@ func (h *Handler) RegisterTracesHandlers(s *server.MCPServer) {
845871
})
846872

847873
getTraceErrorAnalysisTool := mcp.NewTool("get_trace_error_analysis",
848-
mcp.WithDescription("Analyze error patterns in traces. Defaults to last 24 hours if no time specified."),
849-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
850-
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 24 hours ago)")),
874+
mcp.WithDescription("Analyze error patterns in traces. Defaults to last 5 hours if no time specified."),
875+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
876+
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 5 hours ago)")),
851877
mcp.WithString("end", mcp.Description("End time in milliseconds (optional, defaults to now)")),
852878
mcp.WithString("service", mcp.Description("Service name to filter by (optional)")),
853879
)
@@ -880,10 +906,10 @@ func (h *Handler) RegisterTracesHandlers(s *server.MCPServer) {
880906
})
881907

882908
getTraceSpanHierarchyTool := mcp.NewTool("get_trace_span_hierarchy",
883-
mcp.WithDescription("Get trace span relationships and hierarchy. Defaults to last 24 hours if no time specified."),
909+
mcp.WithDescription("Get trace span relationships and hierarchy. Defaults to last 5 hours if no time specified."),
884910
mcp.WithString("traceId", mcp.Required(), mcp.Description("Trace ID to get span hierarchy for")),
885-
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '6h', '24h', '7d'. Defaults to last 24 hours if not provided.")),
886-
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 24 hours ago)")),
911+
mcp.WithString("timeRange", mcp.Description("Time range string (optional, overrides start/end). Format: <number><unit> where unit is 'm' (minutes), 'h' (hours), or 'd' (days). Examples: '30m', '1h', '2h', '5h', '6h', '24h', '7d'. Defaults to last 5 hours if not provided.")),
912+
mcp.WithString("start", mcp.Description("Start time in milliseconds (optional, defaults to 5 hours ago)")),
887913
mcp.WithString("end", mcp.Description("End time in milliseconds (optional, defaults to now)")),
888914
)
889915

pkg/timeutil/time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func GetTimestampsWithDefaults(args map[string]any, unit string) (start, end str
3838
}
3939

4040
defaultEnd := toUnix(now)
41-
defaultStart := toUnix(now.Add(-24 * time.Hour))
41+
defaultStart := toUnix(now.Add(-5 * time.Hour))
4242

4343
if timeRange, ok := args["timeRange"].(string); ok && timeRange != "" {
4444
if duration, err := ParseTimeRange(timeRange); err == nil {

0 commit comments

Comments
 (0)