-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add external MCP server integration for enhance prompt #6633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,14 @@ const baseProviderSettingsSchema = z.object({ | |
| reasoningEffort: reasoningEffortsSchema.optional(), | ||
| modelMaxTokens: z.number().optional(), | ||
| modelMaxThinkingTokens: z.number().optional(), | ||
|
|
||
| // External MCP server settings for enhance prompt | ||
| enhancePrompt: z | ||
| .object({ | ||
| useExternalServer: z.boolean().optional(), | ||
| endpoint: z.string().url().optional(), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For production use, should we restrict the endpoint to HTTPS only? Also, consider if we need to support authentication headers for secured endpoints in the future. |
||
| }) | ||
| .optional(), | ||
| }) | ||
|
|
||
| // Several of the providers share common model config properties. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||
| import { ProviderSettings, ClineMessage, GlobalState, TelemetryEventName } from "@roo-code/types" | ||||||||||||||||||||||||||||||||||||
| import { ProviderSettings, ClineMessage, GlobalState, TelemetryEventName, getModelId } from "@roo-code/types" | ||||||||||||||||||||||||||||||||||||
| import { TelemetryService } from "@roo-code/telemetry" | ||||||||||||||||||||||||||||||||||||
| import { supportPrompt } from "../../shared/support-prompt" | ||||||||||||||||||||||||||||||||||||
| import { singleCompletionHandler } from "../../utils/single-completion-handler" | ||||||||||||||||||||||||||||||||||||
|
|
@@ -58,6 +58,55 @@ export class MessageEnhancer { | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Check if external MCP server is enabled | ||||||||||||||||||||||||||||||||||||
| if (configToUse.enhancePrompt?.useExternalServer && configToUse.enhancePrompt?.endpoint) { | ||||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great implementation! Just a thought - should we add UI components to configure these settings in the settings panel? Currently users would need to manually edit their settings.json. We could add controls similar to other provider settings. |
||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||
| // Prepare context messages for external server | ||||||||||||||||||||||||||||||||||||
| const contextMessages = | ||||||||||||||||||||||||||||||||||||
| currentClineMessages | ||||||||||||||||||||||||||||||||||||
| ?.filter((msg) => { | ||||||||||||||||||||||||||||||||||||
| if (msg.type === "ask" && msg.text) return true | ||||||||||||||||||||||||||||||||||||
| if (msg.type === "say" && msg.say === "text" && msg.text) return true | ||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||
| .slice(-10) | ||||||||||||||||||||||||||||||||||||
| .map((msg) => ({ | ||||||||||||||||||||||||||||||||||||
| role: msg.type === "ask" ? "user" : "assistant", | ||||||||||||||||||||||||||||||||||||
| content: msg.text || "", | ||||||||||||||||||||||||||||||||||||
| })) || [] | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Make request to external MCP server | ||||||||||||||||||||||||||||||||||||
| const response = await fetch(configToUse.enhancePrompt.endpoint, { | ||||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a timeout to prevent hanging requests. You could use AbortController:
Suggested change
|
||||||||||||||||||||||||||||||||||||
| method: "POST", | ||||||||||||||||||||||||||||||||||||
| headers: { "Content-Type": "application/json" }, | ||||||||||||||||||||||||||||||||||||
| body: JSON.stringify({ | ||||||||||||||||||||||||||||||||||||
| prompt: text, | ||||||||||||||||||||||||||||||||||||
| context: contextMessages, | ||||||||||||||||||||||||||||||||||||
| model: getModelId(configToUse) || "unknown", | ||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||||||||||||||||||||
| throw new Error(`External server returned ${response.status}: ${response.statusText}`) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const result = await response.json() | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (result.enhancedPrompt) { | ||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||
| enhancedText: result.enhancedPrompt, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| throw new Error("External server response missing 'enhancedPrompt' field") | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||||||||||||||
| console.error("Failed to enhance prompt via external server:", err) | ||||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error logging could be more descriptive to help with debugging. Consider:
Suggested change
|
||||||||||||||||||||||||||||||||||||
| // Fallback to default logic | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Default internal enhancement logic | ||||||||||||||||||||||||||||||||||||
| // Prepare the prompt to enhance | ||||||||||||||||||||||||||||||||||||
| let promptToEnhance = text | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding JSDoc comments to document these new settings: