| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema\JsonRpc; |
| 15: | |
| 16: | use Nexus\Mcp\Core\Schema\Arrayable; |
| 17: | use Nexus\Mcp\Core\Schema\Request; |
| 18: | use Nexus\Mcp\Core\Schema\RequestId; |
| 19: | use Nexus\Mcp\Core\Schema\RequestParamsInterface; |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | abstract readonly class JsonRpcRequest extends Request implements Arrayable, JsonRpcMessage |
| 33: | { |
| 34: | public function __construct(public RequestId $id, ?RequestParamsInterface $params = null) |
| 35: | { |
| 36: | parent::__construct(params: $params); |
| 37: | } |
| 38: | |
| 39: | #[\Override] |
| 40: | public function jsonSerialize(): array |
| 41: | { |
| 42: | $envelope = [ |
| 43: | 'jsonrpc' => self::JSONRPC_VERSION, |
| 44: | 'id' => $this->id->id, |
| 45: | 'method' => static::getMethod(), |
| 46: | ]; |
| 47: | |
| 48: | if (null !== $this->params) { |
| 49: | $envelope['params'] = $this->params->jsonSerialize(); |
| 50: | } |
| 51: | |
| 52: | return $envelope; |
| 53: | } |
| 54: | } |
| 55: | |