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
| Name | Type | Description |
|---|---|---|
| $success | bool | |
| $data | ?mixed | |
| $message | ?string | |
| $error | ?string | |
| $meta | array<string, mixed> |
ToolResult::success()
public static function success(?mixed $data = null, ?string $message = null, array $meta = []): selfCreate a success result.
Parameters
| Name | Type | Description |
|---|---|---|
| $data | ?mixed | |
| $message | ?string | |
| $meta | array<string, mixed> |
ToolResult::error()
public static function error(string $error, ?mixed $data = null, array $meta = []): selfCreate an error result.
Parameters
| Name | Type | Description |
|---|---|---|
| $error | string | |
| $data | ?mixed | |
| $meta | array<string, mixed> |
ToolResult::paginated()
public static function paginated(array $items, int $page, int $totalItems, int $limit, ?string $message = null, array $extraMeta = []): selfCreate a paginated list result.
Parameters
| Name | Type | Description |
|---|---|---|
| $items | list<array<string, mixed>> | |
| $page | int | |
| $totalItems | int | |
| $limit | int | |
| $message | ?string | |
| $extraMeta | array<string, mixed> |
ToolResult::detail()
public static function detail(array $item, string $entity, ?string $message = null, array $actions = []): selfCreate a detail/single item result.
Parameters
| Name | Type | Description |
|---|---|---|
| $item | array<string, mixed> | |
| $entity | string | |
| $message | ?string | |
| $actions | list<mixed> |
ToolResult::confirmation()
public static function confirmation(string $message, array $details, string $action, string $target, string|int $targetId): selfCreate a confirmation request result.
Parameters
| Name | Type | Description |
|---|---|---|
| $message | string | |
| $details | array<string, mixed> | |
| $action | string | |
| $target | string | |
| $targetId | string|int |
ToolResult::blocked()
public static function blocked(string $reason, ?string $suggestion = null): selfCreate a blocked result (by business rule).
Parameters
| Name | Type | Description |
|---|---|---|
| $reason | string | |
| $suggestion | ?string |
ToolResult::requiresConfirmation()
public function requiresConfirmation(): boolCheck if this result requires confirmation.
ToolResult::isBlocked()
public function isBlocked(): boolCheck if this result was blocked by a business rule.
ToolResult::getType()
public function getType(): stringGet the result type.
ToolResult::getPagination()
public function getPagination(): ?arrayGet pagination info if present.
ToolResult::getActions()
public function getActions(): arrayGet actions if present.
ToolResult::getConfirmToken()
public function getConfirmToken(): ?stringGet the confirmation token, if this result carries a confirmation request.
ToolResult::withMeta()
public function withMeta(array $extra): selfReturn 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
| Name | Type | Description |
|---|---|---|
| $extra | array<string, mixed> |
ToolResult::jsonSerialize()
public function jsonSerialize(): arraySerialize to the wire shape consumed by every channel renderer and the MCP transport.
ToolResult::toJson()
public function toJson(): stringEncode this result as pretty-printed, unescaped-unicode JSON.
ToolResult::toArray()
public function toArray(): arrayConvert to a plain array; same shape as {@see jsonSerialize()}.