Skip to main content
Glama

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
NameRequiredDescriptionDefault
filenameNoName of the log file (default: combined.log)combined.log
linesNoNumber of lines to return (default: 50)

Implementation Reference

  • 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 }; } }
  • 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: [] } },
  • 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;
  • 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: [] }

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/mariosss/local-logs-mcp-server'

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