Skip to content

Commit 1f4d3c3

Browse files
committed
fix: resolve MCP selector issues and simplify implementation
- Fixed useEffect to properly detect MCP object format { mcp: { included: [...] } } - Fixed empty selection behavior to enable all MCP servers instead of disabling MCP - Removed tuple format handling since this feature hasn't been released yet - Simplified code to only handle the new object format for MCP configuration - Removed unused GroupOptions import When no specific servers are selected, MCP is added as a string (enables all servers). When specific servers are selected, MCP is added as an object with the included list. This ensures the MCP selector properly loads configurations and maintains the expected behavior where empty selection means all servers are enabled.
1 parent b223d71 commit 1f4d3c3

File tree

2 files changed

+27
-39
lines changed

2 files changed

+27
-39
lines changed

src/core/prompts/sections/mcp-servers.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,20 @@ export async function getMcpServersSection(
5252
let mcpIncludedList: string[] | undefined
5353

5454
if (currentMode) {
55-
// Find MCP group configuration
55+
// Find MCP group configuration - object format: { mcp: { included: [...] } }
5656
const mcpGroup = currentMode.groups.find((group: GroupEntry) => {
57-
// Handle tuple format: ["mcp", { mcp: { included: [...] } }]
58-
if (Array.isArray(group) && group.length === 2 && group[0] === "mcp") {
59-
return true
60-
}
61-
// Handle direct object format: { mcp: { included: [...] } }
6257
if (typeof group === "object" && !Array.isArray(group) && "mcp" in group) {
6358
return true
6459
}
6560
return getGroupName(group) === "mcp"
6661
})
6762

68-
// Extract mcpIncludedList based on the format
69-
if (mcpGroup) {
70-
let mcpOptions: { mcp?: { included?: unknown[] } } | undefined
71-
72-
if (Array.isArray(mcpGroup) && mcpGroup.length === 2) {
73-
// Tuple format
74-
mcpOptions = mcpGroup[1] as { mcp?: { included?: unknown[] } }
75-
} else if (typeof mcpGroup === "object" && !Array.isArray(mcpGroup) && "mcp" in mcpGroup) {
76-
// Direct object format
77-
mcpOptions = mcpGroup as { mcp?: { included?: unknown[] } }
78-
}
79-
80-
if (mcpOptions) {
81-
mcpIncludedList = Array.isArray(mcpOptions.mcp?.included)
82-
? mcpOptions.mcp.included.filter((item: unknown): item is string => typeof item === "string")
83-
: undefined
84-
}
63+
// Extract mcpIncludedList from the MCP configuration
64+
if (mcpGroup && typeof mcpGroup === "object" && !Array.isArray(mcpGroup) && "mcp" in mcpGroup) {
65+
const mcpOptions = mcpGroup as { mcp?: { included?: unknown[] } }
66+
mcpIncludedList = Array.isArray(mcpOptions.mcp?.included)
67+
? mcpOptions.mcp.included.filter((item: unknown): item is string => typeof item === "string")
68+
: undefined
8569
}
8670
}
8771

webview-ui/src/components/modes/McpSelector.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
CommandItem,
1515
} from "@src/components/ui"
1616
import { useAppTranslation } from "@src/i18n/TranslationContext"
17-
import { ModeConfig, GroupEntry, GroupOptions } from "@roo-code/types"
17+
import { ModeConfig, GroupEntry } from "@roo-code/types"
1818
import { McpServer } from "@roo/mcp"
1919

2020
interface McpSelectorProps {
@@ -55,42 +55,46 @@ const McpSelector: React.FC<McpSelectorProps> = ({
5555
return
5656
}
5757

58-
const mcpGroupArr = currentMode.groups?.find(
59-
(g: GroupEntry): g is ["mcp", GroupOptions] => Array.isArray(g) && g.length === 2 && g[0] === "mcp",
60-
)
58+
// Find MCP group - object format: { mcp: { included: [...] } }
59+
const mcpGroup = currentMode.groups?.find((g: GroupEntry) => {
60+
return typeof g === "object" && !Array.isArray(g) && "mcp" in g
61+
})
6162

62-
const rawGroupOptions: GroupOptions | undefined = mcpGroupArr ? mcpGroupArr[1] : undefined
63+
let included: string[] = []
6364

64-
const included = Array.isArray(rawGroupOptions?.mcp?.included)
65-
? (rawGroupOptions.mcp.included.filter((item) => typeof item === "string") as string[])
66-
: []
65+
if (mcpGroup && typeof mcpGroup === "object" && !Array.isArray(mcpGroup) && "mcp" in mcpGroup) {
66+
const mcpOptions = mcpGroup as { mcp?: { included?: unknown[] } }
67+
included = Array.isArray(mcpOptions.mcp?.included)
68+
? (mcpOptions.mcp.included.filter((item) => typeof item === "string") as string[])
69+
: []
70+
}
6771

6872
// Sync MCP settings when mode changes
6973
setMcpIncludedList(included)
7074
}, [currentMode])
7175
// Handle save
7276
function updateMcpGroupOptions(groups: GroupEntry[] = [], _group: string, mcpIncludedList: string[]): GroupEntry[] {
73-
// Filter out any existing "mcp" entries (both string and object forms)
77+
// Filter out any existing "mcp" entries (string or object forms)
7478
const filteredGroups = groups.filter((g) => {
7579
if (typeof g === "string") {
7680
return g !== "mcp"
7781
}
78-
if (Array.isArray(g) && g[0] === "mcp") {
79-
return false
80-
}
8182
if (typeof g === "object" && g !== null && !Array.isArray(g) && "mcp" in g) {
8283
return false
8384
}
8485
return true
8586
})
8687

87-
// Add the new MCP configuration if there are selected servers
88+
// Always add MCP back if it's enabled
89+
// If mcpIncludedList is empty, it means all servers are enabled (default behavior)
90+
// If mcpIncludedList has items, only those servers are enabled
8891
if (mcpIncludedList.length > 0) {
89-
// Directly add the mcp object without wrapping in an array
92+
// Specific servers selected
9093
return [...filteredGroups, { mcp: { included: mcpIncludedList } }] as GroupEntry[]
94+
} else {
95+
// No specific servers selected - enable all (just add "mcp" string)
96+
return [...filteredGroups, "mcp"] as GroupEntry[]
9197
}
92-
93-
return filteredGroups as GroupEntry[]
9498
}
9599

96100
// Handle save

0 commit comments

Comments
 (0)