mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 00:21:09 -07:00
fix: allow MCP prompts with spaces in name (#12910)
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
This commit is contained in:
@@ -175,6 +175,40 @@ describe('McpPromptLoader', () => {
|
||||
expect(commands[0].kind).toBe(CommandKind.MCP_PROMPT);
|
||||
});
|
||||
|
||||
it('should sanitize prompt names by replacing spaces with hyphens', async () => {
|
||||
const mockPromptWithSpaces = {
|
||||
...mockPrompt,
|
||||
name: 'Prompt Name',
|
||||
};
|
||||
vi.spyOn(cliCore, 'getMCPServerPrompts').mockReturnValue([
|
||||
mockPromptWithSpaces,
|
||||
]);
|
||||
|
||||
const loader = new McpPromptLoader(mockConfigWithPrompts);
|
||||
const commands = await loader.loadCommands(new AbortController().signal);
|
||||
|
||||
expect(commands).toHaveLength(1);
|
||||
expect(commands[0].name).toBe('Prompt-Name');
|
||||
expect(commands[0].kind).toBe(CommandKind.MCP_PROMPT);
|
||||
});
|
||||
|
||||
it('should trim whitespace from prompt names before sanitizing', async () => {
|
||||
const mockPromptWithWhitespace = {
|
||||
...mockPrompt,
|
||||
name: ' Prompt Name ',
|
||||
};
|
||||
vi.spyOn(cliCore, 'getMCPServerPrompts').mockReturnValue([
|
||||
mockPromptWithWhitespace,
|
||||
]);
|
||||
|
||||
const loader = new McpPromptLoader(mockConfigWithPrompts);
|
||||
const commands = await loader.loadCommands(new AbortController().signal);
|
||||
|
||||
expect(commands).toHaveLength(1);
|
||||
expect(commands[0].name).toBe('Prompt-Name');
|
||||
expect(commands[0].kind).toBe(CommandKind.MCP_PROMPT);
|
||||
});
|
||||
|
||||
it('should handle prompt invocation successfully', async () => {
|
||||
const loader = new McpPromptLoader(mockConfigWithPrompts);
|
||||
const commands = await loader.loadCommands(new AbortController().signal);
|
||||
|
||||
@@ -38,7 +38,8 @@ export class McpPromptLoader implements ICommandLoader {
|
||||
for (const serverName in mcpServers) {
|
||||
const prompts = getMCPServerPrompts(this.config, serverName) || [];
|
||||
for (const prompt of prompts) {
|
||||
const commandName = `${prompt.name}`;
|
||||
// Sanitize prompt names to ensure they are valid slash commands (e.g. "Prompt Name" -> "Prompt-Name")
|
||||
const commandName = `${prompt.name}`.trim().replace(/\s+/g, '-');
|
||||
const newPromptCommand: SlashCommand = {
|
||||
name: commandName,
|
||||
description: prompt.description || `Invoke prompt ${prompt.name}`,
|
||||
|
||||
Reference in New Issue
Block a user