Class: VectorMCP::Middleware::Context
- Inherits:
-
Object
- Object
- VectorMCP::Middleware::Context
- Defined in:
- lib/vector_mcp/middleware/context.rb
Overview
Context object passed to middleware hooks containing operation metadata Provides access to request data, session info, and mutable response data
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#operation_name ⇒ Object
readonly
Returns the value of attribute operation_name.
-
#operation_type ⇒ Object
readonly
Returns the value of attribute operation_type.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#result ⇒ Object
Returns the value of attribute result.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#skip_remaining_hooks ⇒ Object
Returns the value of attribute skip_remaining_hooks.
Instance Method Summary collapse
-
#add_metadata(key, value) ⇒ Object
Add custom metadata.
-
#error? ⇒ Boolean
Check if operation failed.
-
#initialize(options = {}) ⇒ Context
constructor
A new instance of Context.
-
#success? ⇒ Boolean
Check if operation completed successfully.
-
#timing ⇒ Hash
Get operation timing information.
-
#to_h ⇒ Hash
Get all available data as hash for logging/debugging.
-
#user ⇒ Hash?
Get user context from session if available.
Constructor Details
#initialize(options = {}) ⇒ Context
Returns a new instance of Context.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vector_mcp/middleware/context.rb', line 18 def initialize( = {}) @operation_type = [:operation_type] @operation_name = [:operation_name] @params = ([:params] || {}).dup.freeze # Immutable copy @session = [:session] @server = [:server] @metadata = ([:metadata] || {}).dup @result = nil @error = nil @skip_remaining_hooks = false end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/vector_mcp/middleware/context.rb', line 9 def error @error end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/vector_mcp/middleware/context.rb', line 8 def @metadata end |
#operation_name ⇒ Object (readonly)
Returns the value of attribute operation_name.
8 9 10 |
# File 'lib/vector_mcp/middleware/context.rb', line 8 def operation_name @operation_name end |
#operation_type ⇒ Object (readonly)
Returns the value of attribute operation_type.
8 9 10 |
# File 'lib/vector_mcp/middleware/context.rb', line 8 def operation_type @operation_type end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/vector_mcp/middleware/context.rb', line 8 def params @params end |
#result ⇒ Object
Returns the value of attribute result.
9 10 11 |
# File 'lib/vector_mcp/middleware/context.rb', line 9 def result @result end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
8 9 10 |
# File 'lib/vector_mcp/middleware/context.rb', line 8 def server @server end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
8 9 10 |
# File 'lib/vector_mcp/middleware/context.rb', line 8 def session @session end |
#skip_remaining_hooks ⇒ Object
Returns the value of attribute skip_remaining_hooks.
9 10 11 |
# File 'lib/vector_mcp/middleware/context.rb', line 9 def skip_remaining_hooks @skip_remaining_hooks end |
Instance Method Details
#add_metadata(key, value) ⇒ Object
Add custom metadata
57 58 59 |
# File 'lib/vector_mcp/middleware/context.rb', line 57 def (key, value) @metadata[key] = value end |
#error? ⇒ Boolean
Check if operation failed
38 39 40 |
# File 'lib/vector_mcp/middleware/context.rb', line 38 def error? !@error.nil? end |
#success? ⇒ Boolean
Check if operation completed successfully
32 33 34 |
# File 'lib/vector_mcp/middleware/context.rb', line 32 def success? @error.nil? end |
#timing ⇒ Hash
Get operation timing information
50 51 52 |
# File 'lib/vector_mcp/middleware/context.rb', line 50 def timing @metadata[:timing] || {} end |
#to_h ⇒ Hash
Get all available data as hash for logging/debugging
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vector_mcp/middleware/context.rb', line 63 def to_h { operation_type: @operation_type, operation_name: @operation_name, params: @params, session_id: @session&.id, metadata: @metadata, success: success?, error: @error&.class&.name } end |
#user ⇒ Hash?
Get user context from session if available
44 45 46 |
# File 'lib/vector_mcp/middleware/context.rb', line 44 def user @session&.security_context&.user end |