Skip to content

feat: add search_container_logs MCP tool - #4832

Merged
amir20 merged 1 commit into
amir20:masterfrom
morcth:feat/mcp-search-logs
Jul 15, 2026
Merged

amir20 merged 1 commit into
amir20:masterfrom
morcth:feat/mcp-search-logs

Conversation

@morcth

@morcth morcth commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a search_container_logs MCP tool that filters logs server-side before returning them. This solves a practical problem for AI agents: get_container_logs returns 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

  • New search_container_logs tool in internal/mcp/server.go
  • Accepts query (required), host, container_id, since_minutes, stream, and case_sensitive params
  • Case-insensitive by default
  • Returns a summary line with match count and total entries scanned
  • Same 1MB cap as get_container_logs, but rarely hit since only matches are included
  • Added tests for matching, case sensitivity, no matches, and missing params
  • Updated docs/guide/mcp.md with the new tool in the available tools table

Usage

The agent calls search_container_logs with 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":"..."}

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.
@amir20
amir20 merged commit a0704d5 into amir20:master Jul 15, 2026
7 of 8 checks passed
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