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\Request;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest;
18: use Nexus\Mcp\Core\Schema\Request\ClientRequest;
19: use Nexus\Mcp\Core\Schema\RequestId;
20: use Nexus\Mcp\Core\Schema\RequestParams;
21: use Nexus\Mcp\Extension\Skills\Schema\RequestParams\GetSkillRequestParams;
22:
23: /**
24: * Sent from the client to request the entry of one skill, named by the URI of its `SKILL.md`.
25: *
26: * @property-read GetSkillRequestParams $params
27: *
28: * @extends JsonRpcRequest<'skills/get', array{
29: * jsonrpc: '2.0',
30: * id: int|non-empty-string,
31: * method: 'skills/get',
32: * params: template-type<GetSkillRequestParams, RequestParams, 'T'>,
33: * }>
34: *
35: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/seps/2640-skills-extension.md
36: */
37: final readonly class GetSkillRequest extends JsonRpcRequest implements ClientRequest
38: {
39: public function __construct(RequestId $id, GetSkillRequestParams $params)
40: {
41: parent::__construct(id: $id, params: $params);
42: }
43:
44: #[\Override]
45: public static function getMethod(): string
46: {
47: return 'skills/get';
48: }
49:
50: #[\Override]
51: public static function fromArray(array $data): static
52: {
53: Assert::that($data)->hasOffset('id', 'missing the required "id" key.');
54: $id = $data['id'];
55: Assert::that($id)->isIntOrNonEmptyString('"id" must be an int or non-empty string, {type} given.');
56:
57: Assert::that($data)->hasOffset('params', 'missing the required "params" key.');
58: Assert::that($data['params'])
59: ->isArray('"params" must be an object, {type} given.')
60: ->isMap('"params" must be a string-keyed object.')
61: ;
62:
63: return new self(id: new RequestId(id: $id), params: GetSkillRequestParams::fromArray($data['params']));
64: }
65:
66: #[\Override]
67: public function toArray(): array
68: {
69: return [
70: 'jsonrpc' => self::JSONRPC_VERSION,
71: 'id' => $this->id->id,
72: 'method' => self::getMethod(),
73: 'params' => $this->params->toArray(),
74: ];
75: }
76: }
77: