Skip to main content
Glama

search

Search through past Claude Code conversations to find previous discussions, decisions, or information from prior interactions across projects.

Instructions

Search through past Claude Code conversations across all projects. Use when the user asks about previous discussions, past decisions, or anything from a prior conversation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
projectNo
branchNo
afterNo
beforeNo
limitNo

Implementation Reference

  • The handleSearch function performs the core search logic, including validating the query, checking the indexed session count, performing a hybrid (vector/FTS) search, and formatting the response.
    export async function handleSearch(
      db: Database.Database,
      params: SearchParams
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const startTime = Date.now();
    
      // 1. Validate query
      if (!params.query || params.query.trim().length === 0) {
        throw new Error("query parameter is required and must be non-empty");
      }
    
      // 2. Clamp limit
      const limit = Math.min(
        params.limit ?? CONFIG.searchDefaultLimit,
        CONFIG.searchMaxLimit
      );
    
      // 3. Check indexed session count
      const indexedCount = getIndexedSessionCount(db);
    
      if (indexedCount === 0) {
        // Count what's on disk
        const sessionsOnDisk = countSessionsOnDisk();
    
        if (sessionsOnDisk <= CONFIG.autoIndexThreshold) {
          // Auto-index then search — must wait for background completion
          await handleIndex(db, { mode: "incremental" });
          await waitForIndexComplete(30000);
          // Fall through — indexedCount will now be non-zero
        } else {
          // Too many sessions; require explicit index
          const response: SearchResponse = {
            status: "index_required",
            message: `No sessions have been indexed yet. Found ${sessionsOnDisk} sessions on disk. Run the index tool first.`,
            sessions_found: sessionsOnDisk,
          };
          return {
            content: [{ type: "text", text: JSON.stringify(response) }],
          };
        }
      }
    
      // 4. Embed the query with the required prefix
      const embedder = await getEmbedder();
      const embedding = await embedder.embed("query: " + params.query);
    
      // 5. Hybrid search (vector + FTS5/BM25 with RRF)
      const results = vectorSearch(db, {
        embedding,
        query: params.query,
        limit,
        projectName: params.project,
        branch: params.branch,
        after: params.after,
        before: params.before,
      });
    
      // 6. Format results
      const formatted = results.map(formatResult);
    
      // 7. Check for stale sessions
      const currentIndexedCount = getIndexedSessionCount(db);
      const sessionsOnDiskNow = countSessionsOnDisk();
      const unindexedCount = sessionsOnDiskNow - currentIndexedCount;
    
      let note: string | undefined;
      if (unindexedCount > 0) {
        note = `${unindexedCount} session(s) on disk are not yet indexed. Run the index tool to include them in searches.`;
      }
    
      const queryTimeMs = Date.now() - startTime;
    
      const response: SearchResponse = {
        status: "ok",
        query: params.query,
        query_time_ms: queryTimeMs,
        total_indexed_sessions: currentIndexedCount,
        result_count: formatted.length,
        results: formatted,
        ...(note ? { note } : {}),
      };
    
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • src/server.ts:24-46 (registration)
    The "search" tool is registered here with the MCP server, defining the input schema using zod and calling the handleSearch handler.
    // search tool
    server.tool(
      "search",
      "Search through past Claude Code conversations across all projects. Use when the user asks about previous discussions, past decisions, or anything from a prior conversation.",
      {
        query: z.string(),
        project: z.string().optional(),
        branch: z.string().optional(),
        after: z.string().optional(),
        before: z.string().optional(),
        limit: z.number().optional(),
      },
      async (args): Promise<ToolResult> => {
        return handleSearch(db, {
          query: args.query,
          project: args.project,
          branch: args.branch,
          after: args.after,
          before: args.before,
          limit: args.limit,
        });
      }
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While it mentions the scope (across all projects), it doesn't describe what the search returns (snippets, full conversations, metadata), whether there are rate limits, authentication requirements, or how results are ordered/paginated. For a search tool with 6 parameters, this leaves significant behavioral gaps.

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

Conciseness5/5

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

The description is perfectly concise with two sentences that each earn their place. The first states what the tool does, and the second provides usage guidance. There's zero wasted text or redundancy.

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 complexity (search tool with 6 parameters), no annotations, and no output schema, the description is incomplete. It doesn't explain what the search returns, how results are structured, or provide any parameter guidance. For a tool that presumably returns search results, the lack of output information is a significant gap.

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%, so the schema provides no parameter documentation. The description mentions none of the 6 parameters, not even the required 'query' parameter. While the usage context implies a search query, it doesn't explain what format the query should take, what the project/branch parameters filter, or what the date/time parameters expect.

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 searches through past Claude Code conversations across all projects, which is a specific verb+resource combination. However, it doesn't explicitly distinguish this search tool from potential sibling tools like 'get_context' or 'list_sessions' that might also retrieve conversation data.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: 'when the user asks about previous discussions, past decisions, or anything from a prior conversation.' This gives good guidance but doesn't explicitly state when NOT to use it or mention alternatives among the sibling tools.

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/hyunjae-labs/lore'

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