Skip to main content
Glama

memory.search

Search your stored memories by metadata like tags, type, or importance. Returns lightweight results for quick browsing without loading full content.

Instructions

Search your memories by metadata. Returns lightweight results (no encrypted content) — use memory.recall with the IDs to get the full blobs. Useful for browsing what you've stored without loading everything.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_identifierYesYour agent identifier.
tagsNoFilter by tags (matches any).
memory_typeNoFilter by memory type.
min_importanceNoOnly return memories at or above this importance.
limitNoMax results. Default: 20.

Implementation Reference

  • The handleSearch function is the main handler for the memory.search tool. It validates agent_identifier, looks up the agent, and calls searchMemories to query the database, returning results without encrypted content.
    export async function handleSearch(args: Record<string, unknown>): Promise<ToolResult> {
      const agentIdentifier = (args.agent_identifier as string || "").trim();
      if (!agentIdentifier) return { error: "agent_identifier is required" };
    
      const agent = await getAgent(agentIdentifier);
      if (!agent) return { error: "Agent not registered. Call memory.register first." };
    
      await updateAgentSeen(agent.id);
    
      const results = await searchMemories(
        agent.id,
        args.tags as string[] | undefined,
        args.memory_type as string | undefined,
        args.min_importance as number | undefined,
        Math.min((args.limit as number) || 20, 100)
      );
    
      return {
        status: "found",
        results,
        count: results.length,
        note: "Results exclude encrypted content. Use memory.recall with IDs to get full memories.",
      };
    }
  • The searchMemories function executes the actual database query. It searches the am_memories table with optional filters (tags overlap, memory_type, min_importance), orders by importance then creation date, and limits results.
    export async function searchMemories(
      agentId: string,
      queryTags?: string[],
      memoryType?: string,
      minImportance?: number,
      limit: number = 20
    ): Promise<Partial<MemoryRecord>[]> {
      const client = getClient();
      let q = client
        .from("am_memories")
        .select(
          "id, agent_id, tags, importance, memory_type, created_at, accessed_at, size_bytes"
        )
        .eq("agent_id", agentId);
    
      if (queryTags && queryTags.length > 0) {
        q = q.overlaps("tags", queryTags);
      }
      if (memoryType) {
        q = q.eq("memory_type", memoryType);
      }
      if (minImportance != null) {
        q = q.gte("importance", minImportance);
      }
    
      const { data } = await q
        .order("importance", { ascending: false })
        .order("created_at", { ascending: false })
        .limit(limit);
    
      return (data || []) as Partial<MemoryRecord>[];
    }
  • The tool definition for memory.search, including its description and inputSchema with agent_identifier (required), tags, memory_type (enum), min_importance, and limit parameters.
    {
      name: "memory.search",
      description:
        "Search your memories by metadata. Returns lightweight results " +
        "(no encrypted content) — use memory.recall with the IDs to get " +
        "the full blobs. Useful for browsing what you've stored without " +
        "loading everything.",
      inputSchema: {
        type: "object",
        properties: {
          agent_identifier: {
            type: "string",
            description: "Your agent identifier.",
          },
          tags: {
            type: "array",
            items: { type: "string" },
            description: "Filter by tags (matches any).",
          },
          memory_type: {
            type: "string",
            enum: [
              "general",
              "decision",
              "preference",
              "fact",
              "skill",
              "relationship",
              "event",
            ],
            description: "Filter by memory type.",
          },
          min_importance: {
            type: "integer",
            minimum: 1,
            maximum: 10,
            description:
              "Only return memories at or above this importance.",
          },
          limit: {
            type: "integer",
            minimum: 1,
            maximum: 100,
            description: "Max results. Default: 20.",
          },
        },
  • src/server.ts:11-12 (registration)
    Import of handleSearch from tools/memory.ts into the server.
      handleSearch, handleExport, handleStats, handleAnnotate,
    } from "./tools/memory.js";
  • src/server.ts:57-63 (registration)
    The call_tool router case statement that dispatches 'memory.search' to the handleSearch function.
    switch (name) {
      // Memory
      case "memory.register": result = await handleRegister(safeArgs); break;
      case "memory.store": result = await handleStore(safeArgs); break;
      case "memory.recall": result = await handleRecall(safeArgs); break;
      case "memory.search": result = await handleSearch(safeArgs); break;
      case "memory.export": result = await handleExport(safeArgs); break;
Behavior4/5

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

Despite no annotations, description discloses that results are lightweight and exclude encrypted content. This helps set expectations about data sensitivity and size. Does not explicitly state read-only or cost implications, but search context implies safety.

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, no fluff. First sentence states core action, second sentence provides context and alternative tool reference. Front-loaded and efficient.

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

Completeness4/5

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

Covers purpose, return type, and relationship with sibling tool. Lacks mention of ordering or pagination details beyond the limit parameter, but for a metadata search tool, this is mostly sufficient.

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

Parameters3/5

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

Schema coverage is 100% with detailed parameter descriptions. The tool description adds no additional parameter context beyond what schema already provides. Adequate but not enhanced.

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 searches memories by metadata, returning lightweight results without encrypted content. It explicitly distinguishes from the sibling memory.recall, which returns full blobs.

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

Usage Guidelines5/5

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

Clearly instructs when to use this tool (browsing metadata) and when to use memory.recall (full content). Provides actionable guidance: 'Useful for browsing what you've stored without loading everything.'

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/MastadoonPrime/sylex-memory'

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