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

Returns a new instance of Invocation.

Parameters:

  • session (VectorMCP::Session)

    the session the request arrived on

  • request_context (RequestContext, Hash, nil) (defaults to: nil)

    this request's context; defaults to the session's stored context when not provided



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

Returns this request's context (headers, params, ...).

Returns:



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

def request_context
  @request_context
end

#security_contextVectorMCP::Security::SessionContext

Returns the security context resolved for this request.

Returns:



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

def security_context
  @security_context
end

#sessionVectorMCP::Session (readonly)

Returns the underlying session this request belongs to.

Returns:



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.

Returns:

  • (Boolean)

    whether authentication has run for this invocation



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?

Returns the header value for this request.

Parameters:

  • name (String)

    the header name

Returns:

  • (String, nil)

    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.

Returns:

  • (Boolean)

    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.

Parameters:

  • name (String)

    the parameter name

Returns:

  • (String, nil)

    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.

Returns:

  • (Boolean)

    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.

Parameters:

  • attributes (Hash)

    attributes to merge

Returns:



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

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