MCP PHP SDK

ProtocolVersionMiddleware implements MiddlewareInterface

FinalYes

Validates the `MCP-Protocol-Version` header against the SDK's supported set.

Per the MCP Streamable HTTP spec, after the initialize handshake clients must echo the negotiated protocol version on every subsequent request via the MCP-Protocol-Version header. Servers MUST reject unknown or malformed values with 400 Bad Request.

When the header is absent the middleware passes the request through — the initialize round-trip does not carry the header, and legacy clients that omit it are tolerated.

Tags
see
https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#protocol-version-header
author

Volodymyr Panivko sveneld300@gmail.com

Table of Contents

Interfaces

MiddlewareInterface

Properties

$responseFactory  : ResponseFactoryInterface
$streamFactory  : StreamFactoryInterface
$supportedVersions  : array<int, string>

Methods

__construct()  : mixed
process()  : ResponseInterface

Properties

Methods

__construct()

public __construct([array<int, ProtocolVersion>|null $supportedVersions = null ][, ResponseFactoryInterface|null $responseFactory = null ][, StreamFactoryInterface|null $streamFactory = null ]) : mixed
Parameters
$supportedVersions : array<int, ProtocolVersion>|null = null

Versions the server accepts. Defaults to all values of ProtocolVersion.

$responseFactory : ResponseFactoryInterface|null = null

PSR-17 response factory (auto-discovered if null)

$streamFactory : StreamFactoryInterface|null = null

PSR-17 stream factory (auto-discovered if null)

process()

public process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
$request : ServerRequestInterface
$handler : RequestHandlerInterface
Return values
ResponseInterface
On this page

Search results