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\Extension\Tasks\Schema\Request;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest;
18: use Nexus\Mcp\Core\Schema\Request\ClientRequest;
19: use Nexus\Mcp\Core\Schema\RequestId;
20: use Nexus\Mcp\Core\Schema\RequestParams;
21: use Nexus\Mcp\Extension\Tasks\Schema\RequestParams\UpdateTaskRequestParams;
22:
23: /**
24: * Sent from the client to the server, to supply input responses to a task waiting in the `input_required` status.
25: *
26: * @property-read UpdateTaskRequestParams $params
27: *
28: * @extends JsonRpcRequest<'tasks/update', array{
29: * jsonrpc: '2.0',
30: * id: int|non-empty-string,
31: * method: 'tasks/update',
32: * params: template-type<UpdateTaskRequestParams, RequestParams, 'T'>,
33: * }>
34: *
35: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/seps/2663-tasks-extension.md
36: */
37: final readonly class UpdateTaskRequest extends JsonRpcRequest implements ClientRequest
38: {
39: public function __construct(RequestId $id, UpdateTaskRequestParams $params)
40: {
41: parent::__construct(id: $id, params: $params);
42: }
43:
44: #[\Override]
45: public static function getMethod(): string
46: {
47: return 'tasks/update';
48: }
49:
50: #[\Override]
51: public static function fromArray(array $data): static
52: {
53: Assert::that($data)->hasOffset('id', 'missing the required "id" key.');
54: $id = $data['id'];
55: Assert::that($id)->isIntOrNonEmptyString('"id" must be an int or non-empty string, {type} given.');
56:
57: Assert::that($data)->hasOffset('params', 'missing the required "params" key.');
58: Assert::that($data['params'])
59: ->isArray('"params" must be an object, {type} given.')
60: ->isMap('"params" must be a string-keyed object.')
61: ;
62:
63: return new self(
64: id: new RequestId(id: $id),
65: params: UpdateTaskRequestParams::fromArray($data['params']),
66: );
67: }
68:
69: #[\Override]
70: public function toArray(): array
71: {
72: return [
73: 'jsonrpc' => self::JSONRPC_VERSION,
74: 'id' => $this->id->id,
75: 'method' => self::getMethod(),
76: 'params' => $this->params->toArray(),
77: ];
78: }
79: }
80: