-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathClientStateInterface.php
More file actions
115 lines (98 loc) · 3.19 KB
/
ClientStateInterface.php
File metadata and controls
115 lines (98 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Client\State;
use Mcp\Schema\Implementation;
use Mcp\Schema\JsonRpc\Error;
use Mcp\Schema\JsonRpc\Response;
/**
* 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.
*
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
*/
interface ClientStateInterface
{
/**
* Get the next request ID for outgoing requests.
*/
public function nextRequestId(): int;
/**
* Add a pending request to track.
*
* @param int|string $requestId The request ID
* @param int $timeout Timeout in seconds
*/
public function addPendingRequest(int|string $requestId, int $timeout): void;
/**
* Remove a pending request.
*/
public function removePendingRequest(int|string $requestId): void;
/**
* Get all pending requests.
*
* @return array<int|string, array{request_id: int|string, timestamp: int, timeout: int}>
*/
public function getPendingRequests(): array;
/**
* Store a received response.
*
* @param int|string $requestId The request ID
* @param array<string, mixed> $responseData The raw response data
*/
public function storeResponse(int|string $requestId, array $responseData): void;
/**
* Check and consume a response for a request ID.
*
* @return Response<array<string, mixed>>|Error|null
*/
public function consumeResponse(int|string $requestId): Response|Error|null;
/**
* Set initialization state.
*/
public function setInitialized(bool $initialized): void;
/**
* Check if connection is initialized.
*/
public function isInitialized(): bool;
/**
* Store the server info from initialization.
*/
public function setServerInfo(Implementation $serverInfo): void;
/**
* Get the server info from initialization.
*/
public function getServerInfo(): ?Implementation;
/**
* Store the server instructions from initialization.
*/
public function setInstructions(?string $instructions): void;
/**
* Get the server instructions from initialization.
*/
public function getInstructions(): ?string;
/**
* Store progress data received from a notification.
*
* @param string $token The progress token
* @param float $progress Current progress value
* @param float|null $total Total progress value (if known)
* @param string|null $message Progress message
*/
public function storeProgress(string $token, float $progress, ?float $total, ?string $message): void;
/**
* Consume all pending progress updates.
*
* @return array<int, array{token: string, progress: float, total: ?float, message: ?string}>
*/
public function consumeProgressUpdates(): array;
}