Class: TalkToYourApp::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/talk_to_your_app/railtie.rb

Overview

Wires the gem into the Rails boot sequence. The headline behavior is the fail-closed validation initializer: every required piece of configuration is checked once, at the end of boot, so misconfiguration surfaces at deploy time rather than on the first MCP request.

Class Method Summary collapse

Class Method Details

.validate_auth!Object

At least one auth mechanism must be configured once the endpoint serves tools. With no plugins enabled (the default) there is nothing to protect, so the gem still boots cleanly with no configuration at all.

Raises:



49
50
51
52
53
54
55
56
# File 'lib/talk_to_your_app/railtie.rb', line 49

def self.validate_auth!
  return if TalkToYourApp.configuration.enabled_plugins.empty?
  return if TalkToYourApp.configuration.auth_configured?

  raise ConfigurationError,
    "talk_to_your_app: no authentication configured. Set `config.api_keys` or `config.basic_auth` " \
    "in config/initializers/talk_to_your_app.rb (the MCP endpoint must not be exposed unauthenticated)."
end

.validate_boot!Object

Aggregated fail-closed validation. With nothing enabled (the default), validation is a no-op and the gem boots silently. With config.enabled false the gem serves nothing, so there is nothing to validate — boot silently. (Re-enabling means a reboot, where this runs again and fails closed on missing auth or connections.)



37
38
39
40
41
42
43
44
# File 'lib/talk_to_your_app/railtie.rb', line 37

def self.validate_boot!
  return unless TalkToYourApp.configuration.enabled

  TalkToYourApp::PluginRegistry.validate_enabled!
  TalkToYourApp::ConnectionRegistry.validate!(TalkToYourApp.required_connections)
  validate_auth!
  warn_missing_authorize!
end

.warn_missing_authorize!Object

Warn (do not fail) when plugins are enabled without config.authorize. Without an authorizer every authenticated principal may call every tool — easy to miss, and a leaked key then has the full blast radius of every enabled plugin.



62
63
64
65
66
67
68
69
70
71
# File 'lib/talk_to_your_app/railtie.rb', line 62

def self.warn_missing_authorize!
  return if TalkToYourApp.configuration.enabled_plugins.empty?
  return if TalkToYourApp.configuration.authorize_configured?

  message = "talk_to_your_app: no config.authorize configured — every authenticated " \
    "principal can call every enabled tool. Set `config.authorize` to scope access by " \
    "principal, tool, and arguments."
  logger = TalkToYourApp.configuration.logger
  logger ? logger.warn(message) : warn(message)
end