| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Server\Prompt; |
| 15: | |
| 16: | use Nexus\Mcp\Core\Schema\Cursor; |
| 17: | use Nexus\Mcp\Core\Schema\Prompt\Prompt; |
| 18: | use Nexus\Mcp\Core\Schema\Result\GetPromptResult; |
| 19: | use Nexus\Mcp\Core\Schema\Result\ListPromptsResult; |
| 20: | use Nexus\Mcp\Server\AbstractPaginatedStore; |
| 21: | use Nexus\Mcp\Server\Exception\PromptNotFoundException; |
| 22: | use Nexus\Mcp\Server\ServerContext; |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | final readonly class PromptStore extends AbstractPaginatedStore implements PromptStoreInterface |
| 30: | { |
| 31: | protected const string STORE_LABEL = 'Prompt store'; |
| 32: | |
| 33: | #[\Override] |
| 34: | public function list(?Cursor $cursor): ListPromptsResult |
| 35: | { |
| 36: | return $this->paginate( |
| 37: | $cursor, |
| 38: | static fn(PromptEntry $entry): Prompt => $entry->prompt, |
| 39: | static fn(array $prompts, ?Cursor $nextCursor): ListPromptsResult => new ListPromptsResult($prompts, $nextCursor), |
| 40: | ); |
| 41: | } |
| 42: | |
| 43: | #[\Override] |
| 44: | public function get(string $name, ?array $arguments, ServerContext $context): GetPromptResult |
| 45: | { |
| 46: | if (! \array_key_exists($name, $this->entries)) { |
| 47: | throw new PromptNotFoundException($name, $context->requestId); |
| 48: | } |
| 49: | |
| 50: | return $this->entries[$name]->renderer->render($arguments, $context); |
| 51: | } |
| 52: | } |
| 53: | |