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\Core\Transport;
15:
16: /**
17: * A transport that replaces its own connection in place, so the peer a caller writes to may be a
18: * different one from the peer it wrote to a moment ago.
19: */
20: interface ReconnectingTransportInterface extends TransportInterface
21: {
22: /**
23: * Registers a listener invoked once for every replacement connection that has started serving.
24: * It runs after the close emitted for the connection being replaced, and never for the first
25: * connection, which `start()` already reports.
26: *
27: * A protocol layer holding per-connection state uses this to rebuild it. The fresh peer has no
28: * memory of the old one, so anything the caller expects to survive must be re-sent.
29: *
30: * @param \Closure(): void $listener
31: */
32: public function onReconnect(\Closure $listener): SubscriptionInterface;
33:
34: /**
35: * Whether a replacement connection is still on its way. False on a live connection and false once the
36: * transport has stopped for good, whether it was closed or gave up.
37: *
38: * Answers "will what just failed be tried again?", so it is read when a per-connection operation fails,
39: * not before one is issued.
40: */
41: public function isReconnecting(): bool;
42: }
43: