Class: Riffer::Mcp::SearchTool

Inherits:
Tool
  • Object
show all
Defined in:
lib/riffer/mcp/search_tool.rb,
sig/generated/riffer/mcp/search_tool.rbs

Overview

Searches available MCP tools by name or description.

Defined Under Namespace

Classes: Result

Constant Summary collapse

IDENTIFIER =

Returns:

  • (::String)
"mcp_search"

Constants included from Tools::Toolable

Tools::Toolable::DEFAULT_TIMEOUT

Instance Method Summary collapse

Methods inherited from Tool

#call_with_validation, #error, #json, #text

Methods included from Tools::Toolable

all, #description, extended, #identifier, #kind, #name, #parameters_schema, #params, #timeout, #to_tool_schema, #validate_as_tool!

Instance Method Details

#call(context:, query:) ⇒ Riffer::Tools::Response

Searches progressive MCP tools and returns a Result with discovered_tools.

: (context: Riffer::Agent::Context?, query: String) -> Riffer::Tools::Response

Parameters:

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/riffer/mcp/search_tool.rb', line 31

def call(context:, query:)
  return error("Provide a search query to find MCP tools by name or description.") if query.strip.empty?

  tools = context&.mcp_progressive_tools || []
  matches = filter(tools, query)

  return text("No tools found matching '#{query}'.") if matches.empty?

  names = matches.map(&:name).join(", ")
  Result.new(
    "Found #{matches.length} tool(s): #{names}. They are now available — call them directly.",
    matches
  )
end

#filter(tools, query) ⇒ Array[singleton(Riffer::Tool)]

: (Array, String) -> Array

Parameters:

Returns:



49
50
51
52
# File 'lib/riffer/mcp/search_tool.rb', line 49

def filter(tools, query)
  q = query.downcase
  tools.select { |t| t.name.downcase.include?(q) || t.description.to_s.downcase.include?(q) }
end