| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Dispatch; |
| 15: | |
| 16: | use Nexus\Mcp\Core\Exception\OutboundRequestsNotSupportedException; |
| 17: | use Nexus\Mcp\Core\Handler\SenderInterface; |
| 18: | use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcNotification; |
| 19: | use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest; |
| 20: | use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcResultResponse; |
| 21: | use Nexus\Mcp\Core\Schema\RequestId; |
| 22: | use Nexus\Mcp\Core\Transport\SendContext; |
| 23: | use Nexus\Mcp\Core\Transport\TransportInterface; |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | final readonly class RequestBoundSender implements SenderInterface |
| 31: | { |
| 32: | private SendContext $outboundContext; |
| 33: | |
| 34: | public function __construct(private TransportInterface $transport, private RequestId $requestId) |
| 35: | { |
| 36: | $this->outboundContext = new SendContext(relatedRequestId: $this->requestId); |
| 37: | } |
| 38: | |
| 39: | #[\Override] |
| 40: | public function sendNotification(JsonRpcNotification $notification): void |
| 41: | { |
| 42: | $this->transport->send($notification, $this->outboundContext); |
| 43: | } |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | #[\Override] |
| 51: | public function sendRequest(JsonRpcRequest $request): JsonRpcResultResponse |
| 52: | { |
| 53: | throw new OutboundRequestsNotSupportedException($this->requestId); |
| 54: | } |
| 55: | } |
| 56: | |