MCP PHP SDK

RequestContext

FinalYes

Context related to a single request. This includes information about the session and will build request-specific objects.

This is a stateful object, it should not be reused between requests.

Tags
author

Tobias Nyholm tobias.nyholm@gmail.com

Table of Contents

Constants

PROTOCOL_VERSION_META_KEY  : mixed = 'io.modelcontextprotocol/protocolVersion'
`_meta` key carrying the protocol revision of a single request, introduced with the modern era that replaced the `initialize` handshake.

Properties

$clientGateway  : ClientGateway|null
$clientLogger  : ClientLogger|null
$request  : Request
$session  : SessionInterface

Methods

__construct()  : mixed
getClientCapabilities()  : ClientCapabilities|null
What the client declared on this request. A server MUST NOT ask for input the client cannot supply. Null in the handshake era, where capabilities are connection state.
getClientGateway()  : ClientGateway
getClientLogger()  : ClientLogger
getInputContext()  : InputContext|null
What a multi round-trip retry carried back, or null on a first call — which is the signal to return an {@see \Mcp\Schema\Result\InputRequiredResult} instead of an answer.
getProtocolVersion()  : ProtocolVersion
The protocol revision this request is served under.
getRequest()  : Request
getSession()  : SessionInterface
getTraceContext()  : array<string, string>
The W3C trace context this request carried, if any.
mintRequestState()  : string
Seals handler context into the string an {@see \Mcp\Schema\Result\InputRequiredResult} carries to the client.

Constants

Properties

Methods

getClientCapabilities()

What the client declared on this request. A server MUST NOT ask for input the client cannot supply. Null in the handshake era, where capabilities are connection state.

public getClientCapabilities() : ClientCapabilities|null
Return values
ClientCapabilities|null

getInputContext()

What a multi round-trip retry carried back, or null on a first call — which is the signal to return an {@see \Mcp\Schema\Result\InputRequiredResult} instead of an answer.

public getInputContext() : InputContext|null
Return values
InputContext|null

getProtocolVersion()

The protocol revision this request is served under.

public getProtocolVersion() : ProtocolVersion

Modern revisions declare it per request in _meta, handshake ones negotiate it once and keep it on the session. Neither is guaranteed to be present — a transport may skip initialize entirely — so this falls back to the newest handshake revision, whose rules hold for every revision below it too.

Return values
ProtocolVersion

getTraceContext()

The W3C trace context this request carried, if any.

public getTraceContext() : array<string, string>

Values are passed through exactly as they arrived — validating or regenerating them is the tracing library's job, not the protocol's. The SDK echoes them onto the notifications a handler emits so a span stays joined across the stream.

Return values
array<string, string>

keyed by traceparent, tracestate, baggage

mintRequestState()

Seals handler context into the string an {@see \Mcp\Schema\Result\InputRequiredResult} carries to the client.

public mintRequestState(array<string, mixed> $payload) : string

Signed, not encrypted: nothing secret belongs in the payload.

Parameters
$payload : array<string, mixed>
Return values
string
On this page

Search results