-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Add MCP server prompts support (#8004) #8006
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 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
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.
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> { |
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 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:
| 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 { |
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.
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 () => { |
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.
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+/) |
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 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 |
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.
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:
| // 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 [] | |
| } |
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, andMcpGetPromptResponsetypespromptsfield toMcpServertype for storing server promptsEnhanced McpHub (
src/services/mcp/McpHub.ts):fetchPromptsList()to retrieve available prompts from MCP serversgetPrompt()to execute prompts with argumentsCreated MCP prompts integration module (
src/services/command/mcp-prompts.ts):getMcpPromptsAsCommands(): Converts MCP prompts to slash commandsexecuteMcpPrompt(): Executes MCP prompts and returns formatted contentparsePromptArguments(): Parses positional arguments for promptsUpdated command system (
src/services/command/commands.ts):mcpHubparameter to integrate MCP promptsModified slash command tool (
src/core/tools/runSlashCommandTool.ts):Testing
Key Features
/mcp.<serverName>.<promptName>Testing
Example Usage
This would execute the "greeting" prompt from "myserver" with "John" as the first argument.
Notes
Important
Adds support for MCP server prompts in RooCode, enabling access via slash commands with priority handling and comprehensive testing.
mcp.tsand integrates them into the command system.McpHubinMcpHub.tsto fetch and execute MCP prompts.mcp-prompts.tsfor converting MCP prompts to commands and executing them.commands.tsto prioritize MCP prompts over other commands.runSlashCommandTool.tsto support MCP prompt execution.mcp-prompts.spec.tsfor testing MCP prompt functionalities.ExtensionMessage.tsandshared/mcp.tsto include new types and structures for MCP prompts.This description was created by
for fe96d0d. You can customize this summary. It will automatically update as commits are pushed.