Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 15, 2025

Summary

This PR implements support for MCP (Model Context Protocol) server prompts within RooCode, allowing users to discover and use prompts provided by MCP servers through the existing slash command interface.

Fixes #8004

Changes

Core Implementation

  • Added MCP prompt types to src/shared/mcp.ts:

    • McpPrompt, McpPromptArgument, McpPromptMessage, and McpGetPromptResponse types
    • Added prompts field to McpServer type for storing server prompts
  • Enhanced McpHub (src/services/mcp/McpHub.ts):

    • Added fetchPromptsList() to retrieve available prompts from MCP servers
    • Added getPrompt() to execute prompts with arguments
    • Integrated prompt fetching during server initialization and capability updates
  • Created MCP prompts integration module (src/services/command/mcp-prompts.ts):

    • getMcpPromptsAsCommands(): Converts MCP prompts to slash commands
    • executeMcpPrompt(): Executes MCP prompts and returns formatted content
    • parsePromptArguments(): Parses positional arguments for prompts
  • Updated command system (src/services/command/commands.ts):

    • Added optional mcpHub parameter to integrate MCP prompts
    • MCP prompts have highest priority, overriding project/global/built-in commands
    • Added "mcp" as a new command source type
  • Modified slash command tool (src/core/tools/runSlashCommandTool.ts):

    • Added support for executing MCP prompts with dynamic arguments
    • Integrated with McpServerManager for hub access

Testing

  • Added comprehensive test suite for MCP prompts functionality
  • All existing tests updated and passing
  • Type checking passes without errors

Key Features

  1. Dynamic Discovery: Prompts are automatically fetched when MCP servers connect
  2. Command Pattern: MCP prompts follow the pattern /mcp.<serverName>.<promptName>
  3. Argument Support: Both required and optional arguments are supported with positional parsing
  4. Priority System: MCP prompts have the highest priority in the command system
  5. Virtual Commands: MCP prompts are treated as virtual commands with no physical file backing

Testing

  • ✅ All tests passing
  • ✅ TypeScript compilation successful
  • ✅ Manual testing with MCP servers (when available)

Example Usage

This would execute the "greeting" prompt from "myserver" with "John" as the first argument.

Notes

  • The implementation gracefully handles servers without prompt capabilities
  • Error handling is in place for prompt execution failures
  • The system is backward compatible with existing slash commands

Important

Adds support for MCP server prompts in RooCode, enabling access via slash commands with priority handling and comprehensive testing.

  • Behavior:
    • Adds MCP prompt types to mcp.ts and integrates them into the command system.
    • Enhances McpHub in McpHub.ts to fetch and execute MCP prompts.
    • Introduces mcp-prompts.ts for converting MCP prompts to commands and executing them.
    • Updates commands.ts to prioritize MCP prompts over other commands.
    • Modifies runSlashCommandTool.ts to support MCP prompt execution.
  • Testing:
    • Adds mcp-prompts.spec.ts for testing MCP prompt functionalities.
    • Updates existing tests to accommodate MCP prompt integration.
  • Misc:
    • Updates ExtensionMessage.ts and shared/mcp.ts to include new types and structures for MCP prompts.

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

- Add prompt types to shared/mcp.ts (McpPrompt, McpPromptArgument, etc.)
- Update McpHub to fetch prompts from MCP servers via prompts/list
- Add getPrompt method to McpHub for executing prompts
- Create mcp-prompts.ts service to integrate MCP prompts with slash commands
- Update command system to support MCP prompts as slash commands (mcp.<server>.<prompt>)
- Add support for prompt arguments/parameters
- Update tests to support new function signatures

Implements #8004
- Test getMcpPromptsAsCommands for converting prompts to commands
- Test executeMcpPrompt for executing prompts with arguments
- Test parsePromptArguments for parsing positional arguments
- Ensure proper handling of edge cases and errors
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 15, 2025 22:13
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Sep 15, 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.

Reviewing my own code is like debugging in production—technically possible but morally questionable.

/**
* Parse arguments from a command string
*/
export function parsePromptArguments(prompt: McpPrompt, argsString: string): Record<string, unknown> {
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 current implementation only supports simple positional arguments. What happens if a user provides named arguments or complex values with spaces? Consider adding validation or documenting this limitation clearly in the comments.

For example, if someone tries /mcp.server.prompt --name="John Doe" --age=30, this will be incorrectly parsed. Maybe we could add a comment like:

Suggested change
export function parsePromptArguments(prompt: McpPrompt, argsString: string): Record<string, unknown> {
/**
* Parse arguments from a command string
* NOTE: Currently only supports simple positional arguments separated by spaces.
* Named arguments (--key=value) and quoted strings are not yet supported.
*/

promptName: string,
args?: Record<string, unknown>,
): Promise<string> {
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.

While there's a try-catch here, could we add more specific error handling for different failure scenarios? For instance:

  • Network timeouts
  • Malformed responses
  • Missing required fields

This would help with debugging when MCP servers misbehave.

expect(result).toEqual([])
})

it("should convert MCP prompts to commands", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test case for prompt names containing dots? The implementation handles this with parts.slice(2).join(".") on line 56 of mcp-prompts.ts, but we should verify it works correctly.

For example:

it("should handle prompt names with dots", async () => {
  const prompts: McpPrompt[] = [
    {
      name: "prompt.v2.beta",
      description: "Versioned prompt",
      arguments: [],
    },
  ]
  // ... rest of test
})

}

const args: Record<string, unknown> = {}
const parts = trimmedArgs.split(/\s+/)
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 split operation here could benefit from limiting the number of splits to preserve spaces in later arguments. Currently, "arg1 arg2 with spaces" would incorrectly become three separate arguments.

Consider handling this edge case or documenting the limitation.

const response = await connection.client.request({ method: "prompts/list" }, ListPromptsResultSchema)
return response?.prompts || []
} catch (error) {
// Prompts might not be supported by all servers, so we silently handle errors
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we at least log when a server doesn't support prompts? The silent failure makes debugging harder. Even a debug-level log would help:

Suggested change
// Prompts might not be supported by all servers, so we silently handle errors
} catch (error) {
// Prompts might not be supported by all servers
// console.debug(`Server ${serverName} does not support prompts:`, error)
return []
}

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 15, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Sep 15, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Sep 15, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 22, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Sep 22, 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 PR - Needs Preliminary Review size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[Improvement] Support MCP Server Prompts

3 participants