Skip to content

ActionToolAdapter

The actions-as-tools bridge (the headline feature): maps one tools/call to a specific #[Route] action’s own execution path.

Rather than reaching into ActionExecutor directly — which requires preconditions (a canonical WebRequest, a validation decision) that only Context::handle()’s own middleware pipeline satisfies — this builds a synthetic PSR-7 request and drives it through that exact same pipeline, so the action gets the real DI, verb dispatch, and validation a normal HTTP call would get, for free.

One instance is registered per discovered action-tool (see ActionToolScanner), each bound to its own route name and primary HTTP method at construction time — unlike a [class, method] catalog handler, which mcp/sdk always re-resolves fresh per call and so can’t carry per-registration configuration like this.

final class ActionToolAdapter implements ToolHandlerInterface

ImplementsToolHandlerInterface
SourceBridge/ActionToolAdapter.php

public function __construct(string $contextName, string $routeName, string $httpMethod): mixed

ParameterTypeDescription
$contextNamestring
$routeNamestring
$httpMethodstring

Returns mixed

MethodDescription
execute(array<string, mixed> $arguments, ClientGateway $gateway): mixed

public function execute(array<string, mixed> $arguments, ClientGateway $gateway): mixed

ParameterTypeDescription
$argumentsarray``<``string``, ``mixed``>
$gatewayClientGateway

Returns mixed