*/ class InitializeResult implements ResultInterface { /** * Create a new InitializeResult. * * @param ServerCapabilities $capabilities the capabilities of the server * @param Implementation $serverInfo information about the server * @param string|null $instructions Instructions describing how to use the server and its features. This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt. * @param array|null $_meta optional _meta field */ public function __construct( public readonly ServerCapabilities $capabilities, public readonly Implementation $serverInfo, public readonly ?string $instructions = null, public readonly ?array $_meta = null, public readonly ?ProtocolVersion $protocolVersion = null, ) { } /** * @param array{ * protocolVersion: string, * capabilities: array, * serverInfo: array, * instructions?: string, * _meta?: array, * } $data */ public static function fromArray(array $data): self { if (!isset($data['protocolVersion']) || !\is_string($data['protocolVersion'])) { throw new InvalidArgumentException('Missing or invalid "protocolVersion".'); } if (!isset($data['capabilities']) || !\is_array($data['capabilities'])) { throw new InvalidArgumentException('Missing or invalid "capabilities".'); } if (!isset($data['serverInfo']) || !\is_array($data['serverInfo'])) { throw new InvalidArgumentException('Missing or invalid "serverInfo".'); } return new self( ServerCapabilities::fromArray($data['capabilities']), Implementation::fromArray($data['serverInfo']), $data['instructions'] ?? null, $data['_meta'] ?? null, ProtocolVersion::tryFrom($data['protocolVersion']), ); } /** * @return array{ * protocolVersion: string, * capabilities: ServerCapabilities, * serverInfo: Implementation, * instructions?: string, * _meta?: array, * } */ public function jsonSerialize(): array { $protocolVersion = $this->protocolVersion ?? MessageInterface::PROTOCOL_VERSION; $data = [ 'protocolVersion' => $protocolVersion->value, 'capabilities' => $this->capabilities, 'serverInfo' => $this->serverInfo, ]; if (null !== $this->instructions) { $data['instructions'] = $this->instructions; } if (null !== $this->_meta) { $data['_meta'] = $this->_meta; } return $data; } }