Skip to main content
Glama

watch_log_file

Monitor log files in real-time to detect errors and issues as they occur, enabling prompt debugging and analysis.

Instructions

Start monitoring a log file for real-time error detection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the log file to monitor
pollIntervalNoPolling interval in milliseconds

Implementation Reference

  • MCP server-side handler for the 'watch_log_file' tool. Validates input arguments and delegates to FileWatcher.watchLogFile to start monitoring the log file.
    private async handleWatchLogFile(args: any): Promise<MCPToolResult> {
      const { filePath, pollInterval = 1000 } = args;
    
      if (!filePath || typeof filePath !== 'string') {
        throw new Error('filePath is required and must be a string');
      }
    
      await this.fileWatcher.watchLogFile(filePath, { pollInterval });
    
      return {
        success: true,
        data: {
          message: `Started watching ${filePath}`,
          filePath,
          pollInterval
        }
      };
    }
  • Core helper function implementing log file watching using chokidar. Sets up polling watcher, handles file changes by analyzing new content for errors with LogAnalyzer, tracks errors per file.
    async watchLogFile(filePath: string, options: WatchOptions = {}): Promise<void> {
      // Validate file path first
      const validation = await LogUtils.validateFilePath(filePath);
      if (!validation.valid) {
        throw new Error(`Cannot watch file: ${validation.error}`);
      }
    
      // Stop existing watcher if present
      if (this.watchers.has(filePath)) {
        await this.stopWatching(filePath);
      }
    
      const watchOptions: WatchOptions = {
        pollInterval: options.pollInterval || 1000,
        ignoreInitial: options.ignoreInitial ?? false,
        usePolling: options.usePolling ?? true
      };
    
      // Get initial file size
      const stats = await fs.stat(filePath);
      const initialSize = stats.size;
    
      // Create watcher
      const watcher = chokidar.watch(filePath, {
        ignoreInitial: watchOptions.ignoreInitial,
        usePolling: watchOptions.usePolling,
        interval: watchOptions.pollInterval
      });
    
      const watchedFile: WatchedFile = {
        filePath,
        watcher,
        lastSize: initialSize,
        errors: [],
        lastUpdate: new Date(),
        options: watchOptions
      };
    
      // Set up event handlers
      watcher.on('change', async (path) => {
        await this.handleFileChange(path);
      });
    
      watcher.on('error', (error) => {
        console.error(`File watcher error for ${filePath}:`, error);
      });
    
      this.watchers.set(filePath, watchedFile);
    
      // Process initial content if not ignoring initial
      if (!watchOptions.ignoreInitial) {
        await this.handleFileChange(filePath);
      }
    }
  • src/server.ts:103-121 (registration)
    Registration of the 'watch_log_file' tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.
    {
      name: 'watch_log_file',
      description: 'Start monitoring a log file for real-time error detection',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path to the log file to monitor'
          },
          pollInterval: {
            type: 'number',
            default: 1000,
            description: 'Polling interval in milliseconds'
          }
        },
        required: ['filePath']
      }
    },
  • Input schema definition for the 'watch_log_file' tool, specifying required filePath and optional pollInterval.
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path to the log file to monitor'
          },
          pollInterval: {
            type: 'number',
            default: 1000,
            description: 'Polling interval in milliseconds'
          }
        },
        required: ['filePath']
      }
    },
  • Dispatch switch case in CallToolRequestSchema handler that routes 'watch_log_file' calls to the specific handler.
    case 'watch_log_file':
      result = await this.handleWatchLogFile(args);
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 'real-time error detection' which implies ongoing monitoring, but fails to describe critical behaviors such as whether this starts a background process, how errors are reported, if it requires specific permissions, or what happens on tool invocation. This leaves significant gaps for a monitoring tool.

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, well-structured sentence that efficiently conveys the core action and purpose without any wasted words. It is appropriately front-loaded with the main verb and resource, making it easy to parse quickly.

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 monitoring tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a stream, status, or error messages), how long monitoring persists, or interaction with sibling tools like 'stop_watching'. Given the complexity and lack of structured data, more context is needed.

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 both parameters ('filePath' and 'pollInterval'). The description adds no additional parameter semantics beyond what's in the schema, such as format examples or constraints. This meets the baseline for high schema coverage.

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 with a specific verb ('Start monitoring') and resource ('a log file'), and specifies the goal ('for real-time error detection'). However, it doesn't explicitly distinguish this tool from its siblings like 'list_watched_files' or 'stop_watching', which prevents a perfect score.

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 'analyze_log', 'get_recent_errors', or 'quick_scan'. It lacks any mention of prerequisites, exclusions, or comparative contexts, leaving the agent with insufficient direction for tool selection.

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/ChiragPatankar/loganalyzer-mcp'

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