Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 3, 2025

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

  • Added enhancePrompt object with:
    • useExternalServer: boolean to enable/disable external server
    • endpoint: URL string for the external MCP server endpoint

2. Updated MessageEnhancer

  • Added logic to check for external server configuration
  • Routes enhancement requests to external server when enabled
  • Includes context messages in the request payload
  • Falls back to default internal enhancement on failure
  • Uses getModelId helper for consistent model ID extraction

3. Added comprehensive tests

  • Tests for successful external server enhancement
  • Tests for context message inclusion
  • Tests for various fallback scenarios (network errors, non-ok responses, missing fields)
  • Tests for configuration validation
  • Tests for different provider model ID fields

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

  • All existing tests pass
  • Added 8 new tests for external MCP server functionality
  • TypeScript compilation successful
  • Linting checks pass

Fixes #6631


Important

Adds external MCP server integration to MessageEnhancer with fallback to internal enhancement and updates provider settings schema.

  • Behavior:
    • Adds external MCP server integration to MessageEnhancer in messageEnhancer.ts.
    • Routes enhancement requests to external server if useExternalServer is true and endpoint is set.
    • Falls back to internal enhancement if external server fails or response is invalid.
    • Includes context messages in external server requests.
  • Settings:
    • Adds enhancePrompt object to provider-settings.ts with useExternalServer and endpoint fields.
  • Tests:
    • Adds tests in messageEnhancer.test.ts for external server usage, context inclusion, and fallback scenarios.
    • Tests handle network errors, non-ok responses, and missing fields in server response.

This description was created by Ellipsis for bfa3929. You can customize this summary. It will automatically update as commits are pushed.

- 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
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 3, 2025 21:04
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Aug 3, 2025
Copy link
Contributor Author

@roomote roomote bot left a 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
Copy link
Contributor Author

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:

Suggested change
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)
Copy link
Contributor Author

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:

Suggested change
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",
Copy link
Contributor Author

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:

Suggested change
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 {
Copy link
Contributor Author

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(),
Copy link
Contributor Author

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.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 3, 2025
@daniel-lxs
Copy link
Member

Not approved yet, closing

@daniel-lxs daniel-lxs closed this Aug 4, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 4, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

External MCP Server Integration for "Enhance Prompt

4 participants