Skip to content

Commit 8a35b64

Browse files
fix: prevent MCP server creation when setting is disabled (RooCodeInc#6613)
* 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 RooCodeInc#6607 * fix: address review comments - add JSDoc, null test, and clarify default behavior --------- Co-authored-by: Roo Code <[email protected]>
1 parent 4a9222b commit 8a35b64

File tree

5 files changed

+89
-13
lines changed

5 files changed

+89
-13
lines changed

src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/prompts/system.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ${getToolDescriptionsForMode(
105105
experiments,
106106
partialReadsEnabled,
107107
settings,
108+
enableMcpServerCreation,
108109
)}
109110
110111
${getToolUseGuidelinesSection(codeIndexManager)}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, it, expect } from "vitest"
2+
import { getFetchInstructionsDescription } from "../fetch-instructions"
3+
4+
describe("getFetchInstructionsDescription", () => {
5+
it("should include create_mcp_server when enableMcpServerCreation is true", () => {
6+
const description = getFetchInstructionsDescription(true)
7+
8+
expect(description).toContain("create_mcp_server")
9+
expect(description).toContain("create_mode")
10+
expect(description).toContain("Example: Requesting instructions to create an MCP Server")
11+
expect(description).toContain("<task>create_mcp_server</task>")
12+
})
13+
14+
it("should include create_mcp_server when enableMcpServerCreation is undefined (default behavior)", () => {
15+
const description = getFetchInstructionsDescription()
16+
17+
expect(description).toContain("create_mcp_server")
18+
expect(description).toContain("create_mode")
19+
expect(description).toContain("Example: Requesting instructions to create an MCP Server")
20+
expect(description).toContain("<task>create_mcp_server</task>")
21+
})
22+
23+
it("should exclude create_mcp_server when enableMcpServerCreation is false", () => {
24+
const description = getFetchInstructionsDescription(false)
25+
26+
expect(description).not.toContain("create_mcp_server")
27+
expect(description).toContain("create_mode")
28+
expect(description).toContain("Example: Requesting instructions to create a Mode")
29+
expect(description).toContain("<task>create_mode</task>")
30+
expect(description).not.toContain("Example: Requesting instructions to create an MCP Server")
31+
})
32+
33+
it("should have the correct structure", () => {
34+
const description = getFetchInstructionsDescription(true)
35+
36+
expect(description).toContain("## fetch_instructions")
37+
expect(description).toContain("Description: Request to fetch instructions to perform a task")
38+
expect(description).toContain("Parameters:")
39+
expect(description).toContain("- task: (required) The task to get instructions for.")
40+
expect(description).toContain("<fetch_instructions>")
41+
expect(description).toContain("</fetch_instructions>")
42+
})
43+
44+
it("should handle null value consistently (treat as default/undefined)", () => {
45+
const description = getFetchInstructionsDescription(null as any)
46+
47+
// Should behave the same as undefined (default to true)
48+
expect(description).toContain("create_mcp_server")
49+
expect(description).toContain("create_mode")
50+
expect(description).toContain("Example: Requesting instructions to create an MCP Server")
51+
expect(description).toContain("<task>create_mcp_server</task>")
52+
})
53+
})
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
export function getFetchInstructionsDescription(): string {
2-
return `## fetch_instructions
3-
Description: Request to fetch instructions to perform a task
4-
Parameters:
5-
- task: (required) The task to get instructions for. This can take the following values:
6-
create_mcp_server
7-
create_mode
1+
/**
2+
* Generates the fetch_instructions tool description.
3+
* @param enableMcpServerCreation - Whether to include MCP server creation task.
4+
* Defaults to true when undefined.
5+
*/
6+
export function getFetchInstructionsDescription(enableMcpServerCreation?: boolean): string {
7+
const tasks =
8+
enableMcpServerCreation !== false
9+
? ` create_mcp_server
10+
create_mode`
11+
: ` create_mode`
812

9-
Example: Requesting instructions to create an MCP Server
13+
const example =
14+
enableMcpServerCreation !== false
15+
? `Example: Requesting instructions to create an MCP Server
1016
1117
<fetch_instructions>
1218
<task>create_mcp_server</task>
1319
</fetch_instructions>`
20+
: `Example: Requesting instructions to create a Mode
21+
22+
<fetch_instructions>
23+
<task>create_mode</task>
24+
</fetch_instructions>`
25+
26+
return `## fetch_instructions
27+
Description: Request to fetch instructions to perform a task
28+
Parameters:
29+
- task: (required) The task to get instructions for. This can take the following values:
30+
${tasks}
31+
32+
${example}`
1433
}

src/core/prompts/tools/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { CodeIndexManager } from "../../../services/code-index/manager"
2929
const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined> = {
3030
execute_command: (args) => getExecuteCommandDescription(args),
3131
read_file: (args) => getReadFileDescription(args),
32-
fetch_instructions: () => getFetchInstructionsDescription(),
32+
fetch_instructions: (args) => getFetchInstructionsDescription(args.settings?.enableMcpServerCreation),
3333
write_to_file: (args) => getWriteToFileDescription(args),
3434
search_files: (args) => getSearchFilesDescription(args),
3535
list_files: (args) => getListFilesDescription(args),
@@ -61,6 +61,7 @@ export function getToolDescriptionsForMode(
6161
experiments?: Record<string, boolean>,
6262
partialReadsEnabled?: boolean,
6363
settings?: Record<string, any>,
64+
enableMcpServerCreation?: boolean,
6465
): string {
6566
const config = getModeConfig(mode, customModes)
6667
const args: ToolArgs = {
@@ -70,7 +71,10 @@ export function getToolDescriptionsForMode(
7071
browserViewportSize,
7172
mcpHub,
7273
partialReadsEnabled,
73-
settings,
74+
settings: {
75+
...settings,
76+
enableMcpServerCreation,
77+
},
7478
experiments,
7579
}
7680

0 commit comments

Comments
 (0)