* Loads all available prompts from all configured MCP servers and adapts * them into executable SlashCommand objects. * * @param _signal An AbortSignal (unused for this synchronous loader). * @returns A promise that resolves to an array of loaded SlashCommands.
(_signal: AbortSignal)
| 34 | * @returns A promise that resolves to an array of loaded SlashCommands. |
| 35 | */ |
| 36 | loadCommands(_signal: AbortSignal): Promise<SlashCommand[]> { |
| 37 | const promptCommands: SlashCommand[] = []; |
| 38 | if (!this.config) { |
| 39 | return Promise.resolve([]); |
| 40 | } |
| 41 | const mcpServers = this.config.getMcpServers() || {}; |
| 42 | for (const serverName in mcpServers) { |
| 43 | const prompts = getMCPServerPrompts(this.config, serverName) || []; |
| 44 | for (const prompt of prompts) { |
| 45 | const commandName = `${prompt.name}`; |
| 46 | const newPromptCommand: SlashCommand = { |
| 47 | name: commandName, |
| 48 | description: prompt.description || `Invoke prompt ${prompt.name}`, |
| 49 | kind: CommandKind.MCP_PROMPT, |
| 50 | subCommands: [ |
| 51 | { |
| 52 | name: 'help', |
| 53 | description: 'Show help for this prompt', |
| 54 | kind: CommandKind.MCP_PROMPT, |
| 55 | action: async (): Promise<SlashCommandActionReturn> => { |
| 56 | if (!prompt.arguments || prompt.arguments.length === 0) { |
| 57 | return { |
| 58 | type: 'message', |
| 59 | messageType: 'info', |
| 60 | content: `Prompt "${prompt.name}" has no arguments.`, |
| 61 | }; |
| 62 | } |
| 63 | |
| 64 | let helpMessage = `Arguments for "${prompt.name}":\n\n`; |
| 65 | if (prompt.arguments && prompt.arguments.length > 0) { |
| 66 | helpMessage += `You can provide arguments by name (e.g., --argName="value") or by position.\n\n`; |
| 67 | helpMessage += `e.g., ${prompt.name} ${prompt.arguments?.map((_) => `"foo"`)} is equivalent to ${prompt.name} ${prompt.arguments?.map((arg) => `--${arg.name}="foo"`)}\n\n`; |
| 68 | } |
| 69 | for (const arg of prompt.arguments) { |
| 70 | helpMessage += ` --${arg.name}\n`; |
| 71 | if (arg.description) { |
| 72 | helpMessage += ` ${arg.description}\n`; |
| 73 | } |
| 74 | helpMessage += ` (required: ${ |
| 75 | arg.required ? 'yes' : 'no' |
| 76 | })\n\n`; |
| 77 | } |
| 78 | return { |
| 79 | type: 'message', |
| 80 | messageType: 'info', |
| 81 | content: helpMessage, |
| 82 | }; |
| 83 | }, |
| 84 | }, |
| 85 | ], |
| 86 | action: async ( |
| 87 | context: CommandContext, |
| 88 | args: string, |
| 89 | ): Promise<SlashCommandActionReturn> => { |
| 90 | if (!this.config) { |
| 91 | return { |
| 92 | type: 'message', |
| 93 | messageType: 'error', |
nothing calls this directly
no test coverage detected