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\Server\Subscription;
15:
16: use Nexus\Mcp\Core\Handler\SenderInterface;
17: use Nexus\Mcp\Core\Schema\RequestId;
18: use Nexus\Mcp\Core\Schema\SubscriptionFilter;
19: use Nexus\Mcp\Server\Exception\SubscriptionLimitReachedException;
20:
21: /**
22: * Holds the open `subscriptions/listen` streams and fans server-side events out to the ones that asked for them.
23: */
24: interface SubscriptionStoreInterface
25: {
26: /**
27: * Opens a stream, acknowledging it before it becomes visible to any emit.
28: *
29: * @param RequestId $subscriptionId Id every message on the stream carries, as the client sent it
30: * @param null|non-empty-string $peer Stable peer identity for the per-peer budget, null when the transport cannot supply one
31: *
32: * @throws SubscriptionLimitReachedException
33: */
34: public function open(RequestId $subscriptionId, SubscriptionFilter $requested, SenderInterface $sender, ?string $peer = null): SubscriptionEntry;
35:
36: /**
37: * Narrows `$requested` to the notification types this store delivers, omitting rather than
38: * falsifying the ones it does not honour.
39: */
40: public function honour(SubscriptionFilter $requested): SubscriptionFilter;
41:
42: /**
43: * Tears `$entry` down, naming the ending `subscriptions/listen` to the client and releasing the
44: * handler, and does nothing for a stream already gone.
45: */
46: public function close(SubscriptionEntry $entry): void;
47:
48: /**
49: * Deregisters `$entry` without announcing anything, for a stream the client already abandoned.
50: */
51: public function discard(SubscriptionEntry $entry): void;
52:
53: /**
54: * Closes every open stream so the server can drain, settling any opened afterwards at once.
55: */
56: public function closeAll(): void;
57:
58: /**
59: * Clears the drained state left by `closeAll()`, so a store reused on a new transport serves live streams again.
60: */
61: public function reopen(): void;
62:
63: public function emitToolListChanged(): void;
64:
65: public function emitPromptListChanged(): void;
66:
67: public function emitResourceListChanged(): void;
68:
69: /**
70: * Announces that the contents behind `$uri` changed, to the streams subscribed to that URI.
71: */
72: public function emitResourceUpdated(string $uri): void;
73: }
74: