Class: Llmemory::MCP::Tools::MemorySearch

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/llmemory/mcp/tools/memory_search.rb

Class Method Summary collapse

Class Method Details

.call(query:, user_id:, search_type: "all", max_results: 10, server_context: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/llmemory/mcp/tools/memory_search.rb', line 24

def call(query:, user_id:, search_type: "all", max_results: 10, server_context: nil)
  results = []
  search_type = (search_type || "all").downcase
  max_results = max_results || 10

  if search_type == "all" || search_type == "short_term"
    results.concat(search_short_term(user_id, query, max_results))
  end

  if search_type == "all" || search_type == "long_term"
    results.concat(search_long_term(user_id, query, max_results))
  end

  ::MCP::Tool::Response.new([{
    type: "text",
    text: format_results(results.first(max_results))
  }])
rescue => e
  ::MCP::Tool::Response.new([{
    type: "text",
    text: "Error searching memory: #{e.message}"
  }], error: true)
end