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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Text to search for in logs | |
| filename | No | Log file to search (default: combined.log) | combined.log |
| lines | No | Number of matching lines to return (default: 10) |
Implementation Reference
- local-logs-mcp-server.js:399-436 (handler)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 }; } }
- local-logs-mcp-server.js:164-187 (schema)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'] } }
- local-logs-mcp-server.js:231-233 (registration)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;