MCP PHP SDK

StatelessResult

FinalYes

One modern-era answer, paired with the HTTP status that carries it.

SEP-2575 fixes specific statuses to specific JSON-RPC error codes, so the status is part of the answer rather than something the transport re-derives.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Properties

$frames  : Closure|null
$httpStatus  : int
$message  : MessageInterface|null
$body  : array<string|int, mixed>|null
$bodyless  : bool
$id  : string|int|null

Methods

empty()  : self
A status with no body — what a notification gets, since it has no id to correlate a JSON-RPC message against.
error()  : self
isEmpty()  : bool
isError()  : bool
isStream()  : bool
ok()  : self
A successful answer whose body the wire codec has already stamped — a plain array, since no result class models the fields it added.
stream()  : self
A long-lived answer delivered as frames — today only `subscriptions/listen`. Deferred, since the frames are produced over the life of the connection.
toJson()  : string
__construct()  : mixed

Properties

Methods

empty()

A status with no body — what a notification gets, since it has no id to correlate a JSON-RPC message against.

public static empty(int $httpStatus) : self
Parameters
$httpStatus : int
Return values
self

error()

public static error(Error $error, int $httpStatus) : self
Parameters
$error : Error
$httpStatus : int
Return values
self

ok()

A successful answer whose body the wire codec has already stamped — a plain array, since no result class models the fields it added.

public static ok(string|int $id, array<string, mixed> $body) : self
Parameters
$id : string|int
$body : array<string, mixed>
Return values
self

stream()

A long-lived answer delivered as frames — today only `subscriptions/listen`. Deferred, since the frames are produced over the life of the connection.

public static stream(callable(): Generator<string|int, mixed> $frames) : self
Parameters
$frames : callable(): Generator<string|int, mixed>
Return values
self

__construct()

private __construct(MessageInterface|null $message, int $httpStatus[, callable(): Generator<string|int, mixed>|null $frames = null ][, array<string, mixed>|null $body = null ][, string|int|null $id = null ][, bool $bodyless = false ]) : mixed
Parameters
$message : MessageInterface|null
$httpStatus : int
$frames : callable(): Generator<string|int, mixed>|null = null

set instead of $message when the answer is a stream

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

a result body already through the wire codec

$id : string|int|null = null
$bodyless : bool = false
On this page

Search results