Skip to main content
Glama
mfreeman451

JSON Logs MCP Server

by mfreeman451

query_logs

Search and filter JSON log entries by level, module, function, time range, or message content to analyze application logs.

Instructions

Search and filter log entries across log files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesNoLog files to search (default: all files)
levelNoFilter by log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
moduleNoFilter by module name
functionNoFilter by function name
message_containsNoFilter by message content (case-insensitive)
start_timeNoStart time filter (ISO format)
end_timeNoEnd time filter (ISO format)
limitNoMaximum number of results

Implementation Reference

  • Core handler function in JsonLogAnalyzer that reads log files, parses entries, applies filters (level, module, function, message, time range), sorts by timestamp, and limits results.
    def query_logs(self,
                   files: Optional[List[str]] = None,
                   level: Optional[str] = None,
                   module: Optional[str] = None,
                   function: Optional[str] = None,
                   message_contains: Optional[str] = None,
                   start_time: Optional[str] = None,
                   end_time: Optional[str] = None,
                   limit: int = 100) -> List[Dict[str, Any]]:
        """Query logs with various filters"""
    
        # Determine which files to search
        if files is None:
            files = list(self.log_files_cache.keys())
    
        all_entries = []
        for filename in files:
            try:
                entries = self.read_log_file(filename)
                all_entries.extend(entries)
            except (FileNotFoundError, RuntimeError):
                continue
    
        # Apply filters
        filtered_entries = []
        for entry in all_entries:
            # Level filter
            if level and entry.get("level", "").upper() != level.upper():
                continue
    
            # Module filter
            if module and entry.get("module", "") != module:
                continue
    
            # Function filter
            if function and entry.get("function", "") != function:
                continue
    
            # Message contains filter
            if message_contains and message_contains.lower() not in entry.get("message", "").lower():
                continue
    
            # Time range filters
            timestamp = entry.get("parsed_timestamp")
            if start_time:
                try:
                    start_dt = datetime.fromisoformat(start_time)
                    if timestamp and timestamp < start_dt:
                        continue
                except ValueError:
                    pass
    
            if end_time:
                try:
                    end_dt = datetime.fromisoformat(end_time)
                    if timestamp and timestamp > end_dt:
                        continue
                except ValueError:
                    pass
    
            filtered_entries.append(entry)
    
        # Sort by timestamp (newest first) and limit
        filtered_entries.sort(key=lambda x: x.get("parsed_timestamp", datetime.min), reverse=True)
        return filtered_entries[:limit]
  • MCP tool dispatch handler in call_tool that invokes the query_logs method and formats results as JSON text content.
    if name == "query_logs":
        results = log_analyzer.query_logs(**arguments)
        # Remove parsed_timestamp for JSON serialization
        for entry in results:
            entry.pop("parsed_timestamp", None)
    
        return [
            types.TextContent(
                type="text",
                text=json.dumps(results, indent=2, default=str)
            )
        ]
  • Input schema defining parameters for the query_logs tool, including optional filters and limit.
    inputSchema={
        "type": "object",
        "properties": {
            "files": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Log files to search (default: all files)"
            },
            "level": {
                "type": "string",
                "description": "Filter by log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)"
            },
            "module": {
                "type": "string",
                "description": "Filter by module name"
            },
            "function": {
                "type": "string",
                "description": "Filter by function name"
            },
            "message_contains": {
                "type": "string",
                "description": "Filter by message content (case-insensitive)"
            },
            "start_time": {
                "type": "string",
                "description": "Start time filter (ISO format)"
            },
            "end_time": {
                "type": "string",
                "description": "End time filter (ISO format)"
            },
            "limit": {
                "type": "integer",
                "default": 100,
                "description": "Maximum number of results"
            }
        }
    }
  • Tool registration in list_tools() where query_logs is defined with name, description, and schema.
    types.Tool(
        name="query_logs",
        description="Search and filter log entries across log files",
        inputSchema={
            "type": "object",
            "properties": {
                "files": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Log files to search (default: all files)"
                },
                "level": {
                    "type": "string",
                    "description": "Filter by log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)"
                },
                "module": {
                    "type": "string",
                    "description": "Filter by module name"
                },
                "function": {
                    "type": "string",
                    "description": "Filter by function name"
                },
                "message_contains": {
                    "type": "string",
                    "description": "Filter by message content (case-insensitive)"
                },
                "start_time": {
                    "type": "string",
                    "description": "Start time filter (ISO format)"
                },
                "end_time": {
                    "type": "string",
                    "description": "End time filter (ISO format)"
                },
                "limit": {
                    "type": "integer",
                    "default": 100,
                    "description": "Maximum number of results"
                }
            }
        }
    ),
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Search and filter' implies a read-only operation, it doesn't specify whether this is safe, whether it requires authentication, how results are returned (e.g., pagination), or any rate limits. The description lacks critical behavioral context for a tool with 8 parameters.

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 a single, efficient sentence that clearly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with every word earning its place.

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

Completeness2/5

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

For a tool with 8 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns, how results are structured, or behavioral aspects like performance or limitations. The description should provide more context given the tool's complexity and lack of structured metadata.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all 8 parameters. The description adds no parameter-specific information beyond what's in the schema, maintaining the baseline score of 3 where the schema does the heavy lifting.

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 as 'Search and filter log entries across log files', which specifies the verb (search/filter) and resource (log entries). It distinguishes from sibling tools like 'aggregate_logs' and 'get_log_stats' by focusing on searching/filtering rather than aggregation or statistics, though it doesn't explicitly mention these distinctions.

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 like 'aggregate_logs' or 'get_log_stats'. It doesn't mention prerequisites, performance considerations, or typical use cases, leaving the agent to infer usage from the tool name alone.

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/mfreeman451/json-logs-mcp-server'

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