RequestContext
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
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
PROTOCOL_VERSION_META_KEY
`_meta` key carrying the protocol revision of a single request, introduced with the modern era that replaced the `initialize` handshake.
private
mixed
PROTOCOL_VERSION_META_KEY
= 'io.modelcontextprotocol/protocolVersion'
Tags
Properties
$clientGateway
private
ClientGateway|null
$clientGateway
= null
$clientLogger
private
ClientLogger|null
$clientLogger
= null
$request read-only
private
Request
$request
$session read-only
private
SessionInterface
$session
Methods
__construct()
public
__construct(SessionInterface $session, Request $request) : mixed
Parameters
- $session : SessionInterface
- $request : Request
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|nullgetClientGateway()
public
getClientGateway() : ClientGateway
Return values
ClientGatewaygetClientLogger()
public
getClientLogger() : ClientLogger
Return values
ClientLoggergetInputContext()
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|nullgetProtocolVersion()
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
ProtocolVersiongetRequest()
public
getRequest() : Request
Return values
RequestgetSession()
public
getSession() : SessionInterface
Return values
SessionInterfacegetTraceContext()
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>