Elffuss BraidHub

kikocis/continue public

d1cdc8b8ac2b · 926 BRawPermalink
1import { SlashCommandDescWithSource } from "core";
2import { IIdeMessenger } from "../../../../context/IdeMessenger";
3
4export async function renderMcpPrompt(
5 command: SlashCommandDescWithSource,
6 ideMessenger: IIdeMessenger,
7 userInput?: string,
8) {
9 // TODO add support for mcp prompt args using command.mcpArgs
10 const args: { [key: string]: string } = {};
11 if (command.mcpArgs) {
12 command.mcpArgs.forEach((arg, i) => {
13 args[arg.name] = "";
14 });
15 }
16 const response = await ideMessenger.request("mcp/getPrompt", {
17 serverName: command.mcpServerName!,
18 promptName: command.name,
19 args: args,
20 });
21 if (response.status === "success") {
22 let renderedPrompt = response.content.prompt;
23 if (userInput) {
24 renderedPrompt += `\n\n${userInput}`;
25 }
26 return renderedPrompt;
27 } else {
28 throw new Error(
29 `Failed to get MCP prompt for slash command ${command.name}`,
30 );
31 }
32}