1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 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\Core\Schema\RequestParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\RequestMetaObject;
18: use Nexus\Mcp\Core\Schema\RequestParams;
19: use Nexus\Mcp\Core\Validation\IdentifierNameValidator;
20:
21: /**
22: * Parameters for a `prompts/get` request.
23: *
24: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#getpromptrequestparams
25: */
26: final readonly class GetPromptRequestParams extends RequestParams
27: {
28: /**
29: * @var non-empty-string
30: */
31: public string $name;
32:
33: /**
34: * @var null|array<string, string>
35: */
36: public ?array $arguments;
37:
38: /**
39: * @param null|array<string, string> $arguments
40: */
41: public function __construct(string $name, ?array $arguments = null, RequestMetaObject $meta = new RequestMetaObject())
42: {
43: IdentifierNameValidator::validate($name, '"params.name"');
44:
45: if (null !== $arguments) {
46: Assert::that($arguments)
47: ->isMap('"params.arguments" must be a string-keyed map.')
48: ->values()->isString('"params.arguments" values must all be strings, {type} given.')
49: ;
50: }
51:
52: $this->name = $name;
53: $this->arguments = $arguments;
54:
55: parent::__construct($meta);
56: }
57:
58: /**
59: * @param array<string, mixed> $data
60: */
61: #[\Override]
62: public static function fromArray(array $data): static
63: {
64: Assert::that($data)->hasOffset('name', 'missing the required "name" key.');
65: $name = $data['name'];
66: Assert::that($name)->isString('"params.name" must be a string, {type} given.');
67:
68: $arguments = null;
69:
70: if (\array_key_exists('arguments', $data)) {
71: Assert::that($data['arguments'])
72: ->isArray('"params.arguments" must be an object, {type} given.')
73: ->isMap('"params.arguments" must be a string-keyed object.')
74: ->values()->isString('"params.arguments" value must be a string, {type} given.')
75: ;
76: $arguments = $data['arguments'];
77: }
78:
79: $meta = new RequestMetaObject();
80:
81: if (\array_key_exists('_meta', $data)) {
82: Assert::that($data['_meta'])
83: ->isArray('"params._meta" must be an object, {type} given.')
84: ->isMap('"params._meta" must be a string-keyed object.')
85: ;
86: $meta = RequestMetaObject::fromArray($data['_meta']);
87: }
88:
89: return new self($name, $arguments, $meta);
90: }
91:
92: #[\Override]
93: public function toArray(): array
94: {
95: $data = ['name' => $this->name];
96:
97: if ([] !== ($this->arguments ?? [])) {
98: $data['arguments'] = $this->arguments;
99: }
100:
101: return [...parent::toArray(), ...$data];
102: }
103:
104: #[\Override]
105: public function jsonSerialize(): array
106: {
107: return $this->toArray();
108: }
109: }
110: