| 97 | } |
| 98 | |
| 99 | private async load(): Promise<McpAsyncTaskRecord[]> { |
| 100 | try { |
| 101 | const raw = await fs.readFile(this.filePath, "utf-8") |
| 102 | const json = JSON.parse(raw) as unknown |
| 103 | if (!Array.isArray(json)) return [] |
| 104 | const out: McpAsyncTaskRecord[] = [] |
| 105 | for (const item of json) { |
| 106 | const parsed = McpAsyncTaskRecordSchema.safeParse(item) |
| 107 | if (parsed.success) out.push(parsed.data) |
| 108 | } |
| 109 | return out |
| 110 | } catch (err: unknown) { |
| 111 | // ENOENT or malformed JSON → empty store |
| 112 | return [] |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | private async persist(records: McpAsyncTaskRecord[]): Promise<void> { |
| 117 | await fs.mkdir(path.dirname(this.filePath), { recursive: true }) |