Skip to main content
Glama

search_memories

Search and retrieve stored memories using semantic understanding, filter by source type or bucket, and sort results by date or relevance for precise information retrieval.

Instructions

Search for memories using semantic search

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bucket_idNoFilter to specific bucket
date_sortNoSort semantic search results by date after similarity filtering (default: false)
debugNoInclude debug information in results (default: false)
include_reference_dataNoInclude reference data in response (default: false)
limitNoMaximum number of results to return (1-100, default: 10)
offsetNoNumber of results to skip for pagination (default: 0)
queryYesThe search query (semantic search)
sort_orderNoSort order when date_sort is enabled (default: 'desc')
source_typeNoFilter by source type

Implementation Reference

  • The main handler for the 'search_memories' tool. Parses input arguments, validates the query, calls the MemoryBoxClient.searchMemories method with options, formats the search results into a readable text response including similarity scores and optional debug info, and returns it.
    case "search_memories": {
      const query = String(request.params.arguments?.query || "");
      
      if (!query) {
        throw new McpError(ErrorCode.InvalidParams, "Query is required");
      }
    
      const options = {
        bucketId: request.params.arguments?.bucket_id ? String(request.params.arguments.bucket_id) : undefined,
        sourceType: request.params.arguments?.source_type ? String(request.params.arguments.source_type) : undefined,
        limit: request.params.arguments?.limit ? Number(request.params.arguments.limit) : undefined,
        offset: request.params.arguments?.offset ? Number(request.params.arguments.offset) : undefined,
        debug: Boolean(request.params.arguments?.debug || false),
        includeReferenceData: Boolean(request.params.arguments?.include_reference_data || false),
        dateSort: Boolean(request.params.arguments?.date_sort || false),
        sortOrder: request.params.arguments?.sort_order as 'asc' | 'desc' | undefined
      };
    
      // Search memories
      const result = await memoryBoxClient.searchMemories(query, options);
    
      // Format the results
      let responseText = `Search results for "${query}":\n\n`;
      
      if (result.items && result.items.length > 0) {
        result.items.forEach((memory: any, index: number) => {
          const similarity = memory.similarity ? ` (${Math.round(memory.similarity * 100)}% match)` : "";
          responseText += `${index + 1}. ${similarity} ${memory.text}\n\n`;
        });
      } else {
        responseText += "No memories found matching your query.";
      }
    
      // Add debug information if requested
      if (options.debug && result.debug) {
        responseText += "\n\nDebug Information:\n";
        responseText += `Query: ${result.debug.query}\n`;
        responseText += `Query Terms: ${result.debug.query_terms.join(", ")}\n`;
        responseText += `Threshold: ${result.debug.threshold}\n`;
        responseText += `All Results: ${result.debug.all_results.length}\n`;
      }
    
      return {
        content: [{
          type: "text",
          text: responseText
        }]
      };
    }
  • Input schema definition for the 'search_memories' tool, specifying parameters such as query (required), filters, pagination, and sorting options with types and descriptions.
    {
      name: "search_memories",
      description: "Search for memories using semantic search",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "The search query (semantic search)"
          },
          bucket_id: {
            type: "string",
            description: "Filter to specific bucket"
          },
          source_type: {
            type: "string",
            description: "Filter by source type"
          },
          limit: {
            type: "integer",
            description: "Maximum number of results to return (1-100, default: 10)",
            minimum: 1,
            maximum: 100
          },
          offset: {
            type: "integer",
            description: "Number of results to skip for pagination (default: 0)",
            minimum: 0
          },
          debug: {
            type: "boolean",
            description: "Include debug information in results (default: false)"
          },
          include_reference_data: {
            type: "boolean",
            description: "Include reference data in response (default: false)"
          },
          date_sort: {
            type: "boolean",
            description: "Sort semantic search results by date after similarity filtering (default: false)"
          },
          sort_order: {
            type: "string",
            description: "Sort order when date_sort is enabled (default: 'desc')",
            enum: ["asc", "desc"]
          }
        },
        required: ["query"]
      }
    },
  • MemoryBoxClient helper method that constructs query parameters from options and makes the HTTP GET request to the Memory Box API /api/v2/memory endpoint for semantic search, handling errors with McpError.
    async searchMemories(
      query: string,
      options?: {
        bucketId?: string;
        sourceType?: string;
        limit?: number;
        offset?: number;
        debug?: boolean;
        includeReferenceData?: boolean;
        dateSort?: boolean;
        sortOrder?: 'asc' | 'desc';
      }
    ): Promise<any> {
      try {
        const params: any = { query };
        
        if (options) {
          if (options.bucketId !== undefined) params.bucketId = options.bucketId;
          if (options.sourceType !== undefined) params.source_type = options.sourceType;
          if (options.limit !== undefined) params.limit = options.limit;
          if (options.offset !== undefined) params.offset = options.offset;
          if (options.debug !== undefined) params.debug = options.debug;
          if (options.includeReferenceData !== undefined) params.include_reference_data = options.includeReferenceData;
          if (options.dateSort !== undefined) params.date_sort = options.dateSort;
          if (options.sortOrder !== undefined) params.sort_order = options.sortOrder;
        }
    
        const response = await axios.get(
          `${this.baseUrl}/api/v2/memory`,
          {
            params,
            headers: {
              "Authorization": `Bearer ${this.token}`
            }
          }
        );
        return response.data;
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new McpError(
            ErrorCode.InternalError,
            `Failed to search memories: ${error.response?.data?.detail || error.message}`
          );
        }
        throw error;
      }
    }
  • src/index.ts:543-866 (registration)
    The ListToolsRequestHandler registers the 'search_memories' tool by including it in the returned tools list with its name, description, and inputSchema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "save_memory",
            description: "Save a memory to Memory Box",
            inputSchema: {
              type: "object",
              properties: {
                text: {
                  type: "string",
                  description: "The memory content to save (either text OR raw_content required)"
                },
                raw_content: {
                  type: "string",
                  description: "Raw content for processing (alternative to text)"
                },
                bucket_id: {
                  type: "string",
                  description: `The bucket to save the memory to (default: "${DEFAULT_BUCKET}")`
                },
                source_type: {
                  type: "string",
                  description: "Type of memory source (default: 'llm_plugin')"
                },
                reference_data: {
                  type: "object",
                  description: "Structured metadata for memory storage",
                  properties: {
                    source: {
                      type: "object",
                      required: ["platform"],
                      properties: {
                        platform: { type: "string", description: "Platform identifier (required)" },
                        type: { type: "string", description: "Source type" },
                        version: { type: "string", description: "Version info" },
                        url: { type: "string", description: "Source URL" },
                        title: { type: "string", description: "Source title" },
                        additional_metadata: { type: "object", description: "Extra metadata" }
                      }
                    },
                    context: {
                      type: "object",
                      properties: {
                        related_memories: { type: "array", items: { type: "object" }, description: "Related memory references" },
                        conversation_id: { type: "string", description: "Conversation identifier" },
                        message_id: { type: "string", description: "Message identifier" }
                      }
                    },
                    content_context: {
                      type: "object",
                      properties: {
                        url: { type: "string", description: "Content URL" },
                        title: { type: "string", description: "Content title" },
                        surrounding_text: { type: "string", description: "Context around selection" },
                        selected_text: { type: "string", description: "Selected text" },
                        additional_context: { type: "object", description: "Extra context" }
                      }
                    }
                  }
                }
              },
              required: ["text"]
            }
          },
          {
            name: "search_memories",
            description: "Search for memories using semantic search",
            inputSchema: {
              type: "object",
              properties: {
                query: {
                  type: "string",
                  description: "The search query (semantic search)"
                },
                bucket_id: {
                  type: "string",
                  description: "Filter to specific bucket"
                },
                source_type: {
                  type: "string",
                  description: "Filter by source type"
                },
                limit: {
                  type: "integer",
                  description: "Maximum number of results to return (1-100, default: 10)",
                  minimum: 1,
                  maximum: 100
                },
                offset: {
                  type: "integer",
                  description: "Number of results to skip for pagination (default: 0)",
                  minimum: 0
                },
                debug: {
                  type: "boolean",
                  description: "Include debug information in results (default: false)"
                },
                include_reference_data: {
                  type: "boolean",
                  description: "Include reference data in response (default: false)"
                },
                date_sort: {
                  type: "boolean",
                  description: "Sort semantic search results by date after similarity filtering (default: false)"
                },
                sort_order: {
                  type: "string",
                  description: "Sort order when date_sort is enabled (default: 'desc')",
                  enum: ["asc", "desc"]
                }
              },
              required: ["query"]
            }
          },
          {
            name: "get_all_memories",
            description: "Retrieve all memories with pagination support",
            inputSchema: {
              type: "object",
              properties: {
                all: {
                  type: "boolean",
                  description: "Get all memories (overrides pagination, default: false)"
                },
                bucket_id: {
                  type: "string",
                  description: "Filter to specific bucket"
                },
                source_type: {
                  type: "string",
                  description: "Filter by source type"
                },
                limit: {
                  type: "integer",
                  description: "Maximum number of results to return (1-100, default: 10)",
                  minimum: 1,
                  maximum: 100
                },
                offset: {
                  type: "integer",
                  description: "Number of results to skip for pagination (default: 0)",
                  minimum: 0
                },
                include_reference_data: {
                  type: "boolean",
                  description: "Include reference data in response (default: false)"
                },
                date_sort: {
                  type: "boolean",
                  description: "Sort results by date (default: false)"
                },
                sort_order: {
                  type: "string",
                  description: "Sort order (default: 'desc')",
                  enum: ["asc", "desc"]
                }
              }
            }
          },
          {
            name: "get_bucket_memories",
            description: "Get memories from a specific bucket",
            inputSchema: {
              type: "object",
              properties: {
                bucket_id: {
                  type: "string",
                  description: "The bucket to retrieve memories from"
                },
                limit: {
                  type: "integer",
                  description: "Maximum number of results to return (1-100, default: 10)",
                  minimum: 1,
                  maximum: 100
                },
                offset: {
                  type: "integer",
                  description: "Number of results to skip for pagination (default: 0)",
                  minimum: 0
                },
                include_reference_data: {
                  type: "boolean",
                  description: "Include reference data in response (default: false)"
                }
              },
              required: ["bucket_id"]
            }
          },
          {
            name: "get_related_memories",
            description: "Find semantically similar memories to a specific memory",
            inputSchema: {
              type: "object",
              properties: {
                memory_id: {
                  type: "integer",
                  description: "The ID of the memory to find related memories for"
                },
                min_similarity: {
                  type: "number",
                  description: "Minimum similarity threshold (0.0-1.0) for related memories (default: 0.7)"
                }
              },
              required: ["memory_id"]
            }
          },
          {
            name: "check_memory_status",
            description: "Check the processing status of a memory",
            inputSchema: {
              type: "object",
              properties: {
                memory_id: {
                  type: "integer",
                  description: "The ID of the memory to check status for"
                }
              },
              required: ["memory_id"]
            }
          },
          {
            name: "get_usage_stats",
            description: "Retrieve user usage statistics and plan information",
            inputSchema: {
              type: "object",
              properties: {
                // No specific parameters needed for this operation
              }
            }
          },
          {
            name: "get_buckets",
            description: "Retrieve a list of all available buckets",
            inputSchema: {
              type: "object",
              properties: {
                // No specific parameters needed for this operation
              }
            }
          },
          {
            name: "create_bucket",
            description: "Create a new bucket for organizing memories",
            inputSchema: {
              type: "object",
              properties: {
                bucket_name: {
                  type: "string",
                  description: "Name of the bucket to create"
                }
              },
              required: ["bucket_name"]
            }
          },
          {
            name: "delete_bucket",
            description: "Delete a bucket (empty by default, use force to delete with content)",
            inputSchema: {
              type: "object",
              properties: {
                bucket_name: {
                  type: "string",
                  description: "Name of the bucket to delete"
                },
                force: {
                  type: "boolean",
                  description: "Force deletion even if bucket contains memories (default: false)"
                }
              },
              required: ["bucket_name"]
            }
          },
          {
            name: "update_memory",
            description: "Update an existing memory including text, bucket, and relationships",
            inputSchema: {
              type: "object",
              properties: {
                memory_id: {
                  type: "integer",
                  description: "The ID of the memory to update"
                },
                text: {
                  type: "string",
                  description: "New text content for the memory"
                },
                raw_content: {
                  type: "string",
                  description: "New raw content for the memory"
                },
                bucket_id: {
                  type: "string",
                  description: "Move memory to different bucket"
                },
                source_type: {
                  type: "string",
                  description: "Update source type"
                },
                reference_data: {
                  type: "object",
                  description: "Updated reference data (same structure as save_memory)"
                }
              },
              required: ["memory_id"]
            }
          },
          {
            name: "delete_memory",
            description: "Delete a specific memory",
            inputSchema: {
              type: "object",
              properties: {
                memory_id: {
                  type: "integer",
                  description: "The ID of the memory to delete"
                }
              },
              required: ["memory_id"]
            }
          }
        ]
      };
    });
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral information. It mentions 'semantic search' which implies meaning-based rather than keyword-based matching, but doesn't disclose pagination behavior (implied by offset/limit), rate limits, authentication requirements, or what constitutes a 'memory' resource. The description adds some context about the search method but leaves critical behavioral traits unspecified.

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 a single, efficient sentence that states the core functionality without unnecessary words. It's appropriately sized for a search tool and front-loads the essential information. Every word earns its place in conveying the tool's purpose.

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 the complexity (9 parameters, semantic search functionality) and absence of both annotations and output schema, the description is minimally complete. It identifies the core operation but lacks context about what 'memories' are, how results are structured, or performance characteristics. The schema handles parameter documentation well, but the description doesn't compensate for missing behavioral and output context.

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 description coverage is 100%, so the schema already documents all 9 parameters thoroughly with descriptions, constraints, and defaults. The description adds no parameter-specific information beyond what's in the schema. The baseline score of 3 reflects adequate parameter documentation entirely through the schema, with no additional value from the description.

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 verb ('search') and resource ('memories') with the specific method 'semantic search'. It distinguishes from siblings like 'get_all_memories' (which presumably retrieves all without search) and 'get_related_memories' (which likely finds related items rather than semantic search). However, it doesn't explicitly differentiate from potential text-based search tools if they existed.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when semantic search is appropriate compared to other search methods, nor does it reference sibling tools like 'get_all_memories' or 'get_related_memories' for context. The agent must infer usage from the tool name alone.

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

Related 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/amotivv/memory-box-mcp'

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