Class: RailsActiveMcp::Sdk::Tools::DryRunTool

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/rails_active_mcp/sdk/tools/dry_run_tool.rb

Class Method Summary collapse

Class Method Details

.call(code:, server_context:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rails_active_mcp/sdk/tools/dry_run_tool.rb', line 29

def self.call(code:, server_context:)
  config = RailsActiveMcp.config

  # Create safety checker

  executor = RailsActiveMcp::ConsoleExecutor.new(config)
  analysis = executor.dry_run(code)

  output = []
  output << "Code: #{analysis[:code]}"
  output << "Safe: #{analysis[:safety_analysis][:safe] ? 'Yes' : 'No'}"
  output << "Read-only: #{analysis[:safety_analysis][:read_only] ? 'Yes' : 'No'}"
  output << "Risk level: #{analysis[:estimated_risk]}"
  output << "Summary: #{analysis[:safety_analysis][:summary]}"

  if analysis[:safety_analysis][:violations].any?
    output << "\nViolations:"
    analysis[:safety_analysis][:violations].each do |violation|
      output << "  - #{violation[:description]} (#{violation[:severity]})"
    end
  end

  if analysis[:recommendations].any?
    output << "\nRecommendations:"
    analysis[:recommendations].each do |rec|
      output << "  - #{rec}"
    end
  end

  MCP::Tool::Response.new([
                            { type: 'text', text: output.join("\n") }
                          ])
end

.error_response(message) ⇒ Object



63
64
65
66
67
68
# File 'lib/rails_active_mcp/sdk/tools/dry_run_tool.rb', line 63

def self.error_response(message)
  MCP::Tool::Response.new(
    [{ type: 'text', text: message }],
    error: true
  )
end