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\Enum\Action;
17:
18: /**
19: * The client's response to an elicitation request.
20: *
21: * @extends Result<array{
22: * _meta?: array<string, mixed>,
23: * action: 'accept'|'cancel'|'decline',
24: * content?: array<string, bool|int|string>,
25: * }>
26: */
27: final readonly class ElicitResult extends Result implements ClientResult
28: {
29: /**
30: * @param Action $action The user action in response to the elicitation.
31: * @param null|array<string, bool|int|string> $content The submitted form data, only present when action is
32: * “accept”. Contains values matching the requested schema.
33: */
34: public function __construct(
35: public Action $action,
36: public ?array $content = null,
37: ?array $meta = null,
38: ) {
39: if (Action::Accept === $this->action && null === $this->content) {
40: throw new \InvalidArgumentException('Content must be provided when action is "accept".');
41: }
42:
43: parent::__construct($meta);
44: }
45:
46: #[\Override]
47: public function toArray(): array
48: {
49: return array_filter([
50: '_meta' => $this->meta,
51: 'action' => $this->action->value,
52: 'content' => $this->content,
53: ], static fn(mixed $value): bool => null !== $value);
54: }
55: }
56: