Class: StatusMcp::Server::SearchServicesTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/status_mcp/server.rb

Instance Method Summary collapse

Instance Method Details

#call(query:) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/status_mcp/server.rb', line 134

def call(query:)
  services = load_data
  fuzzy_results = find_services_fuzzy(services, query, threshold: 0.5)

  if fuzzy_results.empty?
    "No services found matching '#{query}'"
  else
    # Deduplicate by service name (case-insensitive)
    seen = {}
    unique_results = fuzzy_results.select do |r|
      name_key = r[:service]["name"]&.downcase
      if seen[name_key]
        false
      else
        seen[name_key] = true
        true
      end
    end

    # Limit to top 20 results
    unique_results.first(20).map { |r| format_service(r[:service]) }.join("\n\n")
  end
end