get-logs
Retrieve and filter stdout logs from a named pipe for debugging or analysis. Specify line count, text filters, or timestamps to query application output efficiently.
Instructions
Retrieve logs from the named pipe with optional filtering
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Text to filter logs by | |
| lines | No | Number of log lines to return | |
| since | No | Timestamp to get logs after |
Implementation Reference
- src/index.ts:178-210 (handler)The handler function for the 'get-logs' tool. It filters the in-memory log store based on optional parameters (lines, filter, since) and returns the most recent logs as a JSON-formatted text content block.async ({ lines, filter, since }) => { try { let logs = [...logStore]; if (filter) { logs = logs.filter((entry) => entry.message.toLowerCase().includes(filter.toLowerCase()), ); } if (since) { logs = logs.filter((entry) => { const timestamp = new Date(entry.timestamp).getTime(); return timestamp > since; }); } // Take the last N lines and reverse them so oldest is first logs = logs.slice(-lines).reverse(); return { content: [ { type: "text", text: JSON.stringify(logs, null, 2), }, ], }; } catch (error) { logJson(`Error retrieving logs: ${error}`); throw new Error("Failed to retrieve logs"); } },
- src/index.ts:169-177 (schema)Input schema for the 'get-logs' tool defined using Zod, with optional parameters for number of lines, filter text, and timestamp threshold.{ lines: z .number() .optional() .default(50) .describe("Number of log lines to return"), filter: z.string().optional().describe("Text to filter logs by"), since: z.number().optional().describe("Timestamp to get logs after"), },
- src/index.ts:165-211 (registration)Registration of the 'get-logs' tool on the MCP server, including description, input schema, and inline handler function.// Register get-logs tool server.tool( "get-logs", "Retrieve logs from the named pipe with optional filtering", { lines: z .number() .optional() .default(50) .describe("Number of log lines to return"), filter: z.string().optional().describe("Text to filter logs by"), since: z.number().optional().describe("Timestamp to get logs after"), }, async ({ lines, filter, since }) => { try { let logs = [...logStore]; if (filter) { logs = logs.filter((entry) => entry.message.toLowerCase().includes(filter.toLowerCase()), ); } if (since) { logs = logs.filter((entry) => { const timestamp = new Date(entry.timestamp).getTime(); return timestamp > since; }); } // Take the last N lines and reverse them so oldest is first logs = logs.slice(-lines).reverse(); return { content: [ { type: "text", text: JSON.stringify(logs, null, 2), }, ], }; } catch (error) { logJson(`Error retrieving logs: ${error}`); throw new Error("Failed to retrieve logs"); } }, );
- src/index.ts:28-28 (helper)In-memory store for log entries used by the get-logs handler.const logStore: LogEntry[] = [];
- src/index.ts:16-19 (helper)Type definition for log entries stored in logStore.interface LogEntry { timestamp: string; message: string; }