Skip to main content
Glama

jp_lit_search_cache_index

Cross-search saved Japanese literature search caches and retrieve cache keys for re-extraction.

Instructions

保存済み jp_lit_search キャッシュを横断検索し、再抽出に使える cache_key 一覧を返す

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
session_idNo
sourceNo
issued_fromNo
issued_toNo
saved_onNo
saved_fromNo
saved_toNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
session_idYes
sourceYes
issued_fromYes
issued_toYes
saved_onYes
saved_on_resolvedYes
saved_fromYes
saved_toYes
totalYes
limitYes
cache_keysYes
itemsYes

Implementation Reference

  • Main handler function that iterates over all sessions to find jp_lit_search cache keys, scans cache directories, filters by date/query/source/issued range, matches against normalized query text, and returns matching cache entries.
    export function createJpLitSearchCacheIndexTool(
      cache: FileCache,
      sessions: SessionStore,
      baseDir = process.cwd()
    ) {
      return async (input: unknown) => {
        const parsed = searchCacheIndexInputSchema.parse(input);
        const normalizedQuery = normalizeText(parsed.query);
        const { effectiveSavedFrom, effectiveSavedTo, resolvedSavedOn } =
          resolveSavedDateFilter(parsed);
        const targetSessionIds = parsed.session_id ? new Set([parsed.session_id]) : null;
        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) {
            if (entry.tool !== "jp_lit_search") {
              continue;
            }
            const set = cacheToSessionIds.get(entry.cache_key) ?? new Set<string>();
            set.add(session.session_id);
            cacheToSessionIds.set(entry.cache_key, set);
          }
        }
    
        const searchCacheDirs = [
          path.join(getCacheRoot(baseDir), "jp_lit_search"),
          path.join(getLegacyCacheRoot(baseDir), "jp_lit_search")
        ];
        const cacheKeys = Array.from(
          new Set(
            (
              await Promise.all(
                searchCacheDirs.map(async (directory) => {
                  try {
                    return await readdir(directory);
                  } catch {
                    return [] as string[];
                  }
                })
              )
            )
              .flat()
              .filter((filename) => filename.endsWith(".json"))
              .map((filename) => filename.replace(/\.json$/i, ""))
          )
        );
    
        const results: SearchCacheIndexOutput["items"] = [];
        for (const cacheKey of cacheKeys) {
          if (!cacheToSessionIds.has(cacheKey)) {
            continue;
          }
          const cached = await cache.read<SearchOutput>("jp_lit_search", cacheKey);
          if (!cached) {
            continue;
          }
    
          const output = cached.structured_content;
          if (effectiveSavedFrom && cached.saved_at < effectiveSavedFrom) {
            continue;
          }
          if (effectiveSavedTo && cached.saved_at > effectiveSavedTo) {
            continue;
          }
          if (parsed.source && output.source !== parsed.source) {
            continue;
          }
    
          const items = output.items;
          if (parsed.issued_from || parsed.issued_to) {
            const hasInRange = items.some((item) => {
              if (!item.issued_at) {
                return false;
              }
              if (parsed.issued_from && item.issued_at < parsed.issued_from) {
                return false;
              }
              if (parsed.issued_to && item.issued_at > parsed.issued_to) {
                return false;
              }
              return true;
            });
            if (!hasInRange) {
              continue;
            }
          }
    
          const matchedFields = new Set<MatchedField>();
          if (typeof output.query === "string" && normalizeText(output.query).includes(normalizedQuery)) {
            matchedFields.add("query");
          }
          const itemMatched = matchItems(items, normalizedQuery);
          for (const field of itemMatched) {
            matchedFields.add(field);
          }
          if (matchedFields.size === 0) {
            continue;
          }
    
          const sessionIds = Array.from(cacheToSessionIds.get(cacheKey) ?? []).filter((sessionId) =>
            targetSessionIds ? targetSessionIds.has(sessionId) : true
          );
          if (sessionIds.length === 0) {
            continue;
          }
    
          results.push({
            cache_key: cacheKey,
            session_ids: sessionIds,
            saved_at: cached.saved_at,
            source: output.source,
            query_preview: createPreview(output.query),
            total: output.total,
            item_count: output.items.length,
            matched_fields: Array.from(matchedFields)
          });
        }
    
        results.sort((left, right) => right.saved_at.localeCompare(left.saved_at));
        const limited = results.slice(0, parsed.limit);
    
        const structuredContent: SearchCacheIndexOutput = searchCacheIndexOutputSchema.parse({
          query: parsed.query,
          session_id: parsed.session_id ?? null,
          source: parsed.source ?? null,
          issued_from: parsed.issued_from ?? null,
          issued_to: parsed.issued_to ?? null,
          saved_on: parsed.saved_on ?? null,
          saved_on_resolved: resolvedSavedOn,
          saved_from: parsed.saved_from ?? null,
          saved_to: parsed.saved_to ?? null,
          total: results.length,
          limit: parsed.limit,
          cache_keys: limited.map((item) => item.cache_key),
          items: limited
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(structuredContent, null, 2)
            }
          ],
          structuredContent
        };
      };
    }
  • Utility function normalizeText() used for NFKC normalization and case-insensitive matching in Japanese locale.
    function normalizeText(value: string) {
      return value
        .normalize("NFKC")
        .toLocaleLowerCase("ja-JP")
        .replace(/\s+/g, " ")
        .trim();
    }
Behavior1/5

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

No annotations are provided, and the description does not disclose any behavioral traits such as read-only nature, authentication requirements, or potential side effects. For a search/index tool, it is unclear if it modifies data or requires specific permissions.

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

Conciseness2/5

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

The description is too brief (one short sentence) and lacks essential details. It is under-specified rather than concise, compromising usefulness.

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

Completeness1/5

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

Given the complexity of 9 parameters, no output schema displayed, and no annotations, the description is severely incomplete. It does not explain output format, filtering behavior, or how returned cache keys can be used.

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%, so the description must compensate but provides no explanation of any of the 9 parameters. Parameter names give some hints (e.g., query, source, dates), but patterns like saved_on and session_id are not explained. No value beyond the schema itself.

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

Purpose3/5

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

Description states tool searches saved cache and returns cache_key list, which indicates its basic purpose. However, 'cross-search' is vague and does not clearly differentiate from sibling tools like jp_lit_list_cache or jp_lit_search. Sibling differentiation is lacking.

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

Usage Guidelines1/5

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

No guidance provided on when to use this tool versus alternatives such as jp_lit_search or jp_lit_list_cache. No context on prerequisites or intended use cases.

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