MCP PHP SDK

ClientStateInterface

Interface for client state management.

Tracks pending requests, stores responses, and manages runtime state for the client's connection to a server. This is ephemeral state that exists only for the lifetime of the connection.

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Methods

addPendingRequest()  : void
Add a pending request to track.
consumeProgressUpdates()  : array<int, array{token: string, progress: float, total: ?float, message: ?string}>
Consume all pending progress updates.
consumeResponse()  : Response<string|int, array<string, mixed>>|Error|null
Check and consume a response for a request ID.
getInstructions()  : string|null
Get the server instructions from initialization.
getPendingRequests()  : array<int|string, array{request_id: int|string, timestamp: int, timeout: int}>
Get all pending requests.
getServerInfo()  : Implementation|null
Get the server info from initialization.
isInitialized()  : bool
Check if connection is initialized.
nextRequestId()  : int
Get the next request ID for outgoing requests.
removePendingRequest()  : void
Remove a pending request.
setInitialized()  : void
Set initialization state.
setInstructions()  : void
Store the server instructions from initialization.
setServerInfo()  : void
Store the server info from initialization.
storeProgress()  : void
Store progress data received from a notification.
storeResponse()  : void
Store a received response.

Methods

addPendingRequest()

Add a pending request to track.

public addPendingRequest(int|string $requestId, int $timeout) : void
Parameters
$requestId : int|string

The request ID

$timeout : int

Timeout in seconds

consumeProgressUpdates()

Consume all pending progress updates.

public consumeProgressUpdates() : array<int, array{token: string, progress: float, total: ?float, message: ?string}>
Return values
array<int, array{token: string, progress: float, total: ?float, message: ?string}>

consumeResponse()

Check and consume a response for a request ID.

public consumeResponse(int|string $requestId) : Response<string|int, array<string, mixed>>|Error|null
Parameters
$requestId : int|string
Return values
Response<string|int, array<string, mixed>>|Error|null

getInstructions()

Get the server instructions from initialization.

public getInstructions() : string|null
Return values
string|null

getPendingRequests()

Get all pending requests.

public getPendingRequests() : array<int|string, array{request_id: int|string, timestamp: int, timeout: int}>
Return values
array<int|string, array{request_id: int|string, timestamp: int, timeout: int}>

isInitialized()

Check if connection is initialized.

public isInitialized() : bool
Return values
bool

nextRequestId()

Get the next request ID for outgoing requests.

public nextRequestId() : int
Return values
int

removePendingRequest()

Remove a pending request.

public removePendingRequest(int|string $requestId) : void
Parameters
$requestId : int|string

setInitialized()

Set initialization state.

public setInitialized(bool $initialized) : void
Parameters
$initialized : bool

setInstructions()

Store the server instructions from initialization.

public setInstructions(string|null $instructions) : void
Parameters
$instructions : string|null

storeProgress()

Store progress data received from a notification.

public storeProgress(string $token, float $progress, float|null $total, string|null $message) : void
Parameters
$token : string

The progress token

$progress : float

Current progress value

$total : float|null

Total progress value (if known)

$message : string|null

Progress message

storeResponse()

Store a received response.

public storeResponse(int|string $requestId, array<string, mixed> $responseData) : void
Parameters
$requestId : int|string

The request ID

$responseData : array<string, mixed>

The raw response data


        
On this page

Search results