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\RequestParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\MetaObject;
18: use Nexus\Mcp\Core\Schema\MetaObject\RequestMetaObject;
19: use Nexus\Mcp\Core\Schema\RequestParams;
20:
21: /**
22: * Parameters for a `tasks/cancel` request.
23: *
24: * @extends RequestParams<array{
25: * _meta: template-type<RequestMetaObject, MetaObject, 'T'>,
26: * taskId: non-empty-string,
27: * }>
28: *
29: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/seps/2663-tasks-extension.md
30: */
31: final readonly class CancelTaskRequestParams extends RequestParams
32: {
33: /**
34: * @param non-empty-string $taskId
35: */
36: public function __construct(
37: public string $taskId,
38: RequestMetaObject $meta,
39: ) {
40: parent::__construct(meta: $meta);
41: }
42:
43: #[\Override]
44: public static function fromArray(array $data): static
45: {
46: Assert::that($data)->hasOffset('taskId', '"params" is missing the required "taskId" key.');
47: $taskId = $data['taskId'];
48: Assert::that($taskId)->isNonEmptyString('"params.taskId" must be a non-empty string, {type} given.');
49:
50: Assert::that($data)->hasOffset('_meta', '"params" is missing the required "_meta" key.');
51: Assert::that($data['_meta'])
52: ->isArray('"params._meta" must be an object, {type} given.')
53: ->not()->isNonEmptyList('"params._meta" must be a string-keyed object.')
54: ;
55: $meta = RequestMetaObject::fromArray($data['_meta']);
56:
57: return new self(taskId: $taskId, meta: $meta);
58: }
59:
60: #[\Override]
61: public function toArray(): array
62: {
63: return [
64: '_meta' => $this->meta->toArray(),
65: 'taskId' => $this->taskId,
66: ];
67: }
68: }
69: