1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 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\Schema\Notification;
15:
16: use Nexus\Mcp\Schema\Message\JsonRpcNotification;
17: use Nexus\Mcp\Schema\Message\RequestId;
18:
19: /**
20: * This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
21: *
22: * The request SHOULD still be in-flight, but due to communication latency, it is always possible that this
23: * notification MAY arrive after the request has already finished.
24: *
25: * This notification indicates that the result will be unused, so any associated processing SHOULD cease.
26: *
27: * A client MUST NOT attempt to cancel its `initialize` request.
28: *
29: * @extends JsonRpcNotification<array{
30: * jsonrpc: '2.0',
31: * method: 'notifications/cancelled',
32: * params: array{
33: * _meta?: array<string, mixed>,
34: * requestId: int|non-empty-string,
35: * reason?: non-empty-string
36: * }
37: * }>
38: */
39: final readonly class CancelledNotification extends JsonRpcNotification implements ClientNotification, ServerNotification
40: {
41: /**
42: * @param RequestId $requestId A uniquely identifying ID for a request in JSON-RPC.
43: * This MUST correspond to the ID of a request previously issued in the same direction.
44: * @param null|non-empty-string $reason An optional string describing the reason for the cancellation.
45: * This MAY be logged or presented to the user.
46: * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach
47: * additional metadata to their interactions.
48: */
49: public function __construct(RequestId $requestId, ?string $reason = null, ?array $meta = null)
50: {
51: parent::__construct(self::JSON_RPC_VERSION, 'notifications/cancelled', array_filter([
52: '_meta' => $meta,
53: 'requestId' => $requestId->value,
54: 'reason' => $reason,
55: ], static fn(mixed $value): bool => null !== $value));
56: }
57: }
58: