Skip to main content
Glama

search_logs

Search local log files for specific text patterns to identify errors, debug applications, and monitor system activity.

Instructions

Search for specific text in log files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesText to search for in logs
filenameNoLog file to search (default: combined.log)combined.log
linesNoNumber of matching lines to return (default: 10)

Implementation Reference

  • The `searchLogs` method that executes the tool logic: reads the specified log file, searches for lines containing the query (case-insensitive), collects up to `maxLines` matches with line numbers and extracted timestamps, and returns structured results.
    searchLogs(query, filename = 'combined.log', maxLines = 10) { try { const filePath = path.join(this.logsDir, filename); if (!fs.existsSync(filePath)) { return { matches: [], message: `Log file ${filename} not found`, query, filename }; } const content = fs.readFileSync(filePath, 'utf8'); const lines = content.split('\n'); const matches = []; for (let i = 0; i < lines.length && matches.length < maxLines; i++) { if (lines[i].toLowerCase().includes(query.toLowerCase())) { matches.push({ lineNumber: i + 1, content: lines[i].trim(), timestamp: this.extractTimestamp(lines[i]) }); } } return { matches, query, filename, matchCount: matches.length, message: `Found ${matches.length} matches for "${query}" in ${filename}` }; } catch (error) { return { matches: [], error: error.message, query, filename }; } }
  • Input schema for the `search_logs` tool as returned in `tools/list`, defining required `query` parameter and optional `filename` and `lines`.
    { name: 'search_logs', description: 'Search for specific text in log files', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Text to search for in logs' }, filename: { type: 'string', description: 'Log file to search (default: combined.log)', default: 'combined.log' }, lines: { type: 'number', description: 'Number of matching lines to return (default: 10)', default: 10 } }, required: ['query'] } }
  • Registration/dispatch in the `handleToolCall` switch statement that routes `tools/call` for 'search_logs' to the handler method.
    case 'search_logs': result = this.searchLogs(args?.query, args?.filename, args?.lines); break;

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