1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Core\Schema\Request;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest;
18: use Nexus\Mcp\Core\Schema\RequestId;
19: use Nexus\Mcp\Core\Schema\RequestParams\EmptyRequestParams;
20:
21: /**
22: * A ping, issued by either the server or the client, to check that the other party is still alive.
23: * The receiver must promptly respond, or else may be disconnected.
24: *
25: * @extends JsonRpcRequest<'ping'>
26: *
27: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#pingrequest
28: */
29: final readonly class PingRequest extends JsonRpcRequest implements ClientRequest, ServerRequest
30: {
31: #[\Override]
32: public static function getMethod(): string
33: {
34: return 'ping';
35: }
36:
37: #[\Override]
38: public static function fromArray(array $data): static
39: {
40: Assert::that($data)->hasOffset('id', 'missing the required "id" key.');
41:
42: $id = $data['id'];
43: Assert::that($id)->isArrayKey('"id" must be an int or string, {type} given.');
44:
45: $params = new EmptyRequestParams();
46:
47: if (\array_key_exists('params', $data)) {
48: Assert::that($data['params'])
49: ->isArray('"params" must be an object, {type} given.')
50: ->isMap('"params" must be a string-keyed object.')
51: ;
52: $params = EmptyRequestParams::fromArray($data['params']);
53: }
54:
55: return new self(new RequestId($id), $params);
56: }
57: }
58: