Repository navigation
feat: add search_container_logs MCP tool - #4832
Merged
Merged
Conversation
Adds a new MCP tool that searches container logs server-side and returns only matching entries. This is much more token-efficient than fetching all logs via get_container_logs and searching client-side, especially for AI agents with limited context windows. The tool supports case-insensitive search by default, optional case-sensitive mode, stream filtering (stdout/stderr/all), and a configurable time window. Results include a summary with match count and total entries scanned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
search_container_logsMCP tool that filters logs server-side before returning them. This solves a practical problem for AI agents:get_container_logsreturns up to 1MB of raw log entries, which can consume a large portion of an agent's context window. With search, only matching entries come back.Changes
search_container_logstool ininternal/mcp/server.goquery(required),host,container_id,since_minutes,stream, andcase_sensitiveparamsget_container_logs, but rarely hit since only matches are includeddocs/guide/mcp.mdwith the new tool in the available tools tableUsage
The agent calls
search_container_logswith a query string:search_container_logs(host="abc", container_id="def", query="error", since_minutes=60, stream="stderr")Response includes only matching log entries plus a summary:
Found 3 matches for "error" (scanned 450 entries): {"timestamp":"...","level":"error","stream":"stderr","message":"..."}