Class: Tools::SearchSupportNotesTool
- Inherits:
-
ApplicationTool
- Object
- MCP::Tool
- ApplicationTool
- Tools::SearchSupportNotesTool
- Defined in:
- app/mcp/tools/search_support_notes_tool.rb
Overview
MCP Tool for semantic search across support case activity notes and communications.
Uses pgvector embeddings to find notes/emails matching natural language queries,
filtered to those attached to SupportCase resources.
Activity notes contain technician observations, customer requests, troubleshooting
steps, and resolution details. Communications contain email threads with customers.
rubocop:disable Metrics/ClassLength -- MCP tool: schema + format paths are naturally verbose
Class Method Summary collapse
Class Method Details
.call(query:, source: nil, limit: 10, server_context: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/mcp/tools/search_support_notes_tool.rb', line 48 def call(query:, source: nil, limit: 10, server_context: nil) limit = [[limit.to_i, 1].max, 30].min types = resolve_types(source) return json_response(error: 'source must be omitted or one of: notes, activities, communications, emails') if types.nil? results = ContentEmbedding.hybrid_search( query, limit: limit * 2, # over-fetch to compensate for post-filtering types: types, exclude_sensitive: false ) # Post-filter to only results linked to a SupportCase support_results = results.select do |emb| record = emb. next false unless record record.respond_to?(:resource_type) && record.resource_type == 'SupportCase' end.first(limit) = support_results.filter_map(&:embeddable).compact ActiveRecord::Associations::Preloader.new(records: , associations: :resource).call if .any? support_cases = .filter_map(&:resource).grep(SupportCase).uniq if support_cases.any? ActiveRecord::Associations::Preloader.new( records: support_cases, associations: { support_case_participants: :party } ).call end json_response( query: query, source_filter: source, total_results: support_results.size, results: support_results.filter_map { |emb| format_result(emb) } ) end |