jp_lit_prune_cache
Remove outdated cache files from local storage by listing entries older than a set number of days and deleting them only in non-dry-run mode.
Instructions
古いローカルキャッシュ候補を列挙し、dry_run=false のときだけ安全に削除する
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| older_than_days | No | ||
| tool | No | ||
| dry_run | No | ||
| limit | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | Yes | ||
| older_than_days | Yes | ||
| cutoff_saved_at | Yes | ||
| tool | Yes | ||
| limit | Yes | ||
| matched_count | Yes | ||
| pruned_count | Yes | ||
| total_bytes | Yes | ||
| candidates | Yes | ||
| skipped_count | Yes | ||
| skipped | Yes | ||
| message | Yes |
Implementation Reference
- src/tools/jpLitPruneCache.ts:17-72 (handler)Main tool handler: creates the prune-cache tool function. Parses input (older_than_days, tool filter, dry_run, limit), lists cache inventory, filters/sorts candidates by cutoff date, optionally removes them, and returns structured output.
export function createJpLitPruneCacheTool( baseDir = process.cwd(), now = () => new Date() ) { return async (input: unknown) => { const parsed = pruneCacheInputSchema.parse(input); const cutoff = cutoffFrom(now(), parsed.older_than_days); const inventory = await listCacheInventory(baseDir, parsed.tool); const candidates = inventory.items .filter((item) => item.saved_at < cutoff) .sort((left, right) => left.saved_at.localeCompare(right.saved_at)) .slice(0, parsed.limit); let prunedCount = 0; if (!parsed.dry_run) { for (const candidate of candidates) { await removeInventoryItem(candidate, baseDir); prunedCount += 1; } } const totalBytes = candidates.reduce((sum, item) => sum + item.bytes, 0); const structuredContent: PruneCacheOutput = pruneCacheOutputSchema.parse({ dry_run: parsed.dry_run, older_than_days: parsed.older_than_days, cutoff_saved_at: cutoff, tool: parsed.tool ?? null, limit: parsed.limit, matched_count: candidates.length, pruned_count: prunedCount, total_bytes: totalBytes, candidates: candidates.map(({ tool, cache_key, saved_at, bytes, root }) => ({ tool, cache_key, saved_at, bytes, root })), skipped_count: inventory.skipped.length, skipped: inventory.skipped, message: parsed.dry_run ? `${candidates.length} 件の削除候補があります。削除するには dry_run=false を指定してください。` : `${prunedCount} 件のキャッシュを削除しました。` }); return { content: [ { type: "text" as const, text: JSON.stringify(structuredContent, null, 2) } ], structuredContent }; }; } - src/lib/schemas.ts:439-444 (schema)Input schema: older_than_days (default 30), optional tool filter, dry_run (default true), limit (default 100, max 1000).
export const pruneCacheInputSchema = z.object({ older_than_days: z.number().int().positive().default(30), tool: z.string().trim().min(1).optional(), dry_run: z.boolean().default(true), limit: z.number().int().positive().max(1000).default(100) }); - src/lib/schemas.ts:446-468 (schema)Output schema: structured result including dry_run, cutoff date, tool filter, counts, candidate list, skipped items, and a human-readable message.
export const pruneCacheOutputSchema = z.object({ dry_run: z.boolean(), older_than_days: z.number().int().positive(), cutoff_saved_at: z.string(), tool: z.string().nullable(), limit: z.number().int().positive(), matched_count: z.number().int().nonnegative(), pruned_count: z.number().int().nonnegative(), total_bytes: z.number().int().nonnegative(), candidates: z.array(z.object({ tool: z.string(), cache_key: z.string(), saved_at: z.string(), bytes: z.number().int().nonnegative(), root: z.enum(["current", "legacy"]) })), skipped_count: z.number().int().nonnegative(), skipped: z.array(z.object({ path: z.string(), reason: z.string() })), message: z.string() }); - src/server.ts:487-495 (registration)Registration of the tool on the MCP server with name 'jp_lit_prune_cache', description, and schema references.
server.registerTool( "jp_lit_prune_cache", { description: "古いローカルキャッシュ候補を列挙し、dry_run=false のときだけ安全に削除する", inputSchema: pruneCacheInputSchema, outputSchema: pruneCacheOutputSchema }, pruneCacheTool );