MCP PHP SDK

StatelessHttpTransport uses ReadsBoundedBody

FinalYes

Carries the modern (SEP-2575) lifecycle over HTTP.

Not a mode of StreamableHttpTransport, whose job is largely session management; without a session what is left is a POST in, one message out.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Constants

DEFAULT_MAX_BODY_BYTES  : mixed = 4 * 1024 * 1024
Upper bound on the request body read for a POST, guarding against memory exhaustion from an oversized (or unbounded chunked) payload.

Properties

$logger  : LoggerInterface
$maxBodyBytes  : int
$middleware  : array<int, MiddlewareInterface>
$protocol  : StatelessProtocol
$responder  : StatelessResponder
$responseFactory  : ResponseFactoryInterface
$streamFactory  : StreamFactoryInterface

Methods

__construct()  : mixed
defaultMiddleware()  : array<int, MiddlewareInterface>
Browser-facing protections, era-independent. The protocol-version middleware is absent: here the version travels in `_meta`, so a header-only check would judge half the story.
handle()  : ResponseInterface
dispatch()  : ResponseInterface
json()  : ResponseInterface
readBoundedBody()  : string|null
Returns the body contents, or `null` when the payload exceeds $maxBytes.

Constants

DEFAULT_MAX_BODY_BYTES

Upper bound on the request body read for a POST, guarding against memory exhaustion from an oversized (or unbounded chunked) payload.

public mixed DEFAULT_MAX_BODY_BYTES = 4 * 1024 * 1024

Properties

Methods

__construct()

public __construct(StatelessProtocol $protocol[, ResponseFactoryInterface|null $responseFactory = null ][, StreamFactoryInterface|null $streamFactory = null ][, LoggerInterface $logger = new NullLogger() ][, int $maxBodyBytes = self::DEFAULT_MAX_BODY_BYTES ][, iterable<string|int, MiddlewareInterface>|null $middleware = null ]) : mixed
Parameters
$protocol : StatelessProtocol
$responseFactory : ResponseFactoryInterface|null = null
$streamFactory : StreamFactoryInterface|null = null
$logger : LoggerInterface = new NullLogger()
$maxBodyBytes : int = self::DEFAULT_MAX_BODY_BYTES
$middleware : iterable<string|int, MiddlewareInterface>|null = null

null installs self::defaultMiddleware(); [] disables all middleware

defaultMiddleware()

Browser-facing protections, era-independent. The protocol-version middleware is absent: here the version travels in `_meta`, so a header-only check would judge half the story.

public static defaultMiddleware() : array<int, MiddlewareInterface>
Return values
array<int, MiddlewareInterface>

handle()

public handle(ServerRequestInterface $request) : ResponseInterface
Parameters
$request : ServerRequestInterface
Return values
ResponseInterface

dispatch()

private dispatch(ServerRequestInterface $request) : ResponseInterface
Parameters
$request : ServerRequestInterface
Return values
ResponseInterface

json()

private json(string $payload, int $status) : ResponseInterface
Parameters
$payload : string
$status : int
Return values
ResponseInterface

readBoundedBody()

Returns the body contents, or `null` when the payload exceeds $maxBytes.

private readBoundedBody(StreamInterface $body, int $maxBytes) : string|null

A stream advertising its size is rejected up front; otherwise the read is incremental and stops at the cap, so an unbounded stream cannot exhaust memory.

Parameters
$body : StreamInterface
$maxBytes : int
Return values
string|null
On this page

Search results