Class: VectorMCP::Invocation

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vector_mcp/invocation.rb

Overview

A per-request view of a Session.

Carries the request-scoped state — the incoming request's RequestContext and the Security::SessionContext resolved for it — while delegating session-lived state (identity, initialization, user data, sampling) to the underlying session. Transports build one Invocation per incoming request and pass it through message dispatch, so concurrent requests on the same session each observe their own request data and authentication result.

The Invocation intentionally quacks like a Session: tool handlers and request/notification hooks receive it as their session argument and can keep using session.id, session.data, session.sample, session.request_header, and session.security_context unchanged.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, request_context: nil) ⇒ Invocation



52
53
54
55
56
57
# File 'lib/vector_mcp/invocation.rb', line 52

def initialize(session, request_context: nil)
  @session = session
  @request_context = request_context ? RequestContext.coerce(request_context) : session.request_context
  @security_context = Security::SessionContext.anonymous
  @authentication_resolved = false
end

Instance Attribute Details

#request_contextVectorMCP::RequestContext



29
30
31
# File 'lib/vector_mcp/invocation.rb', line 29

def request_context
  @request_context
end

#security_contextVectorMCP::Security::SessionContext



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

def security_context
  @security_context
end

#sessionVectorMCP::Session (readonly)



26
27
28
# File 'lib/vector_mcp/invocation.rb', line 26

def session
  @session
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Invocations compare by their underlying session so request-scoped views retain the identity semantics of that shared session.



108
109
110
111
# File 'lib/vector_mcp/invocation.rb', line 108

def ==(other)
  other_session = other.is_a?(Invocation) ? other.session : other
  @session == other_session
end

#authentication_resolved?Boolean



67
68
69
# File 'lib/vector_mcp/invocation.rb', line 67

def authentication_resolved?
  @authentication_resolved
end

#hashObject



114
115
116
# File 'lib/vector_mcp/invocation.rb', line 114

def hash
  @session.hash
end

#request_header(name) ⇒ String?



96
97
98
# File 'lib/vector_mcp/invocation.rb', line 96

def request_header(name)
  @request_context.header(name)
end

#request_headers?Boolean



85
86
87
# File 'lib/vector_mcp/invocation.rb', line 85

def request_headers?
  @request_context.headers?
end

#request_param(name) ⇒ String?



102
103
104
# File 'lib/vector_mcp/invocation.rb', line 102

def request_param(name)
  @request_context.param(name)
end

#request_params?Boolean



90
91
92
# File 'lib/vector_mcp/invocation.rb', line 90

def request_params?
  @request_context.params?
end

#update_request_context(**attributes) ⇒ RequestContext

Merge attributes into this request's context.



80
81
82
# File 'lib/vector_mcp/invocation.rb', line 80

def update_request_context(**attributes)
  @request_context = @request_context.merge(attributes)
end