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:



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

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. Later units add auth and plugin checks.



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

def self.validate_boot!
  TalkToYourApp::PluginRegistry.validate_enabled!
  TalkToYourApp::ConnectionRegistry.validate!(TalkToYourApp.required_connections)
  validate_auth!
end