get_recent_errors
Retrieve recent error and warning log entries from your project's log files. Deduplicated and timestamped with secrets redacted.
Instructions
Returns recent ERROR and WARN log entries from the detected project's log files. Deduped, timestamped, secrets redacted. Defaults to last 50 lines.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | ||
| limit | No |
Implementation Reference
- src/tools/errors.ts:24-80 (handler)The actual handler/implementation of get_recent_errors. Reads log files, parses ERROR/WARN lines, deduplicates, redacts secrets, compresses, and returns the last N entries.
export async function getRecentErrors( cwd: string, logPaths: string[], limit: number = 50 ): Promise<ErrorEntry[]> { try { const entries: ErrorEntry[] = []; const seenMessages = new Set<string>(); for (const logPath of logPaths) { const fullPath = resolve(cwd, logPath); let fileStat; try { fileStat = await stat(fullPath); if (!fileStat.isFile()) { continue; } } catch { continue; } let content: string; try { content = await readFile(fullPath, "utf8"); } catch { continue; } const ageMs = Date.now() - fileStat.mtimeMs; const relativeTime = getRelativeTimeFromMs(ageMs); const lines = content.split(/\r?\n/); for (const line of lines) { if (!/(error|warn)/i.test(line)) { continue; } const level: ErrorEntry["level"] = /error/i.test(line) ? "ERROR" : "WARN"; const message = compress(redact(line)); if (seenMessages.has(message)) { continue; } seenMessages.add(message); entries.push({ time: relativeTime, level, message, }); } } return entries.slice(-limit); } catch { return []; } } - src/tools/errors.ts:6-10 (schema)The ErrorEntry interface defining the shape of each error entry returned by getRecentErrors.
export interface ErrorEntry { time: string; level: "ERROR" | "WARN"; message: string; } - src/index.ts:42-57 (registration)Registration of the get_recent_errors tool in the ListToolsRequestSchema handler, including its name, description, and input schema.
{ name: "get_recent_errors", description: "Returns recent ERROR and WARN log entries from the detected project's log files. Deduped, timestamped, secrets redacted. Defaults to last 50 lines.", inputSchema: { type: "object", properties: { cwd: { type: "string", }, limit: { type: "number", }, }, }, }, - src/index.ts:105-134 (registration)CallToolRequestSchema handler that dispatches to getRecentErrors when toolName === 'get_recent_errors'. Invokes detectFramework first to get logPaths, then calls getRecentErrors.
if (toolName === "get_recent_errors") { try { const args = request.params.arguments as | { cwd?: string; limit?: number } | undefined; const cwd = args?.cwd ?? process.cwd(); const limit = args?.limit ?? 50; const framework = await detectFramework(cwd); const result = await getRecentErrors(cwd, framework.logPaths, limit); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify({ error: `Failed to get recent errors: ${String(error)}`, }), }, ], }; } } - src/tools/errors.ts:12-22 (helper)Helper function getRelativeTimeFromMs that converts a file's age in milliseconds to a human-readable relative time string (e.g., 'just now', '5m ago', '2h ago'). Used to timestamp error entries.
function getRelativeTimeFromMs(ageMs: number): string { if (ageMs < 60_000) { return "just now"; } const minutes = Math.floor(ageMs / 60_000); if (minutes < 60) { return `${minutes}m ago`; } const hours = Math.floor(minutes / 60); return `${hours}h ago`; }