MCP PHP SDK

Rev2026Codec implements WireCodecInterface

FinalYes

The wire codec for 2026-07-28: stamps `resultType`, then the SEP-2549 caching hints, then the `_meta` serverInfo identity.

The order matters — the cache fill only runs on a result that came out of the stamp as complete, so one still asking for input never gets a TTL.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Interfaces

WireCodecInterface
Translates the SDK's revision-neutral result model into the wire shape one protocol era expects.

Constants

CACHEABLE_METHODS  : mixed = ['server/discover', 'tools/list', 'prompts/list...
Methods whose results a client may cache, and which therefore MUST carry hints.
EXTENDED_RESULT_TYPE_METHODS  : mixed = ['tools/call', 'prompts/get', 'resources/read']
Methods that can come back asking for input (MRTR).

Properties

$cachePolicy  : CachePolicy
$serverInfo  : Implementation|null

Methods

__construct()  : mixed
encodeResult()  : array<string, mixed>
Stamps an already-serialized result with whatever this era requires.
fillCacheHints()  : array<string, mixed>
Fills `ttlMs`/`cacheScope`, most-specific author first: a value the result itself carries, then the configured {@see CachePolicy}, whose own default is "private, do not cache".
stampResultType()  : array<string, mixed>
A result naming its own type keeps it, but only where the method's vocabulary allows more than `complete`.
stampServerInfo()  : array<string, mixed>
Servers SHOULD identify themselves on every response; an identity the result already carries wins.

Constants

CACHEABLE_METHODS

Methods whose results a client may cache, and which therefore MUST carry hints.

public mixed CACHEABLE_METHODS = ['server/discover', 'tools/list', 'prompts/list', 'resources/list', 'resources/templates/list', 'resources/read']

EXTENDED_RESULT_TYPE_METHODS

Methods that can come back asking for input (MRTR).

public mixed EXTENDED_RESULT_TYPE_METHODS = ['tools/call', 'prompts/get', 'resources/read']

Properties

Methods

encodeResult()

Stamps an already-serialized result with whatever this era requires.

public encodeResult(string $method, array<string|int, mixed> $result[, bool $cacheable = true ]) : array<string, mixed>
Parameters
$method : string

the request method the result answers

$result : array<string|int, mixed>

the neutral result body

$cacheable : bool = true

whether this answer may carry caching hints at all — false for one produced by a multi round-trip retry, whose inputs are not part of any cache key

Return values
array<string, mixed>

fillCacheHints()

Fills `ttlMs`/`cacheScope`, most-specific author first: a value the result itself carries, then the configured {@see CachePolicy}, whose own default is "private, do not cache".

private fillCacheHints(string $method, array<string, mixed> $result) : array<string, mixed>
Parameters
$method : string
$result : array<string, mixed>
Return values
array<string, mixed>

stampResultType()

A result naming its own type keeps it, but only where the method's vocabulary allows more than `complete`.

private stampResultType(string $method, array<string, mixed> $result) : array<string, mixed>
Parameters
$method : string
$result : array<string, mixed>
Return values
array<string, mixed>

stampServerInfo()

Servers SHOULD identify themselves on every response; an identity the result already carries wins.

private stampServerInfo(array<string, mixed> $result) : array<string, mixed>
Parameters
$result : array<string, mixed>
Return values
array<string, mixed>
On this page

Search results