Skip to main content
Glama

jp_lit_prune_cache

Identifies outdated local cache entries and removes them when dry-run is disabled.

Instructions

古いローカルキャッシュ候補を列挙し、dry_run=false のときだけ安全に削除する

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
older_than_daysNo
toolNo
dry_runNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dry_runYes
older_than_daysYes
cutoff_saved_atYes
toolYes
limitYes
matched_countYes
pruned_countYes
total_bytesYes
candidatesYes
skipped_countYes
skippedYes
messageYes

Implementation Reference

  • The main handler function `createJpLitPruneCacheTool` that implements the prune cache logic: parses input, computes cutoff date, lists cache inventory, filters candidates older than cutoff, optionally removes them (unless dry_run), and returns structured output with counts, bytes, and skipped files.
    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
        };
      };
    }
  • Helper function `listCacheInventory` that collects cache files from both 'current' and 'legacy' cache roots, and `removeInventoryItem` that safely deletes a cache file with a path traversal check.
    export async function listCacheInventory(baseDir = process.cwd(), tool?: string) {
      const current = await collectRoot(getCacheRoot(baseDir), "current", tool);
      const legacy = await collectRoot(getLegacyCacheRoot(baseDir), "legacy", tool);
      return {
        items: [...current.items, ...legacy.items],
        skipped: [...current.skipped, ...legacy.skipped]
      };
    }
    
    function isPathInside(parent: string, target: string) {
      const relative = path.relative(path.resolve(parent), path.resolve(target));
      return relative.length > 0 && !relative.startsWith("..") && !path.isAbsolute(relative);
    }
    
    export async function removeInventoryItem(
      item: CacheInventoryItem,
      baseDir = process.cwd()
    ) {
      const rootPath =
        item.root === "current" ? getCacheRoot(baseDir) : getLegacyCacheRoot(baseDir);
      if (!isPathInside(rootPath, item.path)) {
        throw new Error(`Refusing to remove cache file outside cache root: ${item.path}`);
      }
      await rm(item.path, { force: false });
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden for behavioral disclosure. It discloses the core safety behavior (dry_run controls deletion). However, it does not describe what the returned output contains (though an output schema exists), any locking or side effects on the cache, or whether the operation is reversible. The description is partially transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that front-loads the primary action (enumerate candidates) and the key condition (delete only when dry_run=false). It is appropriately sized for the tool's simplicity, with no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 4 parameters, an output schema, and siblings with overlapping functionality, the description is incomplete. It does not explain the role of the 'tool' parameter, how 'older_than_days' interacts with the cache age, or when to prefer this over jp_lit_delete_cache or jp_lit_list_cache. The presence of an output schema partially mitigates the need to describe return values, but usage context remains under-specified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning the input schema provides no parameter descriptions. The tool description does not mention or explain any of the four parameters (older_than_days, tool, dry_run, limit). This is a critical gap; the description must compensate for the missing schema descriptions but fails to do so.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool enumerates old cache candidates and deletes only when dry_run is false. It uses a specific verb 'prune' and resource 'local cache', distinguishing it from siblings like list_cache (which only lists) and delete_cache (which might delete specific entries). However, it does not explicitly name sibling alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying the dry_run safety mechanism (only deletes when dry_run=false). It gives a clear condition for actual deletion. However, it does not provide explicit guidance on when to use this tool vs alternatives like jp_lit_delete_cache or jp_lit_list_cache, nor any prerequisites or side effects.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/itarunnn/jp-lit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server