Skip to main content
Glama
yufeizhou666

log-analyzer-mcp

by yufeizhou666

query_by_timerange

Retrieve log entries from a file or directory within a specified time range. Filter results by log level and limit the number of entries.

Instructions

Query logs within a specific time range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
startTimeYesStart time in ISO8601 format
endTimeYesEnd time in ISO8601 format
logPathNoPath to log file or directory/var/log
levelNoFilter by log level
limitNoMaximum number of results

Implementation Reference

  • Main handler function that executes the query_by_timerange tool logic. Validates required startTime/endTime params, finds .log files, reads them line-by-line filtering by time range and optional level, and returns matching results.
    export async function queryByTimerange(input: ToolInput): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { startTime, endTime, logPath = '/var/log', level, limit = 100 } = input as QueryByTimerangeInput;
    
      if (!startTime || !endTime) {
        return { content: [{ type: 'text', text: 'Error: startTime and endTime are required' }] };
      }
    
      const files = findLogFiles(logPath);
      if (files.length === 0) {
        return { content: [{ type: 'text', text: `No .log files found in ${logPath}` }] };
      }
    
      const allResults: string[] = [];
      for (const file of files) {
        const results = await queryFile(file, startTime, endTime, level, limit - allResults.length);
        allResults.push(...results);
        if (allResults.length >= limit) break;
      }
    
      return {
        content: [{
          type: 'text',
          text: allResults.length > 0
            ? allResults.join('\n')
            : `No logs found between ${startTime} and ${endTime}`
        }]
      };
    }
  • Input interface extending ToolInput, defining the schema with startTime, endTime (required), logPath, level, and limit (optional) fields.
    interface QueryByTimerangeInput extends ToolInput {
      startTime: string;
      endTime: string;
      logPath?: string;
      level?: LogLevel;
      limit?: number;
    }
  • src/index.ts:152-153 (registration)
    Dispatch/case statement in CallToolRequestSchema handler that routes 'query_by_timerange' calls to the queryByTimerange function.
    case 'query_by_timerange':
      return await queryByTimerange(args || {});
  • src/index.ts:65-97 (registration)
    Tool registration in the TOOLS array with name, description, and JSON schema for input validation (startTime/endTime required, optional logPath/level/limit).
    {
      name: 'query_by_timerange',
      description: 'Query logs within a specific time range',
      inputSchema: {
        type: 'object',
        properties: {
          startTime: {
            type: 'string',
            description: 'Start time in ISO8601 format'
          },
          endTime: {
            type: 'string',
            description: 'End time in ISO8601 format'
          },
          logPath: {
            type: 'string',
            default: '/var/log',
            description: 'Path to log file or directory'
          },
          level: {
            type: 'string',
            enum: ['ERROR', 'WARN', 'INFO', 'DEBUG'],
            description: 'Filter by log level'
          },
          limit: {
            type: 'number',
            default: 100,
            description: 'Maximum number of results'
          }
        },
        required: ['startTime', 'endTime']
      }
    },
  • Helper function queryFile that reads a single .log file via readline, parses each line with parseLogLine, filters by time range and level, and collects matching results.
    async function queryFile(
      filePath: string,
      startTime: string,
      endTime: string,
      level?: LogLevel,
      limit?: number
    ): Promise<string[]> {
      const results: string[] = [];
      const stream = fs.createReadStream(filePath);
      const rl = readline.createInterface({ input: stream });
    
      for await (const line of rl) {
        const entry = parseLogLine(line);
        if (!entry) continue;
    
        if (!isWithinTimeRange(entry, startTime, endTime)) continue;
        if (level && entry.level !== level) continue;
    
        results.push(`[${entry.timestamp.toISOString()}] [${entry.level}] ${entry.message}`);
        if (limit && results.length >= limit) break;
      }
    
      return results;
    }
Behavior2/5

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

With no annotations, the description carries full burden for behavioral disclosure. It only states the basic operation without revealing any behavioral traits (e.g., read-only, performance, pagination, or effects). This is insufficient for an agent to understand the tool's behavior.

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

Conciseness3/5

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

The description is extremely short (6 words), which is concise but at the expense of completeness. It leaves out essential information for an agent to use it effectively.

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?

No output schema is provided, so the description should explain return values, but it does not. The tool has 5 parameters and no annotations, yet the description covers only the basic purpose, leaving significant gaps.

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 baseline is 3. The tool description adds minimal meaning beyond the schema (only reiterating the time range). It does not compensate for any missing parameter context.

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 verb 'Query', resource 'logs', and constraint 'within a specific time range'. It provides a specific purpose but does not distinguish from sibling tool 'search_logs' which may have overlapping functionality.

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?

No guidance is provided on when to use this tool versus alternatives like 'search_logs' or 'count_by_level'. The description lacks context for appropriate usage scenarios.

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/yufeizhou666/my_mcp'

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