MCP PHP SDK

RequestStateCodec

FinalYes

Seals and verifies the opaque `requestState` carried across the rounds of a multi round-trip request (SEP-2322).

The value is base64url(payload).base64url(HMAC). It passes through the client, so it is attacker-controlled on return and self::verify() refuses anything whose MAC or expiry does not hold. Signed, not encrypted: nothing secret belongs in the payload.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Constants

MINIMUM_KEY_BYTES  : mixed = 32
Below this the MAC — the only thing making the blob trustworthy — is forgeable.
ALGORITHM  : mixed = 'sha256'

Properties

$key  : string
$ttlSeconds  : int

Methods

__construct()  : mixed
mint()  : string
verify()  : array<string, mixed>
decode()  : string|null
encode()  : string
sign()  : string

Constants

MINIMUM_KEY_BYTES

Below this the MAC — the only thing making the blob trustworthy — is forgeable.

public mixed MINIMUM_KEY_BYTES = 32

Properties

Methods

__construct()

public __construct(string $key[, int $ttlSeconds = 600 ]) : mixed
Parameters
$key : string
$ttlSeconds : int = 600

mint()

public mint(array<string, mixed> $payload[, int|null $now = null ]) : string
Parameters
$payload : array<string, mixed>

server context to carry to the retry — never secrets

$now : int|null = null
Return values
string

verify()

public verify(string $state[, int|null $now = null ]) : array<string, mixed>
Parameters
$state : string
$now : int|null = null
Tags
throws
RequestStateException

when the value is malformed, unsigned by this key, or expired

Return values
array<string, mixed>

the payload that was sealed

decode()

private static decode(string $encoded) : string|null
Parameters
$encoded : string
Return values
string|null

encode()

private static encode(string $raw) : string
Parameters
$raw : string
Return values
string

sign()

private sign(string $body) : string
Parameters
$body : string
Return values
string
On this page

Search results