feat: add auto-execute on Enter behavior to argumentless MCP prompts (#14510)

This commit is contained in:
Jack Wotherspoon
2025-12-04 11:33:45 -05:00
committed by GitHub
parent b27cf0b0a8
commit 1040c246f5
2 changed files with 53 additions and 0 deletions

View File

@@ -261,6 +261,58 @@ describe('McpPromptLoader', () => {
expect(commands).toEqual([]);
});
describe('autoExecute', () => {
it('should set autoExecute to true for prompts with no arguments (undefined)', async () => {
vi.spyOn(cliCore, 'getMCPServerPrompts').mockReturnValue([
{ ...mockPrompt, arguments: undefined },
]);
const loader = new McpPromptLoader(mockConfigWithPrompts);
const commands = await loader.loadCommands(
new AbortController().signal,
);
expect(commands[0].autoExecute).toBe(true);
});
it('should set autoExecute to true for prompts with empty arguments array', async () => {
vi.spyOn(cliCore, 'getMCPServerPrompts').mockReturnValue([
{ ...mockPrompt, arguments: [] },
]);
const loader = new McpPromptLoader(mockConfigWithPrompts);
const commands = await loader.loadCommands(
new AbortController().signal,
);
expect(commands[0].autoExecute).toBe(true);
});
it('should set autoExecute to false for prompts with only optional arguments', async () => {
vi.spyOn(cliCore, 'getMCPServerPrompts').mockReturnValue([
{
...mockPrompt,
arguments: [{ name: 'optional', required: false }],
},
]);
const loader = new McpPromptLoader(mockConfigWithPrompts);
const commands = await loader.loadCommands(
new AbortController().signal,
);
expect(commands[0].autoExecute).toBe(false);
});
it('should set autoExecute to false for prompts with required arguments', async () => {
vi.spyOn(cliCore, 'getMCPServerPrompts').mockReturnValue([
{
...mockPrompt,
arguments: [{ name: 'required', required: true }],
},
]);
const loader = new McpPromptLoader(mockConfigWithPrompts);
const commands = await loader.loadCommands(
new AbortController().signal,
);
expect(commands[0].autoExecute).toBe(false);
});
});
describe('completion', () => {
it('should suggest no arguments when using positional arguments', async () => {
const loader = new McpPromptLoader(mockConfigWithPrompts);

View File

@@ -44,6 +44,7 @@ export class McpPromptLoader implements ICommandLoader {
name: commandName,
description: prompt.description || `Invoke prompt ${prompt.name}`,
kind: CommandKind.MCP_PROMPT,
autoExecute: !prompt.arguments || prompt.arguments.length === 0,
subCommands: [
{
name: 'help',