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
23: * for them.
24: */
25: interface SubscriptionStoreInterface
26: {
27: /**
28: * Opens a stream, acknowledging it before it becomes visible to any emit.
29: *
30: * @param RequestId $subscriptionId Id every message on the stream carries, as the client sent it
31: *
32: * @throws SubscriptionLimitReachedException when the store already holds its maximum open streams
33: */
34: public function open(RequestId $subscriptionId, SubscriptionFilter $requested, SenderInterface $sender): SubscriptionEntry;
35:
36: /**
37: * Narrows `$requested` to the notification types this store delivers. The spec omits the types it does
38: * not honour rather than reporting them false.
39: */
40: public function honour(SubscriptionFilter $requested): SubscriptionFilter;
41:
42: /**
43: * Tears `$entry` down: tells the client which `subscriptions/listen` is ending, then releases the
44: * handler holding it open. Does nothing for a stream that is 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, releasing each handler so the server can drain. Streams opened afterwards
55: * are settled at once rather than held.
56: */
57: public function closeAll(): void;
58:
59: public function emitToolListChanged(): void;
60:
61: public function emitPromptListChanged(): void;
62:
63: public function emitResourceListChanged(): void;
64:
65: /**
66: * Announces that the contents behind `$uri` changed, to the streams subscribed to that URI.
67: */
68: public function emitResourceUpdated(string $uri): void;
69: }
70: