jsonrpc = $jsonrpc; $this->id = $id; $this->result = $result; } /** * Creates an instance from an array. * * @param array{ * jsonrpc: '2.0', * id: string|number, * result: array|\WP\McpSchema\Common\Protocol\DTO\Result * } $data * @phpstan-param array $data * @return self */ public static function fromArray(array $data): self { self::assertRequired($data, ['jsonrpc', 'id', 'result']); /** @var '2.0' $jsonrpc */ $jsonrpc = self::asString($data['jsonrpc']); /** @var string|number $id */ $id = self::asStringOrNumber($data['id']); /** @var \WP\McpSchema\Common\Protocol\DTO\Result $result */ $result = is_array($data['result']) ? Result::fromArray(self::asArray($data['result'])) : $data['result']; return new self( $jsonrpc, $id, $result ); } /** * Converts the instance to an array. * * @return array */ public function toArray(): array { $result = []; $result['jsonrpc'] = $this->jsonrpc; $result['id'] = $this->id; $result['result'] = $this->result->toArray(); return $result; } /** * @return '2.0' */ public function getJsonrpc(): string { return $this->jsonrpc; } /** * @return string|number */ public function getId() { return $this->id; } /** * @return \WP\McpSchema\Common\Protocol\DTO\Result */ public function getResult(): Result { return $this->result; } }