From 952ead5afd1c2e875244411075930b1f1ade44e6 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sat, 2 Aug 2025 22:36:44 +0000 Subject: [PATCH 1/2] fix: prevent MCP server creation when setting is disabled - Modified getFetchInstructionsDescription to conditionally include create_mcp_server task - Updated getToolDescriptionsForMode to pass enableMcpServerCreation parameter - Added tests to verify the conditional behavior - Updated snapshot test to reflect the new expected behavior Fixes #6607 --- .../mcp-server-creation-disabled.snap | 5 +-- src/core/prompts/system.ts | 1 + .../__tests__/fetch-instructions.spec.ts | 43 +++++++++++++++++++ src/core/prompts/tools/fetch-instructions.ts | 30 +++++++++---- src/core/prompts/tools/index.ts | 8 +++- 5 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 src/core/prompts/tools/__tests__/fetch-instructions.spec.ts diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap index 632273dea0..b1fdcc2e32 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap @@ -99,13 +99,12 @@ IMPORTANT: You MUST use this Efficient Reading Strategy: Description: Request to fetch instructions to perform a task Parameters: - task: (required) The task to get instructions for. This can take the following values: - create_mcp_server create_mode -Example: Requesting instructions to create an MCP Server +Example: Requesting instructions to create a Mode -create_mcp_server +create_mode ## search_files diff --git a/src/core/prompts/system.ts b/src/core/prompts/system.ts index cbe91903ee..227e79679d 100644 --- a/src/core/prompts/system.ts +++ b/src/core/prompts/system.ts @@ -105,6 +105,7 @@ ${getToolDescriptionsForMode( experiments, partialReadsEnabled, settings, + enableMcpServerCreation, )} ${getToolUseGuidelinesSection(codeIndexManager)} diff --git a/src/core/prompts/tools/__tests__/fetch-instructions.spec.ts b/src/core/prompts/tools/__tests__/fetch-instructions.spec.ts new file mode 100644 index 0000000000..53a3f5760e --- /dev/null +++ b/src/core/prompts/tools/__tests__/fetch-instructions.spec.ts @@ -0,0 +1,43 @@ +import { describe, it, expect } from "vitest" +import { getFetchInstructionsDescription } from "../fetch-instructions" + +describe("getFetchInstructionsDescription", () => { + it("should include create_mcp_server when enableMcpServerCreation is true", () => { + const description = getFetchInstructionsDescription(true) + + expect(description).toContain("create_mcp_server") + expect(description).toContain("create_mode") + expect(description).toContain("Example: Requesting instructions to create an MCP Server") + expect(description).toContain("create_mcp_server") + }) + + it("should include create_mcp_server when enableMcpServerCreation is undefined (default behavior)", () => { + const description = getFetchInstructionsDescription() + + expect(description).toContain("create_mcp_server") + expect(description).toContain("create_mode") + expect(description).toContain("Example: Requesting instructions to create an MCP Server") + expect(description).toContain("create_mcp_server") + }) + + it("should exclude create_mcp_server when enableMcpServerCreation is false", () => { + const description = getFetchInstructionsDescription(false) + + expect(description).not.toContain("create_mcp_server") + expect(description).toContain("create_mode") + expect(description).toContain("Example: Requesting instructions to create a Mode") + expect(description).toContain("create_mode") + expect(description).not.toContain("Example: Requesting instructions to create an MCP Server") + }) + + it("should have the correct structure", () => { + const description = getFetchInstructionsDescription(true) + + expect(description).toContain("## fetch_instructions") + expect(description).toContain("Description: Request to fetch instructions to perform a task") + expect(description).toContain("Parameters:") + expect(description).toContain("- task: (required) The task to get instructions for.") + expect(description).toContain("") + expect(description).toContain("") + }) +}) diff --git a/src/core/prompts/tools/fetch-instructions.ts b/src/core/prompts/tools/fetch-instructions.ts index eca231c562..0721260332 100644 --- a/src/core/prompts/tools/fetch-instructions.ts +++ b/src/core/prompts/tools/fetch-instructions.ts @@ -1,14 +1,28 @@ -export function getFetchInstructionsDescription(): string { - return `## fetch_instructions -Description: Request to fetch instructions to perform a task -Parameters: -- task: (required) The task to get instructions for. This can take the following values: - create_mcp_server - create_mode +export function getFetchInstructionsDescription(enableMcpServerCreation?: boolean): string { + const tasks = + enableMcpServerCreation !== false + ? ` create_mcp_server + create_mode` + : ` create_mode` -Example: Requesting instructions to create an MCP Server + const example = + enableMcpServerCreation !== false + ? `Example: Requesting instructions to create an MCP Server create_mcp_server ` + : `Example: Requesting instructions to create a Mode + + +create_mode +` + + return `## fetch_instructions +Description: Request to fetch instructions to perform a task +Parameters: +- task: (required) The task to get instructions for. This can take the following values: +${tasks} + +${example}` } diff --git a/src/core/prompts/tools/index.ts b/src/core/prompts/tools/index.ts index 9f4af7f312..0c88bd94b1 100644 --- a/src/core/prompts/tools/index.ts +++ b/src/core/prompts/tools/index.ts @@ -29,7 +29,7 @@ import { CodeIndexManager } from "../../../services/code-index/manager" const toolDescriptionMap: Record string | undefined> = { execute_command: (args) => getExecuteCommandDescription(args), read_file: (args) => getReadFileDescription(args), - fetch_instructions: () => getFetchInstructionsDescription(), + fetch_instructions: (args) => getFetchInstructionsDescription(args.settings?.enableMcpServerCreation), write_to_file: (args) => getWriteToFileDescription(args), search_files: (args) => getSearchFilesDescription(args), list_files: (args) => getListFilesDescription(args), @@ -61,6 +61,7 @@ export function getToolDescriptionsForMode( experiments?: Record, partialReadsEnabled?: boolean, settings?: Record, + enableMcpServerCreation?: boolean, ): string { const config = getModeConfig(mode, customModes) const args: ToolArgs = { @@ -70,7 +71,10 @@ export function getToolDescriptionsForMode( browserViewportSize, mcpHub, partialReadsEnabled, - settings, + settings: { + ...settings, + enableMcpServerCreation, + }, experiments, } From ca98c62537bcd25cb0dae7b1dc4b1870bef58ece Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 4 Aug 2025 18:02:36 +0000 Subject: [PATCH 2/2] fix: address review comments - add JSDoc, null test, and clarify default behavior --- .../prompts/tools/__tests__/fetch-instructions.spec.ts | 10 ++++++++++ src/core/prompts/tools/fetch-instructions.ts | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/core/prompts/tools/__tests__/fetch-instructions.spec.ts b/src/core/prompts/tools/__tests__/fetch-instructions.spec.ts index 53a3f5760e..29e7f0fca2 100644 --- a/src/core/prompts/tools/__tests__/fetch-instructions.spec.ts +++ b/src/core/prompts/tools/__tests__/fetch-instructions.spec.ts @@ -40,4 +40,14 @@ describe("getFetchInstructionsDescription", () => { expect(description).toContain("") expect(description).toContain("") }) + + it("should handle null value consistently (treat as default/undefined)", () => { + const description = getFetchInstructionsDescription(null as any) + + // Should behave the same as undefined (default to true) + expect(description).toContain("create_mcp_server") + expect(description).toContain("create_mode") + expect(description).toContain("Example: Requesting instructions to create an MCP Server") + expect(description).toContain("create_mcp_server") + }) }) diff --git a/src/core/prompts/tools/fetch-instructions.ts b/src/core/prompts/tools/fetch-instructions.ts index 0721260332..dd9cbb80da 100644 --- a/src/core/prompts/tools/fetch-instructions.ts +++ b/src/core/prompts/tools/fetch-instructions.ts @@ -1,3 +1,8 @@ +/** + * Generates the fetch_instructions tool description. + * @param enableMcpServerCreation - Whether to include MCP server creation task. + * Defaults to true when undefined. + */ export function getFetchInstructionsDescription(enableMcpServerCreation?: boolean): string { const tasks = enableMcpServerCreation !== false