Elffuss BraidHub

kikocis/continue public

move render mcp prompt into its own file
Changeset24ab09d466aebb813791730c68e755b4ee58331f20fb7b3c761c6058968af020
AuthorDallin Romney <dallinromney@gmail.com> · 2025-06-27 17:26 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-06-27 17:26 -07:00
Parents409299863087

Browse the files at this changeset

2 files changed

added gui/src/components/mainInput/TipTapEditor/utils/renderMcpPrompt.ts +32 −0
@@ -0,0 +1,32 @@
1+import { SlashCommandDescWithSource } from "core";
2+import { IIdeMessenger } from "../../../../context/IdeMessenger";
3+
4+export 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+}
modified gui/src/components/mainInput/TipTapEditor/utils/renderSlashCommand.ts +16 −26
@@ -1,6 +1,7 @@
11 import { MessagePart, RangeInFile, SlashCommandDescWithSource } from "core";
22 import { stripImages } from "core/util/messageContent";
33 import { IIdeMessenger } from "../../../../context/IdeMessenger";
4+import { renderMcpPrompt } from "./mcpPromptArgs";
45 import { getRenderedV1Prompt } from "./renderPromptv1";
56 import { getPromptV2ContextRequests } from "./renderPromptv2";
67 import { GetContextRequest } from "./types";
@@ -63,32 +64,20 @@
6364 });
6465 break;
6566 case "mcp-prompt":
66- // TODO add support for mcp prompt args using command.mcpArgs
67- const args: { [key: string]: string } = {};
68- if (command.mcpArgs) {
69- command.mcpArgs.forEach((arg, i) => {
70- args[arg.name] = "";
71- });
72- }
73- const response = await ideMessenger.request("mcp/getPrompt", {
74- serverName: command.mcpServerName!,
75- promptName: command.name,
76- args: args,
67+ const renderedMcpPrompt = await renderMcpPrompt(
68+ command,
69+ ideMessenger,
70+ userInput,
71+ );
72+ slashedParts.push({
73+ type: "text",
74+ text: renderedMcpPrompt,
7775 });
78- if (response.status === "success") {
79- slashedParts.push({
80- type: "text",
81- text: `${response.content.prompt}${userInput ? "\n\n" + userInput : ""}`,
82- });
83- } else {
84- throw new Error(
85- `Failed to get MCP prompt for slash command ${command.name}`,
86- );
87- }
8876 break;
8977 case "prompt-file-v1":
9078 case "prompt-file-v2":
9179 case "yaml-prompt-block":
80+ case "invokable-rule":
9281 if (!command.prompt) {
9382 console.warn(`Invalid/empty prompt from slash command ${command.name}`);
9483 break;
@@ -110,13 +99,13 @@
11099 command,
111100 );
112101 contextRequests.push(...promptFileCtxRequests);
113- renderedPrompt = [command.prompt, userInput].join("\n\n");
102+ renderedPrompt = [command.prompt, userInput].join("\n\n").trim();
114103 }
115104
116105 if (renderedPrompt) {
117106 slashedParts.push({
118107 type: "text",
119- text: renderedPrompt.trim(), // Includes user input
108+ text: renderedPrompt, // Includes user input
120109 });
121110 } else {
122111 console.warn(
@@ -126,14 +115,15 @@
126115
127116 break;
128117 case "built-in":
129- case "invokable-rule":
130118 case "json-custom-command":
131119 if (!command.prompt) {
132120 console.warn(`Slash command ${command.name} is missing prompt`);
133121 break;
134122 }
135- const rendered =
136- `${command.prompt}${userInput ? "\n\n" + userInput : ""}`.trim();
123+ let rendered = command.prompt;
124+ if (userInput) {
125+ rendered += `\n\n${userInput}`;
126+ }
137127 if (rendered) {
138128 slashedParts.push({
139129 type: "text",