CreateSamplingMessageResult implements ResultInterface
The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
since protocol revision 2026-07-28 (SEP-2577), earliest removal 2027-07-28. Integrate with an LLM provider's API directly instead.
Tags
Table of Contents
Interfaces
- ResultInterface
- Base class for all specific MCP result objects (the value of the 'result' field).
Properties
- $content : TextContent|ImageContent|AudioContent|ToolUseContent|array<int, TextContent|ImageContent|AudioContent|ToolUseContent>
- $meta : array<string|int, mixed>|null
- $model : string
- $role : Role
- $stopReason : string|null
Methods
- __construct() : mixed
- fromArray() : self
- getContentBlocks() : array<int, TextContent|ImageContent|AudioContent|ToolUseContent>
-
jsonSerialize()
: ToolUseContent>, model: string, stopReason?: string, _meta?: array
} - hydrateContent() : TextContent|ImageContent|AudioContent|ToolUseContent
Properties
$content read-only
public
TextContent|ImageContent|AudioContent|ToolUseContent|array<int, TextContent|ImageContent|AudioContent|ToolUseContent>
$content
$meta read-only
public
array<string|int, mixed>|null
$meta
= null
$model read-only
public
string
$model
$role read-only
public
Role
$role
$stopReason read-only
public
string|null
$stopReason
= null
Methods
__construct()
public
__construct(Role $role, TextContent|ImageContent|AudioContent|ToolUseContent|array<string|int, TextContent|ImageContent|AudioContent|ToolUseContent> $content, string $model[, string|null $stopReason = null ][, array<string, mixed>|null $meta = null ]) : mixed
Parameters
- $role : Role
-
the role of the message
- $content : TextContent|ImageContent|AudioContent|ToolUseContent|array<string|int, TextContent|ImageContent|AudioContent|ToolUseContent>
-
The content of the message. Keys are discarded, the property always holds a list.
- $model : string
-
the name of the model that generated the message
- $stopReason : string|null = null
-
The reason why sampling stopped, if known. The spec defines "endTurn", "stopSequence", "maxTokens" and "toolUse", but leaves the set open for provider-specific values, so this stays an unconstrained string.
- $meta : array<string, mixed>|null = null
-
optional message metadata
fromArray()
public
static fromArray(array<string, mixed> $data) : self
Parameters
- $data : array<string, mixed>
Return values
selfgetContentBlocks()
public
getContentBlocks() : array<int, TextContent|ImageContent|AudioContent|ToolUseContent>
Return values
array<int, TextContent|ImageContent|AudioContent|ToolUseContent>jsonSerialize()
public
jsonSerialize() : ToolUseContent>, model: string, stopReason?: string, _meta?: array}
Return values
ToolUseContent>, model: string, stopReason?: string, _meta?: arrayhydrateContent()
private
static hydrateContent(array<string, mixed> $contentData) : TextContent|ImageContent|AudioContent|ToolUseContent
Parameters
- $contentData : array<string, mixed>