Class: Rails::Hyperdrive::Tools::Base

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/rails/hyperdrive/tools/base.rb

Class Method Summary collapse

Class Method Details

.respond_error(message) ⇒ Object



17
18
19
20
21
22
# File 'lib/rails/hyperdrive/tools/base.rb', line 17

def respond_error(message)
  ::MCP::Tool::Response.new(
    [{ type: "text", text: message.to_s }],
    error: true
  )
end

.respond_json(object) ⇒ Object



13
14
15
# File 'lib/rails/hyperdrive/tools/base.rb', line 13

def respond_json(object)
  respond_text(JSON.pretty_generate(object))
end

.respond_text(text) ⇒ Object



9
10
11
# File 'lib/rails/hyperdrive/tools/base.rb', line 9

def respond_text(text)
  ::MCP::Tool::Response.new([{ type: "text", text: text.to_s }])
end

.with_dev_guardObject

Defense in depth: the Rack middleware already gates the HTTP transport; this catches direct in-process invocations (specs, rake tasks) that bypass it.



27
28
29
30
31
32
33
34
# File 'lib/rails/hyperdrive/tools/base.rb', line 27

def with_dev_guard
  unless Rails::Hyperdrive.dev_mode?
    return respond_error("hyperdrive tools are disabled outside Rails.env.development?")
  end
  yield
rescue => e
  respond_error("#{e.class}: #{e.message}")
end