Class: VectorMCP::Invocation
- Inherits:
-
Object
- Object
- VectorMCP::Invocation
- 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
-
#request_context ⇒ VectorMCP::RequestContext
This request's context (headers, params, ...).
-
#security_context ⇒ VectorMCP::Security::SessionContext
The security context resolved for this request.
-
#session ⇒ VectorMCP::Session
readonly
The underlying session this request belongs to.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Invocations compare by their underlying session so request-scoped views retain the identity semantics of that shared session.
-
#authentication_resolved? ⇒ Boolean
Whether authentication has run for this invocation.
- #hash ⇒ Object
-
#initialize(session, request_context: nil) ⇒ Invocation
constructor
A new instance of Invocation.
-
#request_header(name) ⇒ String?
The header value for this request.
-
#request_headers? ⇒ Boolean
Whether this request carried any headers.
-
#request_param(name) ⇒ String?
The parameter value for this request.
-
#request_params? ⇒ Boolean
Whether this request carried any query parameters.
-
#update_request_context(**attributes) ⇒ RequestContext
Merge attributes into this request's context.
Constructor Details
#initialize(session, request_context: nil) ⇒ Invocation
Returns a new instance of 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_context ⇒ VectorMCP::RequestContext
Returns this request's context (headers, params, ...).
29 30 31 |
# File 'lib/vector_mcp/invocation.rb', line 29 def request_context @request_context end |
#security_context ⇒ VectorMCP::Security::SessionContext
Returns the security context resolved for this request.
32 33 34 |
# File 'lib/vector_mcp/invocation.rb', line 32 def security_context @security_context end |
#session ⇒ VectorMCP::Session (readonly)
Returns the underlying session this request belongs to.
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
Returns whether authentication has run for this invocation.
67 68 69 |
# File 'lib/vector_mcp/invocation.rb', line 67 def authentication_resolved? @authentication_resolved end |
#hash ⇒ Object
114 115 116 |
# File 'lib/vector_mcp/invocation.rb', line 114 def hash @session.hash end |
#request_header(name) ⇒ String?
Returns the header value for this request.
96 97 98 |
# File 'lib/vector_mcp/invocation.rb', line 96 def request_header(name) @request_context.header(name) end |
#request_headers? ⇒ Boolean
Returns whether this request carried any headers.
85 86 87 |
# File 'lib/vector_mcp/invocation.rb', line 85 def request_headers? @request_context.headers? end |
#request_param(name) ⇒ String?
Returns the parameter value for this request.
102 103 104 |
# File 'lib/vector_mcp/invocation.rb', line 102 def request_param(name) @request_context.param(name) end |
#request_params? ⇒ Boolean
Returns whether this request carried any query parameters.
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 |