MCP PHP SDK

SamplingMessage extends Content

Describes a message issued to or received from an LLM API during sampling.

since protocol revision 2026-07-28 (SEP-2577), earliest removal 2027-07-28. Integrate with an LLM provider's API directly instead.

Structural validity is enforced here, but the spec's tool-flow rules (which role may carry which block, tool results not being mixed with other content, every tool use being answered) are not: they span the whole message list and must be reportable as an "invalid params" error rather than as a parse failure. They live in CreateSamplingMessageRequest::validateToolFlow().

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Properties

$content  : SamplingContent|array<int, SamplingContent>
$meta  : array<string|int, mixed>|null
$role  : Role
$type  : string

Methods

__construct()  : mixed
fromArray()  : self
getContentBlocks()  : array<int, SamplingContent>
jsonSerialize()  : SamplingContent>, _meta?: array}
hydrateContent()  : SamplingContent

Properties

$content read-only

public SamplingContent|array<int, SamplingContent> $content

Methods

__construct()

public __construct(Role $role, SamplingContent|array<string|int, SamplingContent$content[, array<string, mixed>|null $meta = null ]) : mixed
Parameters
$role : Role
$content : SamplingContent|array<string|int, SamplingContent>

keys are discarded, the property always holds a list

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

fromArray()

public static fromArray(SamplingMessageData $data) : self
Parameters
$data : SamplingMessageData
Return values
self

getContentBlocks()

public getContentBlocks() : array<int, SamplingContent>
Return values
array<int, SamplingContent>

jsonSerialize()

public jsonSerialize() : SamplingContent>, _meta?: array}
Return values
SamplingContent>, _meta?: array}

hydrateContent()

private static hydrateContent(array<string, mixed> $contentData) : SamplingContent
Parameters
$contentData : array<string, mixed>
Return values
SamplingContent
On this page

Search results