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 =

Returns MCP tool identifier string.

Returns:

  • (String)

    MCP tool identifier string.

'rai_rule_search'
DESCRIPTION =

Returns Human-readable description of this tool.

Returns:

  • (String)

    Human-readable description of this tool.

'Search rules by keyword with optional priority/scope/enabled filters'
ANNOTATIONS =

Returns MCP protocol annotations describing tool capabilities.

Returns:

  • (Hash)

    MCP protocol annotations describing tool capabilities.

{
  'readOnlyHint' => true,
  'destructiveHint' => false,
  'idempotentHint' => true,
  'openWorldHint' => false
}.freeze
INPUT_SCHEMA =

Returns JSON Schema defining the tool input parameters.

Returns:

  • (Hash)

    JSON Schema defining the tool input parameters.

{
  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

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



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rosett_ai/mcp/tools/rule_search_tool.rb', line 67

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