Class: RailsAiBridge::Tools::GetView

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/get_view.rb,
lib/rails_ai_bridge/tools/get_view/base_formatter.rb,
lib/rails_ai_bridge/tools/get_view/full_formatter.rb,
lib/rails_ai_bridge/tools/get_view/summary_formatter.rb,
lib/rails_ai_bridge/tools/get_view/standard_formatter.rb,
lib/rails_ai_bridge/tools/get_view/specific_view_formatter.rb

Overview

Exposes view-layer context through MCP with compact listings and file-focused inspection for editing workflows.

Defined Under Namespace

Classes: BaseFormatter, FullFormatter, SpecificViewFormatter, StandardFormatter, SummaryFormatter

Class Method Summary collapse

Methods inherited from BaseTool

cached_context, cached_section, config, rails_app, reset_cache!, text_response

Class Method Details

.call(path: nil, controller: nil, partial: nil, detail: 'standard', _server_context: nil) ⇒ MCP::Tool::Response

Returns summarized or file-focused view context.

Parameters:

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

    view path relative to app/views

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

    controller view folder filter

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

    partial name or path fragment filter

  • detail (String) (defaults to: 'standard')

    one of summary, standard, or full

  • _server_context (Object, nil) (defaults to: nil)

    MCP server context (unused)

Returns:

  • (MCP::Tool::Response)

    formatted view information



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rails_ai_bridge/tools/get_view.rb', line 44

def self.call(path: nil, controller: nil, partial: nil, detail: 'standard', _server_context: nil)
  data = cached_section(:views)
  return text_response('View introspection not available. Add :views to introspectors.') unless data
  return text_response("View introspection failed: #{data[:error]}") if data[:error]

  if path
    analysis = ViewFileAnalyzer.call(root: rails_app.root, relative_path: path)
    return text_response(SpecificViewFormatter.new.call(analysis))
  end

  formatter = build_formatter(detail, data, controller, partial)
  text_response(formatter.call)
rescue SecurityError => error
  text_response(error.message)
rescue Errno::ENOENT
  text_response("Path not found: #{path}")
end