Class: Portage::Ucp::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/portage/ucp/dispatcher.rb

Overview

Accepts a UCP-shaped request (capability + action + arguments), routes it through the CapabilityRegistry to the backing Adapter method, and wraps the result as MCP's dual content/structuredContent output (see §5).

Instance Method Summary collapse

Constructor Details

#initialize(adapter:, registry: CapabilityRegistry.default, logger: Portage::Ucp.configuration.logger) ⇒ Dispatcher

Returns a new instance of Dispatcher.



7
8
9
10
11
# File 'lib/portage/ucp/dispatcher.rb', line 7

def initialize(adapter:, registry: CapabilityRegistry.default, logger: Portage::Ucp.configuration.logger)
  @adapter = adapter
  @registry = registry
  @logger = logger
end

Instance Method Details

#call(capability:, action:, arguments: {}, correlation_id: nil) ⇒ Object

Parameters:

  • correlation_id (String, nil) (defaults to: nil)

    threaded through to the adapter (via Support::CheckoutState.with_observability, scoped to this call only) so a checkout_state_transition event (§12) it emits during this call carries the same id as the tool_called event that triggered it. Optional, not correlation_id: required, since Dispatcher.call is also the conformance kit's (lib/portage/ucp/rspec.rb) and specs' direct entry point, outside any MCP request (§23).

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/portage/ucp/dispatcher.rb', line 21

def call(capability:, action:, arguments: {}, correlation_id: nil)
  capability_definition = @registry.find(capability)
  raise UnknownCapabilityError, capability if capability_definition.nil?

  raise CapabilityNotAdvertisedError, capability unless capability_definition.advertised_for?(@adapter)

  method_name = capability_definition.actions[action]
  raise UnknownActionError, action if method_name.nil?

  Portage::Ucp::PaymentTokenGuard.validate!(arguments[:payment_token]) if arguments.key?(:payment_token)

  result = call_adapter(method_name, arguments, correlation_id)
  wrap(capability, result)
end