Skip to main content
Glama
yufeizhou666

log-analyzer-mcp

by yufeizhou666

count_by_level

Count log entries grouped by severity level (ERROR, WARN, INFO, DEBUG) for a given log path and time period.

Instructions

Count log entries by severity level (ERROR, WARN, INFO, DEBUG)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
logPathNoPath to log file or directory/var/log
startTimeNoStart time in ISO8601 format
endTimeNoEnd time in ISO8601 format

Implementation Reference

  • Main exported handler function for the count_by_level tool. Parses input (logPath, startTime, endTime), finds all .log files via findLogFiles, aggregates counts from each file using countFile, and returns a formatted text summary of ERROR/WARN/INFO/DEBUG/total counts.
    export async function countByLevel(input: ToolInput): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { logPath = '/var/log', startTime, endTime } = input as CountByLevelInput;
    
      const files = findLogFiles(logPath);
      if (files.length === 0) {
        return { content: [{ type: 'text', text: `No .log files found in ${logPath}` }] };
      }
    
      const totalCounts: CountResult = { ERROR: 0, WARN: 0, INFO: 0, DEBUG: 0, total: 0 };
    
      for (const file of files) {
        const counts = await countFile(file, startTime, endTime);
        totalCounts.ERROR += counts.ERROR;
        totalCounts.WARN += counts.WARN;
        totalCounts.INFO += counts.INFO;
        totalCounts.DEBUG += counts.DEBUG;
        totalCounts.total += counts.total;
      }
    
      const text = `Log Level Distribution:
      ERROR: ${totalCounts.ERROR}
      WARN:  ${totalCounts.WARN}
      INFO:  ${totalCounts.INFO}
      DEBUG: ${totalCounts.DEBUG}
      ────────────
      Total: ${totalCounts.total}`;
    
      return { content: [{ type: 'text', text }] };
    }
  • Input type definition for count_by_level extending ToolInput with optional logPath, startTime, and endTime properties.
    interface CountByLevelInput extends ToolInput {
      logPath?: string;
      startTime?: string;
      endTime?: string;
    }
  • src/index.ts:43-64 (registration)
    Registration of the count_by_level tool in the TOOLS array with name, description, and inputSchema specifying logPath, startTime, and endTime as optional parameters.
    {
      name: 'count_by_level',
      description: 'Count log entries by severity level (ERROR, WARN, INFO, DEBUG)',
      inputSchema: {
        type: 'object',
        properties: {
          logPath: {
            type: 'string',
            default: '/var/log',
            description: 'Path to log file or directory'
          },
          startTime: {
            type: 'string',
            description: 'Start time in ISO8601 format'
          },
          endTime: {
            type: 'string',
            description: 'End time in ISO8601 format'
          }
        }
      }
    },
  • src/index.ts:150-151 (registration)
    Routing dispatch: the CallToolRequestSchema handler maps the 'count_by_level' case to invoke countByLevel(args || {}).
    case 'count_by_level':
      return await countByLevel(args || {});
  • Helper function countFile that reads a single log file line-by-line, parses each line with parseLogLine, filters by time range with isWithinTimeRange, and accumulates counts by log level.
    async function countFile(
      filePath: string,
      startTime?: string,
      endTime?: string
    ): Promise<CountResult> {
      const counts: CountResult = { ERROR: 0, WARN: 0, INFO: 0, DEBUG: 0, total: 0 };
      const stream = fs.createReadStream(filePath);
      const rl = readline.createInterface({ input: stream });
    
      for await (const line of rl) {
        const entry = parseLogLine(line);
        if (entry && isWithinTimeRange(entry, startTime, endTime)) {
          counts[entry.level as LogLevel]++;
          counts.total++;
        }
      }
    
      return counts;
    }
Behavior2/5

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

No annotations are present, so the description must fully disclose behavior. It only states the counting operation but omits details such as read-only nature, error handling for missing paths, or output format. Minimal disclosure.

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?

Single sentence, front-loaded with action and levels. No wasted words. Efficient and to the point.

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?

Tool has 3 parameters, no output schema, and no annotations. Description is too brief; does not explain output format, behavior with directories vs files, or case sensitivity of levels. Incomplete for a tool aggregating log data by severity.

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 description adds no extra meaning beyond the schema; it does not explain how parameters like startTime/endTime relate to the counting logic.

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

Purpose5/5

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

Description clearly states the verb 'Count', the resource 'log entries', and the grouping 'by severity level' with explicit levels. It distinguishes from siblings like search_logs and query_by_timerange which do different operations.

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

Usage Guidelines3/5

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

The description implies usage for counting log entries by level but does not explicitly state when to use this over alternatives like search_logs or query_by_timerange. No prerequisites or exclusions provided.

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