Skip to main content
Glama
djm81

Log Analyzer MCP

by djm81

search_log_last_n_records

Retrieve the most recent log entries with optional filtering and surrounding context for analysis.

Instructions

Search for the last N (newest) records, optionally filtering, with context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYes
scopeNodefault
context_beforeNo
context_afterNo
log_dirs_overrideNo
log_content_patterns_overrideNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for search_log_last_n_records. Builds filter criteria with last_n parameter and delegates to analysis_engine.search_logs(filter_criteria) to perform the search.
    @mcp.tool()
    async def search_log_last_n_records(
        count: int,
        scope: str = "default",
        context_before: int = 2,
        context_after: int = 2,
        log_dirs_override: str = "",
        log_content_patterns_override: str = "",
    ) -> list[dict[str, Any]]:
        """Search for the last N (newest) records, optionally filtering, with context."""
        logger.info(
            "MCP search_log_last_n_records called with count=%s, scope='%s', "
            "context=%sB/%sA, log_dirs_override='%s', "
            "log_content_patterns_override='%s'",
            count,
            scope,
            context_before,
            context_after,
            log_dirs_override,
            log_content_patterns_override,
        )
        if count <= 0:
            logger.error("Invalid count for search_log_last_n_records: %s. Must be > 0.", count)
            raise McpError(ErrorData(code=-32602, message="Count must be a positive integer."))
    
        log_dirs_list = log_dirs_override.split(",") if log_dirs_override else None
        log_content_patterns_list = log_content_patterns_override.split(",") if log_content_patterns_override else None
    
        filter_criteria = build_filter_criteria(
            last_n=count,
            scope=scope,
            context_before=context_before,
            context_after=context_after,
            log_dirs_override=log_dirs_list,
            log_content_patterns_override=log_content_patterns_list,
        )
        try:
            results = await asyncio.to_thread(analysis_engine.search_logs, filter_criteria)
            logger.info("search_log_last_n_records returning %s records.", len(results))
            return results
        except Exception as e:  # pylint: disable=broad-exception-caught
            logger.error("Error in search_log_last_n_records: %s", e, exc_info=True)
            custom_message = f"Failed to search last N logs: {e!s}"
            raise McpError(ErrorData(code=-32603, message=custom_message)) from e
  • Pydantic BaseModel defining the input schema for the search_log_last_n_records tool, inheriting common fields from BaseSearchInput and adding the required 'count' parameter.
    class SearchLogLastNInput(BaseSearchInput):
        """Input for search_log_last_n_records."""
    
        count: int = Field(description="Number of last (newest) matching records to return.", gt=0)
  • The @mcp.tool() decorator registers the search_log_last_n_records function as an MCP tool in the FastMCP server.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'with context' and 'optionally filtering', but doesn't explain what 'context' means (e.g., surrounding log entries), how filtering works, whether this is a read-only operation, potential performance impacts, or output format. For a search tool with 6 parameters, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise—a single sentence that front-loads the core purpose. Every word earns its place, with no redundancy or fluff. It efficiently communicates the tool's essence without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (6 parameters, no annotations, but with an output schema), the description is incomplete. It lacks details on filtering mechanics, context behavior, and how parameters interact. The output schema may cover return values, but the description doesn't provide enough operational context for effective use, especially compared to siblings.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It only vaguely references 'filtering' and 'context', without explaining how parameters like 'scope', 'log_dirs_override', or 'log_content_patterns_override' relate to these concepts. The description adds minimal meaning beyond the schema's parameter names and types, failing to clarify usage or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Search for the last N (newest) records, optionally filtering, with context.' It specifies the verb ('search'), resource ('records'), and scope ('last N/newest'), which distinguishes it from siblings like 'search_log_first_n_records' (first N) and 'search_log_time_based' (time-based). However, it doesn't explicitly differentiate from 'search_log_all_records' in terms of filtering capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions 'optionally filtering' but doesn't specify what filtering entails or when to choose this over siblings like 'search_log_first_n_records' or 'search_log_time_based'. There's no mention of prerequisites, exclusions, or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/djm81/log_analyzer_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server