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
Table of Contents
Interfaces
- MiddlewareInterface
Properties
- $responseFactory : ResponseFactoryInterface
- $streamFactory : StreamFactoryInterface
- $supportedVersions : array<int, string>
Methods
- __construct() : mixed
- process() : ResponseInterface
Properties
$responseFactory
private
ResponseFactoryInterface
$responseFactory
$streamFactory
private
StreamFactoryInterface
$streamFactory
$supportedVersions read-only
private
array<int, string>
$supportedVersions
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