Skip to content

feat(mcp): return logs as pre-formatted strings to reduce token usage#145

Open
AdrianLC wants to merge 2 commits intomainfrom
adrian/logs-mcp-token-efficient
Open

feat(mcp): return logs as pre-formatted strings to reduce token usage#145
AdrianLC wants to merge 2 commits intomainfrom
adrian/logs-mcp-token-efficient

Conversation

@AdrianLC
Copy link
Copy Markdown
Contributor

@AdrianLC AdrianLC commented Apr 9, 2026

Summary

Improves on the structured log entries introduced in #143. That PR returned an entries array of JSON objects, each with timestamp, message, and severity fields. This PR replaces that with a flat logs []string where each line is an RFC3339 timestamp prepended to the log message.

The severity is already embedded in the message text so there is no information loss, but the token count per MCP tool call drops significantly — a JSON object with three named fields per entry becomes a single string.

Replace the structured entries array (objects with timestamp, message,
severity fields) with a flat []string where each line is prefixed with
an RFC3339 timestamp. The message already contains the severity so
there is no information loss, and the token count per log entry drops
significantly.
@AdrianLC AdrianLC force-pushed the adrian/logs-mcp-token-efficient branch from b1251d3 to 5140009 Compare April 9, 2026 16:32
@AdrianLC AdrianLC self-assigned this Apr 9, 2026
@AdrianLC AdrianLC marked this pull request as ready for review April 9, 2026 16:34
Copy link
Copy Markdown
Member

@nathanjcochran nathanjcochran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for making this change!

Message: e.Message,
Severity: e.Severity,
if !e.Timestamp.IsZero() {
logs[i] = e.Timestamp.UTC().Format(time.RFC3339) + " " + e.Message
Copy link
Copy Markdown
Member

@nathanjcochran nathanjcochran Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using a different timestamp format here compared to in the CLI command and API? Shouldn't we use the same format everywhere, for consistency?

Copy link
Copy Markdown
Contributor Author

@AdrianLC AdrianLC Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Claude doing it wrong.

I changed it but made the CLI use local timezone I think that's better in that case?
Let me know if you disagree though and we can change it to UTC too

Use "2006-01-02 15:04:05 UTC" (matching PostgreSQL log format) instead of
RFC3339 in MCP output. CLI text output renders in local timezone so users
see timestamps in their own timezone; MCP and the public API use UTC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants