Skip to content

Commit 39de071

Browse files
authored
feat(mcp): return logs as pre-formatted strings to reduce token usage (#145)
1 parent 7ac3cc3 commit 39de071

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

internal/tiger/cmd/service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,8 @@ Examples:
15951595
for _, entry := range logs {
15961596
line := entry.Message
15971597
if !entry.Timestamp.IsZero() {
1598-
line = entry.Timestamp.UTC().Format("2006-01-02 15:04:05 UTC") + " " + line
1598+
// Local timezone for terminal output; MCP and public API use UTC.
1599+
line = entry.Timestamp.Local().Format("2006-01-02 15:04:05 MST") + " " + line
15991600
}
16001601
fmt.Fprintln(outputWriter, colorizeLogEntry(line, entry.Severity, shouldColorize))
16011602
}

internal/tiger/mcp/service_tools.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,7 @@ func (ServiceLogsInput) Schema() *jsonschema.Schema {
395395

396396
// ServiceLogsOutput represents output for service_logs
397397
type ServiceLogsOutput struct {
398-
Entries []serviceLogEntryOutput `json:"entries" jsonschema:"Structured log entries with timestamp, message, and severity, ordered from oldest to newest"`
399-
}
400-
401-
// serviceLogEntryOutput is the MCP output shape for a single log entry.
402-
type serviceLogEntryOutput struct {
403-
Timestamp time.Time `json:"timestamp"`
404-
Message string `json:"message"`
405-
Severity string `json:"severity"`
398+
Logs []string `json:"logs" jsonschema:"Log lines ordered from oldest to newest. Each line is prefixed with an RFC3339 timestamp followed by the log message."`
406399
}
407400

408401
func (ServiceLogsOutput) Schema() *jsonschema.Schema {
@@ -1184,14 +1177,14 @@ func (s *Server) handleServiceLogs(ctx context.Context, req *mcp.CallToolRequest
11841177
return nil, ServiceLogsOutput{}, err
11851178
}
11861179

1187-
structured := make([]serviceLogEntryOutput, len(entries))
1180+
logs := make([]string, len(entries))
11881181
for i, e := range entries {
1189-
structured[i] = serviceLogEntryOutput{
1190-
Timestamp: e.Timestamp,
1191-
Message: e.Message,
1192-
Severity: e.Severity,
1182+
if !e.Timestamp.IsZero() {
1183+
logs[i] = e.Timestamp.UTC().Format("2006-01-02 15:04:05 UTC") + " " + e.Message
1184+
} else {
1185+
logs[i] = e.Message
11931186
}
11941187
}
11951188

1196-
return nil, ServiceLogsOutput{Entries: structured}, nil
1189+
return nil, ServiceLogsOutput{Logs: logs}, nil
11971190
}

0 commit comments

Comments
 (0)