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
# 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_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 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

#hashObject



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.

Parameters:

  • name (String)

    the header name

Returns:

  • (String, nil)

    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.

Returns:

  • (Boolean)

    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.

Parameters:

  • name (String)

    the parameter name

Returns:

  • (String, nil)

    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.

Returns:

  • (Boolean)

    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.

Parameters:

  • attributes (Hash)

    attributes to merge

Returns:



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

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