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\Extension\Skills\Schema\RequestParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\MetaObject;
18: use Nexus\Mcp\Core\Schema\MetaObject\RequestMetaObject;
19: use Nexus\Mcp\Core\Schema\RequestParams;
20:
21: /**
22: * Parameters for a `skills/get` request.
23: *
24: * @extends RequestParams<array{
25: * _meta: template-type<RequestMetaObject, MetaObject, 'T'>,
26: * uri: non-empty-string,
27: * }>
28: *
29: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/seps/2640-skills-extension.md
30: */
31: final readonly class GetSkillRequestParams extends RequestParams
32: {
33: /**
34: * @param non-empty-string $uri URI of the skill's `SKILL.md`
35: */
36: public function __construct(
37: public string $uri,
38: RequestMetaObject $meta,
39: ) {
40: Assert::that($uri)->isNonEmptyString('"params.uri" must be a non-empty string.');
41:
42: parent::__construct(meta: $meta);
43: }
44:
45: #[\Override]
46: public static function fromArray(array $data): static
47: {
48: Assert::that($data)->hasOffset('uri', '"params" is missing the required "uri" key.');
49: $uri = $data['uri'];
50: Assert::that($uri)->isNonEmptyString('"params.uri" must be a non-empty string, {type} given.');
51:
52: Assert::that($data)->hasOffset('_meta', '"params" is missing the required "_meta" key.');
53: Assert::that($data['_meta'])
54: ->isArray('"params._meta" must be an object, {type} given.')
55: ->not()->isNonEmptyList('"params._meta" must be a string-keyed object.')
56: ;
57:
58: return new self(uri: $uri, meta: RequestMetaObject::fromArray($data['_meta']));
59: }
60:
61: #[\Override]
62: public function toArray(): array
63: {
64: return [
65: '_meta' => $this->meta->toArray(),
66: 'uri' => $this->uri,
67: ];
68: }
69: }
70: