-
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
Conversation
- Add enhancePrompt settings to provider-settings schema with useExternalServer and endpoint options - Update MessageEnhancer to check for external server configuration and route requests accordingly - Add comprehensive tests for external MCP server functionality including fallback behavior - Import and use getModelId helper for consistent model ID extraction across providers Fixes #6631
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.
I reviewed my own code and found it surprisingly coherent. The machines are learning.
| modelMaxThinkingTokens: z.number().optional(), | ||
|
|
||
| // External MCP server settings for enhance prompt | ||
| enhancePrompt: z |
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:
| enhancePrompt: z | |
| // External MCP server settings for enhance prompt | |
| /** | |
| * Configuration for external MCP server integration | |
| * @property {boolean} useExternalServer - Enable routing enhancement requests to external server | |
| * @property {string} endpoint - URL endpoint of the external MCP server | |
| */ | |
| enhancePrompt: z |
| throw new Error("External server response missing 'enhancedPrompt' field") | ||
| } | ||
| } catch (err) { | ||
| console.error("Failed to enhance prompt via external server:", err) |
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.
The error logging could be more descriptive to help with debugging. Consider:
| console.error("Failed to enhance prompt via external server:", err) | |
| } catch (err) { | |
| console.error(`Failed to enhance prompt via external server (${configToUse.enhancePrompt.endpoint}):`, err) | |
| // Fallback to default logic |
|
|
||
| // Make request to external MCP server | ||
| const response = await fetch(configToUse.enhancePrompt.endpoint, { | ||
| method: "POST", |
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 a timeout to prevent hanging requests. You could use AbortController:
| const response = await fetch(configToUse.enhancePrompt.endpoint, { | |
| // Make request to external MCP server | |
| const controller = new AbortController() | |
| const timeoutId = setTimeout(() => controller.abort(), 10000) // 10 second timeout | |
| const response = await fetch(configToUse.enhancePrompt.endpoint, { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| signal: controller.signal, | |
| body: JSON.stringify({ | |
| prompt: text, | |
| context: contextMessages, | |
| model: getModelId(configToUse) || "unknown", | |
| }), | |
| }) | |
| clearTimeout(timeoutId) |
|
|
||
| // Check if external MCP server is enabled | ||
| if (configToUse.enhancePrompt?.useExternalServer && configToUse.enhancePrompt?.endpoint) { | ||
| try { |
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.
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.
| enhancePrompt: z | ||
| .object({ | ||
| useExternalServer: z.boolean().optional(), | ||
| endpoint: z.string().url().optional(), |
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.
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.
|
Not approved yet, closing |
Summary
This PR implements external MCP (Model Context Protocol) server integration for the "Enhance Prompt" functionality in RooCode, as requested in #6631.
Changes
1. Added new settings to provider-settings schema
enhancePromptobject with:useExternalServer: boolean to enable/disable external serverendpoint: URL string for the external MCP server endpoint2. Updated MessageEnhancer
getModelIdhelper for consistent model ID extraction3. Added comprehensive tests
API Contract
When external server is enabled, MessageEnhancer sends a POST request to the configured endpoint with:
{ "prompt": "raw user prompt", "context": [ { "role": "user", "content": "..." }, { "role": "assistant", "content": "..." } ], "model": "model-id" }Expected response:
{ "enhancedPrompt": "enhanced prompt text" }Benefits
✅ Allows prompt enhancement logic to be modular and externalized
✅ Supports local DSPy servers, memory augmentation, and custom enhancement pipelines
✅ Makes RooCode more extensible for power users and enterprise setups
✅ Fully backward compatible - feature is opt-in via settings
✅ Graceful fallback to internal enhancement if external server fails
Testing
Fixes #6631
Important
Adds external MCP server integration to
MessageEnhancerwith fallback to internal enhancement and updates provider settings schema.MessageEnhancerinmessageEnhancer.ts.useExternalServeris true andendpointis set.enhancePromptobject toprovider-settings.tswithuseExternalServerandendpointfields.messageEnhancer.test.tsfor external server usage, context inclusion, and fallback scenarios.This description was created by
for bfa3929. You can customize this summary. It will automatically update as commits are pushed.