MCP PHP SDK

CallToolResult implements ResultInterface

The server's response to a tool call.

Any errors that originate from the tool SHOULD be reported inside the result object, with isError set to true, not as an MCP protocol-level error response. Otherwise, the LLM would not be able to see that an error occurred and self-correct.

However, any errors in finding the tool, an error indicating that the server does not support tool calls, or any other exceptional conditions, should be reported as an MCP error response.

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Interfaces

ResultInterface
Base class for all specific MCP result objects (the value of the 'result' field).

Properties

$content  : array<string|int, mixed>
$isError  : bool
$meta  : array<string|int, mixed>|null
$structuredContent  : array<string|int, mixed>|null

Methods

__construct()  : mixed
Create a new CallToolResult.
error()  : self
Create a new CallToolResult with error status.
fromArray()  : self
jsonSerialize()  : array{content: array, isError: bool, structuredContent?: array, _meta?: array}
success()  : self
Create a new CallToolResult with success status.

Properties

$meta read-only

public array<string|int, mixed>|null $meta = null

$structuredContent read-only

public array<string|int, mixed>|null $structuredContent = null

Methods

__construct()

Create a new CallToolResult.

public __construct(array<string|int, Content$content[, bool $isError = false ][, array<string|int, mixed> $structuredContent = null ][, array<string, mixed>|null $meta = null ]) : mixed
Parameters
$content : array<string|int, Content>

The content of the tool result

$isError : bool = false

Whether the tool execution resulted in an error. If not set, this is assumed to be false (the call was successful).

$structuredContent : array<string|int, mixed> = null

JSON content for structuredContent

$meta : array<string, mixed>|null = null

Optional metadata

error()

Create a new CallToolResult with error status.

public static error(array<string|int, Content$content[, array<string, mixed>|null $meta = null ]) : self
Parameters
$content : array<string|int, Content>

The content of the tool result

$meta : array<string, mixed>|null = null

Optional metadata

Return values
self

fromArray()

public static fromArray(array{content: array, isError?: bool, _meta?: array, structuredContent?: array$data) : self
Parameters
$data : array{content: array, isError?: bool, _meta?: array, structuredContent?: array}
Return values
self

jsonSerialize()

public jsonSerialize() : array{content: array, isError: bool, structuredContent?: array, _meta?: array}
Return values
array{content: array, isError: bool, structuredContent?: array, _meta?: array}

success()

Create a new CallToolResult with success status.

public static success(array<string|int, Content$content[, array<string, mixed>|null $meta = null ]) : self
Parameters
$content : array<string|int, Content>

The content of the tool result

$meta : array<string, mixed>|null = null

Optional metadata

Return values
self

        
On this page

Search results