Skip to main content
Glama

jp_lit_list_cache

Retrieve and summarize cached search results from Japanese academic databases, with filtering by date and source.

Instructions

ローカルキャッシュの一覧・集計を返す。日付や source で絞り込み可能

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toolNo
session_idNo
saved_onNo
saved_fromNo
saved_toNo
sourceNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
toolYes
session_idYes
saved_onYes
saved_on_resolvedYes
saved_fromYes
saved_toYes
sourceYes
totalYes
limitYes
cache_keysYes
summaryYes
itemsYes

Implementation Reference

  • The main handler function `createJpLitListCacheTool` that implements the jp_lit_list_cache tool logic. It reads cached entries from disk, filters by session, date range, tool name, and source, then returns a summary listing with aggregation by tool and source.
    export function createJpLitListCacheTool(
      cache: FileCache,
      sessions: SessionStore,
      baseDir = process.cwd()
    ) {
      return async (input: unknown) => {
        const parsed = listCacheInputSchema.parse(input);
        const { effectiveSavedFrom, effectiveSavedTo, resolvedSavedOn } =
          resolveSavedDateFilter(parsed);
    
        const allSessions = parsed.session_id
          ? [await sessions.readById(parsed.session_id)]
          : await sessions.listAll();
        const cacheToSessionIds = new Map<string, Set<string>>();
        for (const session of allSessions) {
          for (const entry of session.entries) {
            const ids = cacheToSessionIds.get(entry.cache_key) ?? new Set<string>();
            ids.add(session.session_id);
            cacheToSessionIds.set(entry.cache_key, ids);
          }
        }
    
        const cacheRoots = [getCacheRoot(baseDir), getLegacyCacheRoot(baseDir)];
        const targetTools = parsed.tool
          ? [parsed.tool]
          : Array.from(
              new Set(
                (
                  await Promise.all(
                    cacheRoots.map((root) => readdir(root).catch(() => [] as string[]))
                  )
                ).flat()
              )
            );
    
        const summaries: CachedSummary[] = [];
        for (const tool of targetTools) {
          const cacheKeys = Array.from(
            new Set(
              (
                await Promise.all(
                  cacheRoots.map((root) =>
                    readdir(path.join(root, tool)).catch(() => [] as string[])
                  )
                )
              )
                .flat()
                .filter((filename) => filename.endsWith(".json"))
                .map((filename) => filename.replace(/\.json$/i, ""))
            )
          );
    
          for (const cacheKey of cacheKeys) {
            const cached = await cache.read<Record<string, unknown>>(tool, cacheKey);
            if (!cached) {
              continue;
            }
            if (effectiveSavedFrom && cached.saved_at < effectiveSavedFrom) {
              continue;
            }
            if (effectiveSavedTo && cached.saved_at > effectiveSavedTo) {
              continue;
            }
    
            const sessionIds = Array.from(cacheToSessionIds.get(cacheKey) ?? []);
            if (parsed.session_id && !sessionIds.includes(parsed.session_id)) {
              continue;
            }
    
            const content = cached.structured_content as Partial<SearchOutput>;
            const source = typeof content.source === "string" ? content.source : null;
            if (parsed.source && source !== parsed.source) {
              continue;
            }
    
            const query =
              typeof content.query === "string"
                ? content.query
                : typeof cached.input.query === "string"
                  ? cached.input.query
                  : null;
            const itemCount = Array.isArray(content.items) ? content.items.length : 0;
            const total = typeof content.total === "number" ? content.total : itemCount;
    
            summaries.push({
              tool,
              cache_key: cacheKey,
              saved_at: cached.saved_at,
              source,
              session_ids: sessionIds,
              query_preview: createPreview(query),
              total,
              item_count: itemCount
            });
          }
        }
    
        summaries.sort((left, right) => right.saved_at.localeCompare(left.saved_at));
        const limited = summaries.slice(0, parsed.limit);
        const byTool: Record<string, number> = {};
        const bySource: Record<string, number> = {};
        for (const entry of summaries) {
          byTool[entry.tool] = (byTool[entry.tool] ?? 0) + 1;
          const sourceKey = entry.source ?? "unknown";
          bySource[sourceKey] = (bySource[sourceKey] ?? 0) + 1;
        }
    
        const structuredContent: ListCacheOutput = listCacheOutputSchema.parse({
          tool: parsed.tool ?? null,
          session_id: parsed.session_id ?? null,
          saved_on: parsed.saved_on ?? null,
          saved_on_resolved: resolvedSavedOn,
          saved_from: parsed.saved_from ?? null,
          saved_to: parsed.saved_to ?? null,
          source: parsed.source ?? null,
          total: summaries.length,
          limit: parsed.limit,
          cache_keys: limited.map((item) => item.cache_key),
          summary: {
            by_tool: byTool,
            by_source: bySource,
            newest_saved_at: summaries[0]?.saved_at ?? null,
            oldest_saved_at: summaries.at(-1)?.saved_at ?? null
          },
          items: limited
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(structuredContent, null, 2)
            }
          ],
          structuredContent
        };
      };
    }
  • Input schema for jp_lit_list_cache: accepts optional tool, session_id, saved_on/saved_from/saved_to date filters, source, and limit (default 100, max 500).
    export const listCacheInputSchema = z.object({
      tool: z.string().trim().min(1).optional(),
      session_id: z.string().trim().regex(/^\d{4}-\d{2}-\d{2}-\d{6}$/).optional(),
      saved_on: z
        .string()
        .regex(/^(\d{4}-\d{2}-\d{2}|today|yesterday|last_7_days)$/)
        .optional(),
      saved_from: z.string().optional(),
      saved_to: z.string().optional(),
      source: sourceSchema.optional(),
      limit: z.number().int().positive().max(500).default(100)
    });
  • Output schema for jp_lit_list_cache: returns total count, limit, cache_keys array, summary (by_tool/by_source aggregates, newest/oldest dates), and items array with tool, cache_key, saved_at, source, session_ids, query_preview, total, item_count.
    export const listCacheOutputSchema = z.object({
      tool: z.string().nullable(),
      session_id: z.string().nullable(),
      saved_on: z.string().nullable(),
      saved_on_resolved: z.string().nullable(),
      saved_from: z.string().nullable(),
      saved_to: z.string().nullable(),
      source: sourceSchema.nullable(),
      total: z.number().int().nonnegative(),
      limit: z.number().int().positive(),
      cache_keys: z.array(z.string()),
      summary: z.object({
        by_tool: z.record(z.string(), z.number()),
        by_source: z.record(z.string(), z.number()),
        newest_saved_at: z.string().nullable(),
        oldest_saved_at: z.string().nullable()
      }),
      items: z.array(
        z.object({
          tool: z.string(),
          cache_key: z.string(),
          saved_at: z.string(),
          source: sourceSchema.nullable(),
          session_ids: z.array(z.string()),
          query_preview: z.string().nullable(),
          total: z.number().int().nonnegative(),
          item_count: z.number().int().nonnegative()
        })
      )
    });
  • src/server.ts:497-505 (registration)
    Tool registration: `server.registerTool("jp_lit_list_cache", ...)` with description 'ローカルキャッシュの一覧・集計を返す。日付や source で絞り込み可能'. Also at line 317 the handler is instantiated via `createJpLitListCacheTool(cache, sessions)`.
    server.registerTool(
      "jp_lit_list_cache",
      {
        description: "ローカルキャッシュの一覧・集計を返す。日付や source で絞り込み可能",
        inputSchema: listCacheInputSchema,
        outputSchema: listCacheOutputSchema
      },
      listCacheTool
    );
  • Helper function `createPreview` that truncates long query strings to 120 characters for display in the cache listing.
    function createPreview(value: string | null | undefined, maxLength = 120) {
      if (!value) {
        return null;
      }
      const compact = value.replace(/\s+/g, " ").trim();
      return compact.length <= maxLength ? compact : `${compact.slice(0, maxLength - 1)}…`;
    }
Behavior2/5

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

No annotations provided, so description must carry burden. It mentions filtering capabilities but does not disclose read-only nature, pagination behavior, or side effects. The name implies safety but lacks explicit disclosure.

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

Conciseness3/5

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

Two short sentences, very concise and front-loaded. However, for a 7-parameter tool, it is too brief and lacks structure, making it under-specified rather than efficient.

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?

The description is insufficient for a 7-parameter tool with an output schema. Missing details on required parameters, aggregation meaning, and parameter relationships. The output schema existence does not compensate for lack of parameter documentation.

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

Parameters2/5

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

Schema description coverage is 0%, but description only mentions filtering by 'date' and 'source' generically. It does not explain individual parameters like 'tool', 'session_id', 'saved_on', etc., or the meaning of 'aggregation'.

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

Purpose5/5

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

The description clearly states it returns a list/aggregation of 'local cache' with filtering by date and source. The verb '返す' and resource 'ローカルキャッシュ' are explicit, and it distinguishes from sibling tools like 'delete_cache' and 'prune_cache'.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives. No mention of when not to use, prerequisites, or typical scenarios.

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