tail_log
Retrieve the last lines from a log file to monitor recent activity and debug applications by viewing recent log entries.
Instructions
Get the last N lines from a log file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | No | Name of the log file (default: combined.log) | combined.log |
| lines | No | Number of lines to return (default: 50) |
Implementation Reference
- local-logs-mcp-server.js:287-328 (handler)The tailLog method that executes the core logic of the 'tail_log' MCP tool. It reads the last N lines from the specified log file, preferring the 'tail' command on Unix-like systems and falling back to reading the entire file on Windows or if the command fails.tailLog(filename = 'combined.log', lines = 50) { try { const filePath = path.join(this.logsDir, filename); if (!fs.existsSync(filePath)) { return { content: '', message: `Log file ${filename} not found. Available files: ${this.getLogFiles().files.map(f => f.name).join(', ')}`, filename, lines: 0 }; } let content; try { if (process.platform === 'win32') { const fullContent = fs.readFileSync(filePath, 'utf8'); const allLines = fullContent.split('\n'); content = allLines.slice(-lines).join('\n'); } else { content = execSync(`tail -n ${lines} "${filePath}"`, { encoding: 'utf8' }); } } catch (cmdError) { const fullContent = fs.readFileSync(filePath, 'utf8'); const allLines = fullContent.split('\n'); content = allLines.slice(-lines).join('\n'); } const actualLines = content.split('\n').filter(line => line.trim()).length; return { content, message: `Last ${actualLines} lines from ${filename}`, filename, lines: actualLines, fileSize: fs.statSync(filePath).size, fileSizeHuman: this.formatBytes(fs.statSync(filePath).size) }; } catch (error) { return { content: '', error: error.message, filename }; } }
- local-logs-mcp-server.js:106-124 (registration)The registration of the 'tail_log' tool in the 'tools/list' RPC method response, including its name, description, and input schema.name: 'tail_log', description: 'Get the last N lines from a log file', inputSchema: { type: 'object', properties: { filename: { type: 'string', description: 'Name of the log file (default: combined.log)', default: 'combined.log' }, lines: { type: 'number', description: 'Number of lines to return (default: 50)', default: 50 } }, required: [] } },
- local-logs-mcp-server.js:215-217 (registration)The dispatch case in the 'tools/call' handler that routes 'tail_log' calls to the tailLog implementation method.case 'tail_log': result = this.tailLog(args?.filename, args?.lines); break;
- local-logs-mcp-server.js:108-123 (schema)The JSON schema defining the input parameters for the 'tail_log' tool: optional filename (string) and lines (number).inputSchema: { type: 'object', properties: { filename: { type: 'string', description: 'Name of the log file (default: combined.log)', default: 'combined.log' }, lines: { type: 'number', description: 'Number of lines to return (default: 50)', default: 50 } }, required: [] }