Skip to content
docsv0.2.0

ToolResult

Structured result from tool execution. All tools should return ToolResult for consistent rendering across channels.

ToolResult::__construct()

public function __construct(bool $success, ?mixed $data = null, ?string $message = null, ?string $error = null, array $meta = []):

Parameters

Parameters of __construct()
NameTypeDescription
$successbool
$data?mixed
$message?string
$error?string
$metaarray<string, mixed>

ToolResult::success()

public static function success(?mixed $data = null, ?string $message = null, array $meta = []): self

Create a success result.

Parameters

Parameters of success()
NameTypeDescription
$data?mixed
$message?string
$metaarray<string, mixed>

ToolResult::error()

public static function error(string $error, ?mixed $data = null, array $meta = []): self

Create an error result.

Parameters

Parameters of error()
NameTypeDescription
$errorstring
$data?mixed
$metaarray<string, mixed>

ToolResult::paginated()

public static function paginated(array $items, int $page, int $totalItems, int $limit, ?string $message = null, array $extraMeta = []): self

Create a paginated list result.

Parameters

Parameters of paginated()
NameTypeDescription
$itemslist<array<string, mixed>>
$pageint
$totalItemsint
$limitint
$message?string
$extraMetaarray<string, mixed>

ToolResult::detail()

public static function detail(array $item, string $entity, ?string $message = null, array $actions = []): self

Create a detail/single item result.

Parameters

Parameters of detail()
NameTypeDescription
$itemarray<string, mixed>
$entitystring
$message?string
$actionslist<mixed>

ToolResult::confirmation()

public static function confirmation(string $message, array $details, string $action, string $target, string|int $targetId): self

Create a confirmation request result.

Parameters

Parameters of confirmation()
NameTypeDescription
$messagestring
$detailsarray<string, mixed>
$actionstring
$targetstring
$targetIdstring|int

ToolResult::blocked()

public static function blocked(string $reason, ?string $suggestion = null): self

Create a blocked result (by business rule).

Parameters

Parameters of blocked()
NameTypeDescription
$reasonstring
$suggestion?string

ToolResult::requiresConfirmation()

public function requiresConfirmation(): bool

Check if this result requires confirmation.

ToolResult::isBlocked()

public function isBlocked(): bool

Check if this result was blocked by a business rule.

ToolResult::getType()

public function getType(): string

Get the result type.

ToolResult::getPagination()

public function getPagination(): ?array

Get pagination info if present.

ToolResult::getActions()

public function getActions(): array

Get actions if present.

ToolResult::getConfirmToken()

public function getConfirmToken(): ?string

Get the confirmation token, if this result carries a confirmation request.

ToolResult::withMeta()

public function withMeta(array $extra): self

Return a copy with extra metadata merged into meta. Replaces the former ToolResult(A)::withMetadata(); the runtime uses it to attach soft-timeout info without rebuilding the result.

Parameters

Parameters of withMeta()
NameTypeDescription
$extraarray<string, mixed>

ToolResult::jsonSerialize()

public function jsonSerialize(): array

Serialize to the wire shape consumed by every channel renderer and the MCP transport.

ToolResult::toJson()

public function toJson(): string

Encode this result as pretty-printed, unescaped-unicode JSON.

ToolResult::toArray()

public function toArray(): array

Convert to a plain array; same shape as {@see jsonSerialize()}.