Class: RosettAi::Mcp::Tools::RuleSearchTool

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/mcp/tools/rule_search_tool.rb

Overview

MCP tool: search compiled rules by keyword.

Searches behaviour YAML source files for rules matching a keyword, with optional filters for minimum priority, scope, and enabled status. Read-only operation.

Author:

  • hugo

  • claude

Constant Summary collapse

TOOL_NAME =
'rai_rule_search'
DESCRIPTION =
'Search rules by keyword with optional priority/scope/enabled filters'
ANNOTATIONS =
{
  'readOnlyHint' => true,
  'destructiveHint' => false,
  'idempotentHint' => true,
  'openWorldHint' => false
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(keyword:, priority_min: nil, scope: nil, enabled_only: true) ⇒ Hash

Searches rules across all behaviour files.

Parameters:

  • keyword (String)

    search term (matched case-insensitively)

  • priority_min (Integer, nil) (defaults to: nil)

    minimum priority filter

  • scope (String, nil) (defaults to: nil)

    scope filter ('global', 'project', 'personal')

  • enabled_only (Boolean) (defaults to: true)

    filter to enabled rules only (default true)

Returns:

  • (Hash)

    matching rules with metadata



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rosett_ai/mcp/tools/rule_search_tool.rb', line 38

def call(keyword:, priority_min: nil, scope: nil, enabled_only: true)
  matches = []
  each_behaviour_file do |path, data|
    search_behaviour(data, keyword, path, matches)
  end

  matches = apply_filters(matches, priority_min, scope, enabled_only)
  matches.sort_by! { |m| -(m[:priority] || 0) }

  { keyword: keyword, matches: matches, total: matches.size }
rescue StandardError => e
  ResponseHelper.error("Rule search failed: #{e.message}")
end