|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Ecourty\McpServerBundle\Command; |
| 6 | + |
| 7 | +use Ecourty\McpServerBundle\Prompt\Argument; |
| 8 | +use Ecourty\McpServerBundle\Prompt\PromptDefinition; |
| 9 | +use Ecourty\McpServerBundle\Service\PromptRegistry; |
| 10 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 11 | +use Symfony\Component\Console\Command\Command; |
| 12 | +use Symfony\Component\Console\Input\InputArgument; |
| 13 | +use Symfony\Component\Console\Input\InputInterface; |
| 14 | +use Symfony\Component\Console\Output\OutputInterface; |
| 15 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 16 | + |
| 17 | +/** |
| 18 | + * Command to display information about MCP prompts. |
| 19 | + * |
| 20 | + * This command allows users to view details about specific MCP prompts or all available prompts. |
| 21 | + * It provides a table format for easy readability of prompts attributes such as name, description, and arguments. |
| 22 | + */ |
| 23 | +#[AsCommand( |
| 24 | + name: 'debug:mcp-prompts', |
| 25 | + description: 'Display current MCP prompts', |
| 26 | +)] |
| 27 | +class DebugMcpPromptsCommand extends Command |
| 28 | +{ |
| 29 | + public function __construct( |
| 30 | + private readonly PromptRegistry $promptRegistry, |
| 31 | + ) { |
| 32 | + parent::__construct(); |
| 33 | + } |
| 34 | + |
| 35 | + protected function configure(): void |
| 36 | + { |
| 37 | + $this |
| 38 | + ->addArgument('prompt', InputArgument::OPTIONAL, 'Prompt name'); |
| 39 | + } |
| 40 | + |
| 41 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 42 | + { |
| 43 | + $io = new SymfonyStyle($input, $output); |
| 44 | + |
| 45 | + $promptName = $input->getArgument('prompt'); |
| 46 | + |
| 47 | + if ($promptName !== null) { |
| 48 | + return $this->displaySinglePromptInformation($io, $promptName); |
| 49 | + } |
| 50 | + |
| 51 | + return $this->displayAllPromptsInformation($io); |
| 52 | + } |
| 53 | + |
| 54 | + private function displaySinglePromptInformation(SymfonyStyle $io, string $promptName): int |
| 55 | + { |
| 56 | + $prompt = $this->promptRegistry->getPromptDefinition($promptName); |
| 57 | + |
| 58 | + if ($prompt === null) { |
| 59 | + $io->error(\sprintf('Prompt "%s" not found.', $promptName)); |
| 60 | + |
| 61 | + return self::FAILURE; |
| 62 | + } |
| 63 | + |
| 64 | + $io->table( |
| 65 | + ['Name', 'Description', 'Arguments'], |
| 66 | + [ |
| 67 | + [ |
| 68 | + $prompt->name, |
| 69 | + $prompt->description, |
| 70 | + implode(', ', array_map(fn (Argument $argument) => $argument->name, $prompt->arguments ?? [])), |
| 71 | + ], |
| 72 | + ], |
| 73 | + ); |
| 74 | + |
| 75 | + return self::SUCCESS; |
| 76 | + } |
| 77 | + |
| 78 | + private function displayAllPromptsInformation(SymfonyStyle $io): int |
| 79 | + { |
| 80 | + $io->title('MCP Prompts Debug Information'); |
| 81 | + |
| 82 | + $promptsDefinitions = $this->promptRegistry->getPromptsDefinitions(); |
| 83 | + |
| 84 | + if (empty($promptsDefinitions) === true) { |
| 85 | + $io->warning('No prompts found.'); |
| 86 | + |
| 87 | + return self::SUCCESS; |
| 88 | + } |
| 89 | + |
| 90 | + $io->table( |
| 91 | + ['Name', 'Description', 'Arguments'], |
| 92 | + array_map(static function (PromptDefinition $prompt) { |
| 93 | + return [ |
| 94 | + $prompt->name, |
| 95 | + $prompt->description, |
| 96 | + implode(', ', array_map(fn (Argument $argument) => $argument->name, $prompt->arguments ?? [])), |
| 97 | + ]; |
| 98 | + }, $promptsDefinitions), |
| 99 | + ); |
| 100 | + |
| 101 | + return self::SUCCESS; |
| 102 | + } |
| 103 | +} |
0 commit comments