Module: RubyLLM::MCP::Handlers::Concerns::Lifecycle

Included in:
ElicitationHandler, HumanInTheLoopHandler, SamplingHandler
Defined in:
lib/ruby_llm/mcp/handlers/concerns/lifecycle.rb

Overview

Provides lifecycle hook management (before_execute, after_execute) and orchestrates the execution flow

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
# File 'lib/ruby_llm/mcp/handlers/concerns/lifecycle.rb', line 10

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#callObject

Main entry point - orchestrates hooks and execution

Returns:

  • (Object)

    result from execute method



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ruby_llm/mcp/handlers/concerns/lifecycle.rb', line 49

def call
  # Execute before hooks
  execute_hooks(self.class.before_hooks)

  # Execute main logic
  result = execute

  # Execute after hooks
  execute_hooks(self.class.after_hooks, result)

  result
end

#executeObject

Abstract method - must be implemented by subclasses

Returns:

  • (Object)

    handler-specific result

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/ruby_llm/mcp/handlers/concerns/lifecycle.rb', line 64

def execute
  raise NotImplementedError, "#{self.class.name} must implement #execute"
end