Class: Tools::FindProductsTool
- Inherits:
-
ApplicationTool
- Object
- MCP::Tool
- ApplicationTool
- Tools::FindProductsTool
- Defined in:
- app/mcp/tools/find_products_tool.rb
Overview
MCP Tool for finding products (items and product lines).
Returns items with SKUs, pricing context, and product line hierarchy.
Class Method Summary collapse
Class Method Details
.call(query:, limit: 5, server_context: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/mcp/tools/find_products_tool.rb', line 32 def call(query:, limit: 5, server_context: nil) limit = [[limit.to_i, 1].max, 20].min products = SemanticSearchService.find_products(query, limit: limit) items = products.select { |p| p.is_a?(Item) } product_lines = products.select { |p| p.is_a?(ProductLine) } all_pls = (items.filter_map(&:primary_product_line) + product_lines).uniq(&:id) if all_pls.any? paths = ProductLine.canonical_paths_for(all_pls) all_pls.each { |pl| pl.instance_variable_set(:@canonical_path, paths[pl.id]) } end json_response( query: query, total_results: products.size, products: products.map { |p| format_product(p) } ) end |