1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Schema\Result;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17: use Nexus\Mcp\Schema\Prompt\PromptMessage;
18:
19: /**
20: * The server's response to a `prompts/get` request from the client.
21: *
22: * @template T of array<string, mixed>
23: *
24: * @extends Result<array{
25: * _meta?: array<string, mixed>,
26: * messages: list<template-type<PromptMessage<T>, Arrayable, 'T'>>,
27: * description?: non-empty-string,
28: * }>
29: */
30: final readonly class GetPromptResult extends Result implements ServerResult
31: {
32: /**
33: * @param list<PromptMessage<T>> $messages
34: * @param null|non-empty-string $description
35: */
36: public function __construct(
37: public array $messages,
38: public ?string $description = null,
39: ?array $meta = null,
40: ) {
41: parent::__construct($meta);
42: }
43:
44: #[\Override]
45: public function toArray(): array
46: {
47: return array_filter([
48: '_meta' => $this->meta,
49: 'messages' => array_map(
50: static fn(PromptMessage $message): array => $message->toArray(),
51: $this->messages,
52: ),
53: 'description' => $this->description,
54: ], static fn(mixed $value): bool => null !== $value);
55: }
56: }
57: