Skip to content

Commit 2a224a0

Browse files
committed
Add to MCP settings too
1 parent c30bdee commit 2a224a0

File tree

3 files changed

+114
-41
lines changed

3 files changed

+114
-41
lines changed

webview-ui/src/components/chat/TooManyToolsWarning.tsx

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React, { useCallback, useMemo } from "react"
1+
import React, { useCallback } from "react"
22
import { useAppTranslation } from "@/i18n/TranslationContext"
3-
import { useExtensionState } from "@src/context/ExtensionStateContext"
4-
import { MAX_MCP_TOOLS_THRESHOLD } from "@roo-code/types"
3+
import { useTooManyTools } from "@src/hooks/useTooManyTools"
54
import WarningRow from "./WarningRow"
65

76
/**
@@ -16,55 +15,20 @@ import WarningRow from "./WarningRow"
1615
*/
1716
export const TooManyToolsWarning: React.FC = () => {
1817
const { t } = useAppTranslation()
19-
const { mcpServers } = useExtensionState()
20-
21-
const { enabledServerCount, enabledToolCount } = useMemo(() => {
22-
let serverCount = 0
23-
let toolCount = 0
24-
25-
for (const server of mcpServers) {
26-
// Skip disabled servers
27-
if (server.disabled) continue
28-
29-
// Skip servers that are not connected
30-
if (server.status !== "connected") continue
31-
32-
serverCount++
33-
34-
// Count enabled tools on this server
35-
if (server.tools) {
36-
for (const tool of server.tools) {
37-
// Tool is enabled if enabledForPrompt is undefined (default) or true
38-
if (tool.enabledForPrompt !== false) {
39-
toolCount++
40-
}
41-
}
42-
}
43-
}
44-
45-
return { enabledServerCount: serverCount, enabledToolCount: toolCount }
46-
}, [mcpServers])
18+
const { isOverThreshold, title, message } = useTooManyTools()
4719

4820
const handleOpenMcpSettings = useCallback(() => {
4921
window.postMessage({ type: "action", action: "settingsButtonClicked", values: { section: "mcp" } }, "*")
5022
}, [])
5123

5224
// Don't show warning if under threshold
53-
if (enabledToolCount <= MAX_MCP_TOOLS_THRESHOLD) {
25+
if (!isOverThreshold) {
5426
return null
5527
}
5628

57-
const toolsPart = t("chat:tooManyTools.toolsPart", { count: enabledToolCount })
58-
const serversPart = t("chat:tooManyTools.serversPart", { count: enabledServerCount })
59-
const message = t("chat:tooManyTools.messageTemplate", {
60-
tools: toolsPart,
61-
servers: serversPart,
62-
threshold: MAX_MCP_TOOLS_THRESHOLD,
63-
})
64-
6529
return (
6630
<WarningRow
67-
title={t("chat:tooManyTools.title")}
31+
title={title}
6832
message={message}
6933
actionText={t("chat:tooManyTools.openMcpSettings")}
7034
onAction={handleOpenMcpSettings}

webview-ui/src/components/mcp/McpView.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { McpServer } from "@roo-code/types"
1313
import { vscode } from "@src/utils/vscode"
1414
import { useExtensionState } from "@src/context/ExtensionStateContext"
1515
import { useAppTranslation } from "@src/i18n/TranslationContext"
16+
import { useTooManyTools } from "@src/hooks/useTooManyTools"
1617
import {
1718
Button,
1819
Dialog,
@@ -43,6 +44,7 @@ const McpView = () => {
4344
} = useExtensionState()
4445

4546
const { t } = useAppTranslation()
47+
const { isOverThreshold, title, message } = useTooManyTools()
4648

4749
return (
4850
<div>
@@ -99,6 +101,31 @@ const McpView = () => {
99101
</div>
100102
</div>
101103

104+
{/* Too Many Tools Warning */}
105+
{isOverThreshold && (
106+
<div style={{ marginBottom: 15 }}>
107+
<div
108+
style={{
109+
display: "flex",
110+
alignItems: "center",
111+
gap: "6px",
112+
fontWeight: "500",
113+
color: "var(--vscode-editorWarning-foreground)",
114+
marginBottom: "5px",
115+
}}>
116+
<span className="codicon codicon-warning" />
117+
{title}
118+
</div>
119+
<div
120+
style={{
121+
fontSize: "12px",
122+
color: "var(--vscode-descriptionForeground)",
123+
}}>
124+
{message}
125+
</div>
126+
</div>
127+
)}
128+
102129
{/* Server List */}
103130
{servers.length > 0 && (
104131
<div style={{ display: "flex", flexDirection: "column", gap: "10px" }}>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { useMemo } from "react"
2+
import { useExtensionState } from "@src/context/ExtensionStateContext"
3+
import { useAppTranslation } from "@src/i18n/TranslationContext"
4+
import { MAX_MCP_TOOLS_THRESHOLD } from "@roo-code/types"
5+
6+
export interface TooManyToolsInfo {
7+
/** Number of enabled and connected MCP servers */
8+
enabledServerCount: number
9+
/** Total number of enabled tools across all enabled servers */
10+
enabledToolCount: number
11+
/** Whether the tool count exceeds the threshold */
12+
isOverThreshold: boolean
13+
/** The maximum recommended threshold */
14+
threshold: number
15+
/** Localized title string */
16+
title: string
17+
/** Localized message string */
18+
message: string
19+
}
20+
21+
/**
22+
* Hook that calculates tool counts and provides localized warning messages.
23+
* Used by TooManyToolsWarning components in both chat and MCP settings views.
24+
*
25+
* @returns Tool count information and localized messages
26+
*
27+
* @example
28+
* const { isOverThreshold, title, message } = useTooManyTools()
29+
* if (isOverThreshold) {
30+
* // Show warning
31+
* }
32+
*/
33+
export function useTooManyTools(): TooManyToolsInfo {
34+
const { t } = useAppTranslation()
35+
const { mcpServers } = useExtensionState()
36+
37+
const { enabledServerCount, enabledToolCount } = useMemo(() => {
38+
let serverCount = 0
39+
let toolCount = 0
40+
41+
for (const server of mcpServers) {
42+
// Skip disabled servers
43+
if (server.disabled) continue
44+
45+
// Skip servers that are not connected
46+
if (server.status !== "connected") continue
47+
48+
serverCount++
49+
50+
// Count enabled tools on this server
51+
if (server.tools) {
52+
for (const tool of server.tools) {
53+
// Tool is enabled if enabledForPrompt is undefined (default) or true
54+
if (tool.enabledForPrompt !== false) {
55+
toolCount++
56+
}
57+
}
58+
}
59+
}
60+
61+
return { enabledServerCount: serverCount, enabledToolCount: toolCount }
62+
}, [mcpServers])
63+
64+
const isOverThreshold = enabledToolCount > MAX_MCP_TOOLS_THRESHOLD
65+
66+
const toolsPart = t("chat:tooManyTools.toolsPart", { count: enabledToolCount })
67+
const serversPart = t("chat:tooManyTools.serversPart", { count: enabledServerCount })
68+
const message = t("chat:tooManyTools.messageTemplate", {
69+
tools: toolsPart,
70+
servers: serversPart,
71+
threshold: MAX_MCP_TOOLS_THRESHOLD,
72+
})
73+
74+
return {
75+
enabledServerCount,
76+
enabledToolCount,
77+
isOverThreshold,
78+
threshold: MAX_MCP_TOOLS_THRESHOLD,
79+
title: t("chat:tooManyTools.title"),
80+
message,
81+
}
82+
}

0 commit comments

Comments
 (0)