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 =

Returns MCP tool identifier string.

Returns:

  • (String)

    MCP tool identifier string.

'rai_context_query'
DESCRIPTION =

Returns Human-readable description of this tool.

Returns:

  • (String)

    Human-readable description of this tool.

'Query applicable rules for a file path, tool name, or action'
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: {
    file_path: {
      type: 'string',
      description: 'File path to query applicable rules for'
    },
    tool_name: {
      type: 'string',
      description: 'Tool name to query applicable rules for'
    },
    action: {
      type: 'string',
      description: 'Action to query applicable rules for'
    }
  }
}.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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rosett_ai/mcp/tools/context_query_tool.rb', line 59

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