Skip to main content
Glama

search_memory

Search memories with full-text search, returning ranked results boosted by importance. Use at session start to load relevant context.

Instructions

Search memories using full-text search. Returns ranked results with higher-importance memories boosted. Use at session start to load relevant context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (keywords or phrases)
categoryNoFilter by category
projectNoFilter by project
limitNoMaximum results to return

Implementation Reference

  • The MCP tool handler that registers and implements the 'search_memory' tool. Accepts query, optional category, project, and limit; delegates to storage.search() and returns JSON results.
    export function registerSearchMemory(
      server: McpServer,
      storage: RekindleStorage
    ): void {
      server.tool(
        "search_memory",
        "Search memories using full-text search. Returns ranked results with higher-importance memories boosted. Use at session start to load relevant context.",
        {
          query: z.string().describe("Search query (keywords or phrases)"),
          category: z
            .enum(["preference", "lesson", "context", "relationship", "general"])
            .optional()
            .describe("Filter by category"),
          project: z.string().optional().describe("Filter by project"),
          limit: z
            .number()
            .min(1)
            .max(100)
            .default(10)
            .describe("Maximum results to return"),
        },
        async ({ query, category, project, limit }) => {
          const results = storage.search(query, { category, project, limit });
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  count: results.length,
                  results: results.map((r) => ({
                    id: r.id,
                    content: r.content,
                    category: r.category,
                    importance: r.importance,
                    project: r.project,
                    created_at: r.created_at,
                    retrieval_count: r.retrieval_count,
                  })),
                }),
              },
            ],
          };
        }
      );
    }
  • The storage.search() method performs FTS5 full-text search with BM25 ranking, boosted by importance. Filters by category/project, updates retrieval_count and last_accessed, and returns SearchResult objects.
    search(
      query: string,
      opts: { category?: string; project?: string; limit?: number } = {}
    ): SearchResult[] {
      const limit = opts.limit ?? 10;
    
      let sql = `
        SELECT m.*, bm25(memories_fts) AS fts_rank
        FROM memories_fts fts
        JOIN memories m ON m.rowid = fts.rowid
        WHERE memories_fts MATCH ?
      `;
      const ftsQuery = query
        .split(/\s+/)
        .filter((w) => w.length > 0)
        .map((w) => `"${w.replace(/"/g, '""')}"`)
        .join(" OR ");
      const params: (string | number)[] = [ftsQuery];
    
      if (opts.category) {
        sql += ` AND m.category = ?`;
        params.push(opts.category);
      }
      if (opts.project) {
        sql += ` AND m.project = ?`;
        params.push(opts.project);
      }
    
      sql += ` ORDER BY (fts_rank * (m.importance / 10.0)) LIMIT ?`;
      params.push(limit);
    
      const rows = this.db.prepare(sql).all(...params) as (Memory & { fts_rank: number })[];
    
      const now = new Date().toISOString().replace("T", " ").slice(0, 19);
      const updateAccess = this.db.prepare(`
        UPDATE memories SET retrieval_count = retrieval_count + 1, last_accessed = ? WHERE id = ?
      `);
      const updateMany = this.db.transaction((ids: string[]) => {
        for (const id of ids) {
          updateAccess.run(now, id);
        }
      });
      updateMany(rows.map((r) => r.id));
    
      return rows.map((row) => ({
        id: row.id,
        content: row.content,
        category: row.category,
        importance: row.importance,
        project: row.project,
        type: row.type,
        source: row.source,
        session_id: row.session_id,
        created_at: row.created_at,
        updated_at: row.updated_at,
        retrieval_count: row.retrieval_count + 1,
        last_accessed: now,
        rank: row.fts_rank,
      }));
    }
  • SearchResult interface extending Memory with a rank field for FTS ranking.
    export interface SearchResult extends Memory {
      rank: number;
    }
  • src/server.ts:5-5 (registration)
    The 'search_memory' tool is registered in createServer() by importing and calling registerSearchMemory(server, storage).
    import { registerSearchMemory } from "./tools/search.js";
Behavior3/5

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

With no annotations provided, the description carries full burden. It reveals that results are ranked by importance boost and full-text search is used, which is helpful. However, it does not explicitly state whether the tool is read-only, has any side effects, or disclose pagination behavior.

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?

Two sentences with no fluff. The first sentence states the core function, the second adds a usage recommendation. Every word is necessary and nothing is repeated from schema.

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

Completeness3/5

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

Given no output schema and no annotations, the description should explain the return format and potential limitations. It mentions ranked results but does not describe what fields are returned (e.g., id, content, importance). Also, it does not clarify if results are truncated or paginated, though limit parameter implies pagination handling.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. The description adds value by explaining the search algorithm (full-text, ranked, importance-boosted), which clarifies how the query parameter is interpreted and why results are ordered. This goes beyond the schema's basic parameter descriptions.

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?

Description clearly states the tool performs full-text search on memories, returning ranked results with boosted importance. This distinguishes it from sibling tools like list_memories (listing) and store_memory (writing). The verb 'Search' and resource 'memories' are specific and unambiguous.

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?

Explicitly recommends usage 'at session start to load relevant context', providing a clear scenario. However, it does not explicitly state when not to use it or mention alternatives like list_memories for browsing all memories.

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/Skitchy/rekindle'

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