Skip to content

Commit cfda839

Browse files
roomote[bot]roomotedaniel-lxs
authored
feat: auto-omit MCP content when no servers are configured (#5889)
* feat: auto-omit MCP content when no servers are configured - Modify system prompt generation to detect when no MCP servers are defined - Only include MCP sections when mode has mcp group AND servers exist - Pass undefined mcpHub to capabilities and tools when no servers available - Reduces system prompt verbosity when MCP functionality is not in use * fix: add missing Uri and RelativePattern exports to VSCode mocks - Added Uri and RelativePattern exports to global VSCode mock in __mocks__/vscode.js - Fixed McpHub.spec.ts VSCode mock to include Uri and RelativePattern - Fixed Task.spec.ts VSCode mock to include Uri and RelativePattern with proper TypeScript typing - Resolves unhandled rejection errors in unit tests caused by missing VSCode API mocks * fix: add proper TypeScript typing for RelativePattern in McpHub test mock * fix: resolve unit test failures in PR #5889 - Fix VSCode mock onDidChangeWorkspaceFolders to accept callback parameter - Update MCP test mocks to properly test auto-omit functionality - Update test snapshots to reflect new MCP content omission behavior - All core functionality tests now passing * chore: remove package-lock.json as project uses npm * fix: remove unrelated mock changes from PR --------- Co-authored-by: Roo Code <[email protected]> Co-authored-by: Daniel Riccio <[email protected]>
1 parent de13d8a commit cfda839

File tree

7 files changed

+17
-75
lines changed

7 files changed

+17
-75
lines changed

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

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

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/prompts/__tests__/add-custom-instructions.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ const mockContext = {
168168
} as unknown as vscode.ExtensionContext
169169

170170
// Instead of extending McpHub, create a mock that implements just what we need
171-
const createMockMcpHub = (): McpHub =>
171+
const createMockMcpHub = (withServers: boolean = false): McpHub =>
172172
({
173-
getServers: () => [],
173+
getServers: () => (withServers ? [{ name: "test-server", disabled: false }] : []),
174174
getMcpServersPath: async () => "/mock/mcp/path",
175175
getMcpSettingsFilePath: async () => "/mock/settings/path",
176176
dispose: async () => {},
@@ -236,7 +236,7 @@ describe("addCustomInstructions", () => {
236236
})
237237

238238
it("should include MCP server creation info when enabled", async () => {
239-
const mockMcpHub = createMockMcpHub()
239+
const mockMcpHub = createMockMcpHub(true)
240240

241241
const prompt = await SYSTEM_PROMPT(
242242
mockContext,
@@ -262,7 +262,7 @@ describe("addCustomInstructions", () => {
262262
})
263263

264264
it("should exclude MCP server creation info when disabled", async () => {
265-
const mockMcpHub = createMockMcpHub()
265+
const mockMcpHub = createMockMcpHub(false)
266266

267267
const prompt = await SYSTEM_PROMPT(
268268
mockContext,

src/core/prompts/__tests__/system-prompt.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ const mockContext = {
168168
} as unknown as vscode.ExtensionContext
169169

170170
// Instead of extending McpHub, create a mock that implements just what we need
171-
const createMockMcpHub = (): McpHub =>
171+
const createMockMcpHub = (withServers: boolean = false): McpHub =>
172172
({
173-
getServers: () => [],
173+
getServers: () => (withServers ? [{ name: "test-server", disabled: false }] : []),
174174
getMcpServersPath: async () => "/mock/mcp/path",
175175
getMcpSettingsFilePath: async () => "/mock/settings/path",
176176
dispose: async () => {},
@@ -250,7 +250,7 @@ describe("SYSTEM_PROMPT", () => {
250250
})
251251

252252
it("should include MCP server info when mcpHub is provided", async () => {
253-
mockMcpHub = createMockMcpHub()
253+
mockMcpHub = createMockMcpHub(true)
254254

255255
const prompt = await SYSTEM_PROMPT(
256256
mockContext,

src/core/prompts/system.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ async function generatePrompt(
7171
const modeConfig = getModeBySlug(mode, customModeConfigs) || modes.find((m) => m.slug === mode) || modes[0]
7272
const { roleDefinition, baseInstructions } = getModeSelection(mode, promptComponent, customModeConfigs)
7373

74+
// Check if MCP functionality should be included
75+
const hasMcpGroup = modeConfig.groups.some((groupEntry) => getGroupName(groupEntry) === "mcp")
76+
const hasMcpServers = mcpHub && mcpHub.getServers().length > 0
77+
const shouldIncludeMcp = hasMcpGroup && hasMcpServers
78+
7479
const [modesSection, mcpServersSection] = await Promise.all([
7580
getModesSection(context),
76-
modeConfig.groups.some((groupEntry) => getGroupName(groupEntry) === "mcp")
81+
shouldIncludeMcp
7782
? getMcpServersSection(mcpHub, effectiveDiffStrategy, enableMcpServerCreation)
7883
: Promise.resolve(""),
7984
])
@@ -93,7 +98,7 @@ ${getToolDescriptionsForMode(
9398
codeIndexManager,
9499
effectiveDiffStrategy,
95100
browserViewportSize,
96-
mcpHub,
101+
shouldIncludeMcp ? mcpHub : undefined,
97102
customModeConfigs,
98103
experiments,
99104
partialReadsEnabled,
@@ -104,7 +109,7 @@ ${getToolUseGuidelinesSection(codeIndexManager)}
104109
105110
${mcpServersSection}
106111
107-
${getCapabilitiesSection(cwd, supportsComputerUse, mcpHub, effectiveDiffStrategy, codeIndexManager)}
112+
${getCapabilitiesSection(cwd, supportsComputerUse, shouldIncludeMcp ? mcpHub : undefined, effectiveDiffStrategy, codeIndexManager)}
108113
109114
${modesSection}
110115

src/services/mcp/__tests__/McpHub.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ describe("McpHub", () => {
9393
// Mock console.error to suppress error messages during tests
9494
console.error = vi.fn()
9595

96-
9796
const mockUri: Uri = {
9897
scheme: "file",
9998
authority: "",

0 commit comments

Comments
 (0)