Class: Plasma::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/plasma/application.rb

Overview

Base application class for PLASMA applications

Defined Under Namespace

Classes: Configuration

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



15
16
17
# File 'lib/plasma/application.rb', line 15

def config
  @config
end

.registryObject

Returns the value of attribute registry.



15
16
17
# File 'lib/plasma/application.rb', line 15

def registry
  @registry
end

.serverObject

Returns the value of attribute server.



15
16
17
# File 'lib/plasma/application.rb', line 15

def server
  @server
end

Class Method Details

.initialize! {|@config| ... } ⇒ Object

Initialize the application rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength

Yields:



19
20
21
22
23
24
25
26
27
28
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/plasma/application.rb', line 19

def initialize!
  # Set up configuration
  @config ||= Configuration.new
  yield @config if block_given?

  # Set default name based on module name if not explicitly set
  if @config.name.nil?
    module_name = to_s.split("::").first
    @config.name = "#{module_name} MCP Server"
  end

  # Set up autoloading
  module_name = module_parent.name
  loader = Zeitwerk::Loader.new
  loader.push_dir("./app", namespace: Object.const_get(module_name))
  loader.push_dir(File.expand_path("../plasma", __dir__), namespace: Plasma)
  loader.setup

  # Load prompts, resources, and tools
  load_all_components

  # Load the plasma auth server in case it is subclassed
  require "plasma/auth_server"

  # Create the server
  @server = ModelContextProtocol::Server.new do |config|
    config.name = @config.name || "PLASMA MCP Server"
    config.version = @config.version || "1.0.0"
    config.enable_log = @config.enable_log

    # Apply environment variables
    @config.required_env_vars.each do |var|
      config.require_environment_variable(var)
    end

    @config.env_vars.each do |key, value|
      config.set_environment_variable(key, value)
    end
  end

  # Set up the registry
  setup_registry
end

.load_all_componentsObject

Load all the application’s components



70
71
72
73
74
75
76
# File 'lib/plasma/application.rb', line 70

def load_all_components
  load_prompts
  load_resources
  load_tools
  load_variables
  load_records
end

.promptsObject

Find all prompt classes



79
80
81
# File 'lib/plasma/application.rb', line 79

def prompts
  descendants_of("Prompts")
end

.resourcesObject

Find all resource classes



84
85
86
# File 'lib/plasma/application.rb', line 84

def resources
  descendants_of("Resources")
end

.start_serverObject

Start the MCP server



65
66
67
# File 'lib/plasma/application.rb', line 65

def start_server
  @server.start
end

.toolsObject

Find all tool classes



89
90
91
# File 'lib/plasma/application.rb', line 89

def tools
  descendants_of("Tools")
end