Class: RosettAi::Mcp::Tools::ContextQueryTool

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

Overview

MCP tool: query applicable rules for a given context.

Answers "What rules apply to this situation?" by matching rules against a file path, tool name, or action. Returns applicable rules ranked by priority. Read-only operation.

Author:

  • hugo

  • claude

Constant Summary collapse

TOOL_NAME =
'rai_context_query'
DESCRIPTION =
'Query applicable rules for a file path, tool name, or action'
ANNOTATIONS =
{
  'readOnlyHint' => true,
  'destructiveHint' => false,
  'idempotentHint' => true,
  'openWorldHint' => false
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(file_path: nil, tool_name: nil, action: nil) ⇒ Hash

Queries rules applicable to the given context.

Parameters:

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

    file path context

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

    tool name context (e.g. 'Bash', 'Edit')

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

    action context (e.g. 'write', 'delete')

Returns:

  • (Hash)

    applicable rules with metadata



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

def call(file_path: nil, tool_name: nil, action: nil)
  query = build_query(file_path, tool_name, action)
  return ResponseHelper.error('At least one query parameter required') if query.empty?

  matches = search_rules(query)
  matches.sort_by! { |m| -(m[:priority] || 0) }

  {
    applicable_rules: matches,
    total: matches.size,
    query: query
  }
rescue StandardError => e
  ResponseHelper.error("Context query failed: #{e.message}")
end