@@ -15,6 +15,14 @@ import (
1515 "github.com/mark3labs/mcp-go/server"
1616)
1717
18+ const (
19+ // DefaultLokiLogLimit is the default number of log lines to return if not specified
20+ DefaultLokiLogLimit = 10
21+
22+ // MaxLokiLogLimit is the maximum number of log lines that can be requested
23+ MaxLokiLogLimit = 100
24+ )
25+
1826type Client struct {
1927 httpClient * http.Client
2028 baseURL string
@@ -305,7 +313,7 @@ type QueryLokiLogsParams struct {
305313 LogQL string `json:"logql" jsonschema:"required,description=The LogQL query to execute"`
306314 StartRFC3339 string `json:"startRfc3339,omitempty" jsonschema:"description=Optionally, the start time of the query in RFC3339 format"`
307315 EndRFC3339 string `json:"endRfc3339,omitempty" jsonschema:"description=Optionally, the end time of the query in RFC3339 format"`
308- Limit int `json:"limit,omitempty" jsonschema:"description=Optionally, the maximum number of log lines to return"`
316+ Limit int `json:"limit,omitempty" jsonschema:"description=Optionally, the maximum number of log lines to return (default: 10, max: 100) "`
309317 Direction string `json:"direction,omitempty" jsonschema:"description=Optionally, the direction of the query: 'forward' or 'backward'"`
310318}
311319
@@ -316,6 +324,17 @@ type LogEntry struct {
316324 Labels map [string ]string `json:"labels"`
317325}
318326
327+ // enforceLogLimit ensures a log limit value is within acceptable bounds
328+ func enforceLogLimit (requestedLimit int ) int {
329+ if requestedLimit <= 0 {
330+ return DefaultLokiLogLimit
331+ }
332+ if requestedLimit > MaxLokiLogLimit {
333+ return MaxLokiLogLimit
334+ }
335+ return requestedLimit
336+ }
337+
319338// queryLokiLogs queries logs from a Loki datasource using LogQL
320339func queryLokiLogs (ctx context.Context , args QueryLokiLogsParams ) ([]LogEntry , error ) {
321340 client , err := newLokiClient (ctx , args .DatasourceUID )
@@ -335,11 +354,8 @@ func queryLokiLogs(ctx context.Context, args QueryLokiLogsParams) ([]LogEntry, e
335354 endTime = time .Now ().Format (time .RFC3339 )
336355 }
337356
338- // Set default limit if not provided
339- limit := args .Limit
340- if limit <= 0 {
341- limit = 10
342- }
357+ // Apply limit constraints
358+ limit := enforceLogLimit (args .Limit )
343359
344360 // Set default direction if not provided
345361 direction := args .Direction
0 commit comments