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\Prompt;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17: use Nexus\Mcp\Schema\BaseMetadata;
18: use Nexus\Mcp\Schema\Icon;
19:
20: /**
21: * A prompt or prompt template that the server offers.
22: *
23: * @extends BaseMetadata<array{
24: * _meta?: array<string, mixed>,
25: * name: non-empty-string,
26: * title?: non-empty-string,
27: * description?: non-empty-string,
28: * arguments?: list<template-type<PromptArgument, BaseMetadata, 'T'>>,
29: * icons?: list<template-type<Icon, Arrayable, 'T'>>,
30: * }>
31: */
32: final readonly class Prompt extends BaseMetadata
33: {
34: /**
35: * @param null|non-empty-string $description An optional description of what this prompt provides.
36: * @param null|list<PromptArgument> $arguments A list of arguments to use for templating the prompt.
37: * @param null|list<Icon> $icons Optional set of sized icons that the client can display in a user interface.
38: * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach
39: * additional metadata to their interactions.
40: */
41: public function __construct(
42: string $name,
43: ?string $title = null,
44: public ?string $description = null,
45: public ?array $arguments = null,
46: public ?array $icons = null,
47: public ?array $meta = null,
48: ) {
49: parent::__construct($name, $title);
50: }
51:
52: #[\Override]
53: public function toArray(): array
54: {
55: return array_filter([
56: '_meta' => $this->meta,
57: 'name' => $this->name,
58: 'title' => $this->title,
59: 'description' => $this->description,
60: 'arguments' => null === $this->arguments ? null : array_map(
61: static fn(PromptArgument $arg): array => $arg->toArray(),
62: $this->arguments,
63: ),
64: 'icons' => null === $this->icons ? null : array_map(
65: static fn(Icon $icon): array => $icon->toArray(),
66: $this->icons,
67: ),
68: ], static fn(mixed $value): bool => null !== $value);
69: }
70: }
71: