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: /**
17: * The server's response to a `completion/complete` request.
18: *
19: * @extends Result<array{
20: * _meta?: array<string, mixed>,
21: * completion: array{hasMore?: bool, total?: int<0, max>, values: list<string>},
22: * }>
23: */
24: final readonly class CompleteResult extends Result implements ServerResult
25: {
26: /**
27: * @var array{hasMore?: bool, total?: int<0, max>, values: list<string>}
28: */
29: public array $completion;
30:
31: /**
32: * @param list<string> $values An array of completion values. Must not exceed 100 items.
33: * @param null|int<0, max> $total The total number of completion options available. This can exceed
34: * the number of values actually sent in the response.
35: * @param null|bool $hasMore Indicates whether there are additional completion options beyond those
36: * provided in the current response, even if the exact total is unknown.
37: */
38: public function __construct(array $values, ?int $total = null, ?bool $hasMore = null, ?array $meta = null)
39: {
40: if (\count($values) > 100) {
41: throw new \InvalidArgumentException('The number of completion values must not exceed 100 items.');
42: }
43:
44: $this->completion = array_filter([
45: 'hasMore' => $hasMore,
46: 'total' => $total,
47: 'values' => $values,
48: ], static fn(mixed $value): bool => null !== $value);
49:
50: parent::__construct($meta);
51: }
52:
53: #[\Override]
54: public function toArray(): array
55: {
56: return array_filter([
57: '_meta' => $this->meta,
58: 'completion' => $this->completion,
59: ], static fn(mixed $value): bool => null !== $value);
60: }
61: }
62: