| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Schema\Message; |
| 15: | |
| 16: | use Nexus\Mcp\Schema\Request\Request; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | abstract readonly class JsonRpcRequest extends Request |
| 31: | { |
| 32: | |
| 33: | |
| 34: | |
| 35: | public string $jsonrpc; |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | public function __construct( |
| 41: | string $jsonrpc, |
| 42: | public RequestId $id, |
| 43: | string $method, |
| 44: | ?array $params = null, |
| 45: | ) { |
| 46: | $this->validateJsonRpc($jsonrpc); |
| 47: | $this->jsonrpc = $jsonrpc; |
| 48: | |
| 49: | parent::__construct($method, $params); |
| 50: | } |
| 51: | |
| 52: | #[\Override] |
| 53: | public function toArray(): array |
| 54: | { |
| 55: | return array_filter([ |
| 56: | 'jsonrpc' => $this->jsonrpc, |
| 57: | 'id' => $this->id->value, |
| 58: | 'method' => $this->method, |
| 59: | 'params' => $this->params, |
| 60: | ], static fn(mixed $value): bool => null !== $value); |
| 61: | } |
| 62: | } |
| 63: | |