Class: RosettAi::Mcp::Tools::RuleSearchTool
- Inherits:
-
Object
- Object
- RosettAi::Mcp::Tools::RuleSearchTool
- 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.
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
- INPUT_SCHEMA =
{ type: 'object', properties: { keyword: { type: 'string', description: 'Search keyword to match against rule descriptions and IDs' }, priority_min: { type: 'integer', minimum: 0, maximum: 100, description: 'Minimum priority threshold (0-100)' }, scope: { type: 'string', description: 'Behaviour scope to search within' }, enabled_only: { type: 'boolean', description: 'Only return enabled rules (default: true)' } }, required: ['keyword'] }.freeze
Instance Method Summary collapse
-
#call(keyword:, priority_min: nil, scope: nil, enabled_only: true) ⇒ Hash
Searches rules across all behaviour files.
Instance Method Details
#call(keyword:, priority_min: nil, scope: nil, enabled_only: true) ⇒ Hash
Searches rules across all behaviour files.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rosett_ai/mcp/tools/rule_search_tool.rb', line 63 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.}") end |