Class: VectorMCP::Middleware::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vector_mcp/middleware/base.rb

Overview

Base class for all middleware implementations Provides common functionality and hook method templates

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Base

Initialize middleware with optional configuration

Parameters:

  • config (Hash) (defaults to: {})

    Configuration options



10
11
12
13
# File 'lib/vector_mcp/middleware/base.rb', line 10

def initialize(config = {})
  @config = config
  @logger = VectorMCP.logger_for("middleware.#{self.class.name.split("::").last.downcase}")
end

Instance Method Details

#after_auth(context) ⇒ Object

Called after successful authentication

Parameters:



138
139
140
# File 'lib/vector_mcp/middleware/base.rb', line 138

def after_auth(context)
  # Override in subclasses
end

#after_prompt_get(context) ⇒ Object

Called after successful prompt get

Parameters:



78
79
80
# File 'lib/vector_mcp/middleware/base.rb', line 78

def after_prompt_get(context)
  # Override in subclasses
end

#after_resource_read(context) ⇒ Object

Called after successful resource read

Parameters:



58
59
60
# File 'lib/vector_mcp/middleware/base.rb', line 58

def after_resource_read(context)
  # Override in subclasses
end

#after_response(context) ⇒ Object

Called after successful response

Parameters:



118
119
120
# File 'lib/vector_mcp/middleware/base.rb', line 118

def after_response(context)
  # Override in subclasses
end

#after_sampling_response(context) ⇒ Object

Called after successful sampling response

Parameters:



98
99
100
# File 'lib/vector_mcp/middleware/base.rb', line 98

def after_sampling_response(context)
  # Override in subclasses
end

#after_tool_call(context) ⇒ Object

Called after successful tool execution

Parameters:



38
39
40
# File 'lib/vector_mcp/middleware/base.rb', line 38

def after_tool_call(context)
  # Override in subclasses
end

#before_auth(context) ⇒ Object

Called before authentication

Parameters:



132
133
134
# File 'lib/vector_mcp/middleware/base.rb', line 132

def before_auth(context)
  # Override in subclasses
end

#before_prompt_get(context) ⇒ Object

Called before prompt get

Parameters:



72
73
74
# File 'lib/vector_mcp/middleware/base.rb', line 72

def before_prompt_get(context)
  # Override in subclasses
end

#before_request(context) ⇒ Object

Called before any request processing

Parameters:



112
113
114
# File 'lib/vector_mcp/middleware/base.rb', line 112

def before_request(context)
  # Override in subclasses
end

#before_resource_read(context) ⇒ Object

Called before resource read

Parameters:



52
53
54
# File 'lib/vector_mcp/middleware/base.rb', line 52

def before_resource_read(context)
  # Override in subclasses
end

#before_sampling_request(context) ⇒ Object

Called before sampling request

Parameters:



92
93
94
# File 'lib/vector_mcp/middleware/base.rb', line 92

def before_sampling_request(context)
  # Override in subclasses
end

#before_tool_call(context) ⇒ Object

Called before tool execution

Parameters:



32
33
34
# File 'lib/vector_mcp/middleware/base.rb', line 32

def before_tool_call(context)
  # Override in subclasses
end

#call(hook_type, context) ⇒ Object

Generic hook dispatcher - override specific hook methods instead

Parameters:



18
19
20
21
22
23
24
25
26
# File 'lib/vector_mcp/middleware/base.rb', line 18

def call(hook_type, context)
  @logger.debug("Executing middleware hook") do
    {
      middleware: self.class.name,
      hook_type: hook_type,
      operation: context.operation_name
    }
  end
end

#on_auth_error(context) ⇒ Object

Called when authentication fails

Parameters:



144
145
146
# File 'lib/vector_mcp/middleware/base.rb', line 144

def on_auth_error(context)
  # Override in subclasses
end

#on_prompt_error(context) ⇒ Object

Called when prompt get fails

Parameters:



84
85
86
# File 'lib/vector_mcp/middleware/base.rb', line 84

def on_prompt_error(context)
  # Override in subclasses
end

#on_resource_error(context) ⇒ Object

Called when resource read fails

Parameters:



64
65
66
# File 'lib/vector_mcp/middleware/base.rb', line 64

def on_resource_error(context)
  # Override in subclasses
end

#on_sampling_error(context) ⇒ Object

Called when sampling fails

Parameters:



104
105
106
# File 'lib/vector_mcp/middleware/base.rb', line 104

def on_sampling_error(context)
  # Override in subclasses
end

#on_tool_error(context) ⇒ Object

Called when tool execution fails

Parameters:



44
45
46
# File 'lib/vector_mcp/middleware/base.rb', line 44

def on_tool_error(context)
  # Override in subclasses
end

#on_transport_error(context) ⇒ Object

Called when transport error occurs

Parameters:



124
125
126
# File 'lib/vector_mcp/middleware/base.rb', line 124

def on_transport_error(context)
  # Override in subclasses
end