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 collections that deduplicate sessions (e.g. prompt subscribers) treat every request view of one session as the same subscriber.
- #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 |
# 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 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 collections that deduplicate sessions (e.g. prompt subscribers) treat every request view of one session as the same subscriber.
96 97 98 99 |
# File 'lib/vector_mcp/invocation.rb', line 96 def ==(other) other_session = other.is_a?(Invocation) ? other.session : other @session == other_session end |
#hash ⇒ Object
102 103 104 |
# File 'lib/vector_mcp/invocation.rb', line 102 def hash @session.hash end |
#request_header(name) ⇒ String?
Returns the header value for this request.
83 84 85 |
# File 'lib/vector_mcp/invocation.rb', line 83 def request_header(name) @request_context.header(name) end |
#request_headers? ⇒ Boolean
Returns whether this request carried any headers.
72 73 74 |
# File 'lib/vector_mcp/invocation.rb', line 72 def request_headers? @request_context.headers? end |
#request_param(name) ⇒ String?
Returns the parameter value for this request.
89 90 91 |
# File 'lib/vector_mcp/invocation.rb', line 89 def request_param(name) @request_context.param(name) end |
#request_params? ⇒ Boolean
Returns whether this request carried any query parameters.
77 78 79 |
# File 'lib/vector_mcp/invocation.rb', line 77 def request_params? @request_context.params? end |
#update_request_context(**attributes) ⇒ RequestContext
Merge attributes into this request's context.
67 68 69 |
# File 'lib/vector_mcp/invocation.rb', line 67 def update_request_context(**attributes) @request_context = @request_context.merge(attributes) end |