Skip to content

Commit 96005f0

Browse files
Changing MCP settings UI to reflect new toggle
1 parent 7ed0302 commit 96005f0

File tree

7 files changed

+137
-27
lines changed

7 files changed

+137
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"configuration": {
5050
"title": "Cline",
5151
"properties": {
52-
"cline.mcp.includeInPrompt": {
52+
"cline.mcp.enabled": {
5353
"type": "boolean",
5454
"default": true,
5555
"description": "Include MCP server functionality in AI prompts. When disabled, the AI will not be aware of MCP capabilities. This saves context window tokens."

src/core/prompts/system.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Usage:
178178
}
179179
180180
${
181-
mcpHub.shouldIncludeInPrompt()
181+
mcpHub.isMcpEnabled()
182182
? `
183183
## use_mcp_tool
184184
Description: Request to use a tool provided by a connected MCP server. Each MCP server can provide multiple tools with different capabilities. Tools have defined input schemas that specify required and optional parameters.
@@ -301,7 +301,7 @@ return (
301301
</diff>
302302
</replace_in_file>
303303
${
304-
mcpHub.shouldIncludeInPrompt()
304+
mcpHub.isMcpEnabled()
305305
? `
306306
307307
## Example 4: Requesting to use an MCP tool
@@ -348,7 +348,7 @@ It is crucial to proceed step-by-step, waiting for the user's message after each
348348
By waiting for and carefully considering the user's response after each tool use, you can react accordingly and make informed decisions about how to proceed with the task. This iterative process helps ensure the overall success and accuracy of your work.
349349
350350
${
351-
mcpHub.shouldIncludeInPrompt()
351+
mcpHub.isMcpEnabled()
352352
? `
353353
====
354354
@@ -849,7 +849,7 @@ CAPABILITIES
849849
: ""
850850
}
851851
${
852-
mcpHub.shouldIncludeInPrompt()
852+
mcpHub.isMcpEnabled()
853853
? `
854854
- You have access to MCP servers that may provide additional tools and resources. Each server may provide different capabilities that you can use to accomplish tasks more effectively.
855855
`
@@ -891,7 +891,7 @@ RULES
891891
: ""
892892
}
893893
${
894-
mcpHub.shouldIncludeInPrompt()
894+
mcpHub.isMcpEnabled()
895895
? `
896896
- MCP operations should be used one at a time, similar to other tool usage. Wait for confirmation of success before proceeding with additional operations.
897897
`

src/core/webview/ClineProvider.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
194194
this.disposables,
195195
)
196196

197-
// Listen for when color changes
197+
// Listen for when color changes or MCP settings
198198
vscode.workspace.onDidChangeConfiguration(
199199
async (e) => {
200200
if (e && e.affectsConfiguration("workbench.colorTheme")) {
@@ -204,6 +204,14 @@ export class ClineProvider implements vscode.WebviewViewProvider {
204204
text: JSON.stringify(await getTheme()),
205205
})
206206
}
207+
if (e && e.affectsConfiguration("cline.mcp.enabled")) {
208+
// Send updated MCP enabled state
209+
const enabled = this.mcpHub?.isMcpEnabled() ?? true
210+
await this.postMessageToWebview({
211+
type: "mcpEnabled",
212+
enabled
213+
})
214+
}
207215
},
208216
null,
209217
this.disposables,
@@ -572,6 +580,18 @@ export class ClineProvider implements vscode.WebviewViewProvider {
572580
await vscode.commands.executeCommand("workbench.action.openSettings", "@ext:saoudrizwan.claude-dev")
573581
break
574582
}
583+
case "getMcpEnabled": {
584+
const enabled = this.mcpHub?.isMcpEnabled() ?? true
585+
await this.postMessageToWebview({
586+
type: "mcpEnabled",
587+
enabled
588+
})
589+
break
590+
}
591+
case "toggleMcp": {
592+
await vscode.workspace.getConfiguration("cline.mcp").update("enabled", message.enabled, true)
593+
break
594+
}
575595
// Add more switch case statements here as more webview message commands
576596
// are created within the webview context (i.e. inside media/main.js)
577597
}

src/services/mcp/McpHub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export class McpHub {
5454
return this.connections.map((conn) => conn.server)
5555
}
5656

57-
shouldIncludeInPrompt(): boolean {
58-
return vscode.workspace.getConfiguration("cline.mcp").get("includeInPrompt") ?? true
57+
isMcpEnabled(): boolean {
58+
return vscode.workspace.getConfiguration("cline.mcp").get("enabled") ?? true
5959
}
6060

6161
async getMcpServersPath(): Promise<string> {

src/shared/ExtensionMessage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export interface ExtensionMessage {
2121
| "openRouterModels"
2222
| "mcpServers"
2323
| "relinquishControl"
24+
| "getMcpEnabled"
25+
| "mcpEnabled"
26+
| "toggleMcp"
2427
text?: string
2528
action?: "chatButtonClicked" | "mcpButtonClicked" | "settingsButtonClicked" | "historyButtonClicked" | "didBecomeVisible"
2629
invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick"
@@ -32,6 +35,7 @@ export interface ExtensionMessage {
3235
partialMessage?: ClineMessage
3336
openRouterModels?: Record<string, ModelInfo>
3437
mcpServers?: McpServer[]
38+
enabled?: boolean // For mcpEnabled message
3539
}
3640

3741
export interface ExtensionState {

src/shared/WebviewMessage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export interface WebviewMessage {
3232
| "checkpointRestore"
3333
| "taskCompletionViewChanges"
3434
| "openExtensionSettings"
35-
// | "relaunchChromeDebugMode"
35+
| "getMcpEnabled"
36+
| "toggleMcp"
37+
// | "relaunchChromeDebugMode"
3638
text?: string
3739
askResponse?: ClineAskResponse
3840
apiConfiguration?: ApiConfiguration
@@ -41,6 +43,7 @@ export interface WebviewMessage {
4143
number?: number
4244
autoApprovalSettings?: AutoApprovalSettings
4345
browserSettings?: BrowserSettings
46+
enabled?: boolean // For toggleMcp message
4447
}
4548

4649
export type ClineAskResponse = "yesButtonClicked" | "noButtonClicked" | "messageResponse"

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

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import { VSCodeButton, VSCodeLink, VSCodePanels, VSCodePanelTab, VSCodePanelView } from "@vscode/webview-ui-toolkit/react"
2-
import { useState } from "react"
1+
import {
2+
VSCodeButton,
3+
VSCodeLink,
4+
VSCodePanels,
5+
VSCodePanelTab,
6+
VSCodePanelView,
7+
VSCodeCheckbox,
8+
} from "@vscode/webview-ui-toolkit/react"
9+
import { useEffect, useState } from "react"
310
import { vscode } from "../../utils/vscode"
411
import { useExtensionState } from "../../context/ExtensionStateContext"
512
import { McpServer } from "../../../../src/shared/mcp"
@@ -12,6 +19,31 @@ type McpViewProps = {
1219

1320
const McpView = ({ onDone }: McpViewProps) => {
1421
const { mcpServers: servers } = useExtensionState()
22+
const [isMcpEnabled, setIsMcpEnabled] = useState(true)
23+
24+
useEffect(() => {
25+
// Get initial MCP enabled state
26+
vscode.postMessage({ type: "getMcpEnabled" })
27+
}, [])
28+
29+
useEffect(() => {
30+
const handler = (event: MessageEvent) => {
31+
const message = event.data
32+
if (message.type === "mcpEnabled") {
33+
setIsMcpEnabled(message.enabled)
34+
}
35+
}
36+
window.addEventListener("message", handler)
37+
return () => window.removeEventListener("message", handler)
38+
}, [])
39+
40+
const toggleMcp = () => {
41+
vscode.postMessage({
42+
type: "toggleMcp",
43+
enabled: !isMcpEnabled,
44+
})
45+
setIsMcpEnabled(!isMcpEnabled)
46+
}
1547
// const [servers, setServers] = useState<McpServer[]>([
1648
// // Add some mock servers for testing
1749
// {
@@ -100,7 +132,7 @@ const McpView = ({ onDone }: McpViewProps) => {
100132
style={{
101133
color: "var(--vscode-foreground)",
102134
fontSize: "13px",
103-
marginBottom: "20px",
135+
marginBottom: "16px",
104136
marginTop: "5px",
105137
}}>
106138
The{" "}
@@ -118,8 +150,57 @@ const McpView = ({ onDone }: McpViewProps) => {
118150
</VSCodeLink>
119151
</div>
120152

121-
{/* Server List */}
122-
{servers.length > 0 && (
153+
{/* MCP Toggle Section */}
154+
<div
155+
style={{
156+
marginBottom: "16px",
157+
paddingBottom: "16px",
158+
borderBottom: "1px solid var(--vscode-textSeparator-foreground)",
159+
}}>
160+
<div>
161+
<VSCodeCheckbox
162+
checked={isMcpEnabled}
163+
onChange={toggleMcp}
164+
style={{
165+
display: "flex",
166+
alignItems: "center",
167+
gap: "8px",
168+
padding: "4px 0",
169+
cursor: "pointer",
170+
fontSize: "13px",
171+
}}>
172+
Enable MCP
173+
</VSCodeCheckbox>
174+
{isMcpEnabled && (
175+
<div
176+
style={{
177+
marginTop: "4px",
178+
marginLeft: "24px",
179+
color: "var(--vscode-descriptionForeground)",
180+
fontSize: "12px",
181+
}}>
182+
Disabling MCP will save on tokens passed in the context.
183+
</div>
184+
)}
185+
{!isMcpEnabled && (
186+
<div
187+
style={{
188+
padding: "8px 12px",
189+
marginTop: "8px",
190+
background: "var(--vscode-textBlockQuote-background)",
191+
border: "1px solid var(--vscode-textBlockQuote-border)",
192+
borderRadius: "4px",
193+
color: "var(--vscode-descriptionForeground)",
194+
fontSize: "12px",
195+
lineHeight: "1.4",
196+
}}>
197+
MCP is currently disabled. Enable MCP to use MCP servers and tools. Enabling MCP will use additional tokens.
198+
</div>
199+
)}
200+
</div>
201+
</div>
202+
203+
{servers.length > 0 && isMcpEnabled && (
123204
<div
124205
style={{
125206
display: "flex",
@@ -132,18 +213,20 @@ const McpView = ({ onDone }: McpViewProps) => {
132213
</div>
133214
)}
134215

135-
{/* Edit Settings Button */}
136-
<div style={{ marginTop: "10px", width: "100%" }}>
137-
<VSCodeButton
138-
appearance="secondary"
139-
style={{ width: "100%" }}
140-
onClick={() => {
141-
vscode.postMessage({ type: "openMcpSettings" })
142-
}}>
143-
<span className="codicon codicon-edit" style={{ marginRight: "6px" }}></span>
144-
Edit MCP Settings
145-
</VSCodeButton>
146-
</div>
216+
{/* Server Configuration Button */}
217+
{isMcpEnabled && (
218+
<div style={{ marginTop: "10px", width: "100%" }}>
219+
<VSCodeButton
220+
appearance="secondary"
221+
style={{ width: "100%" }}
222+
onClick={() => {
223+
vscode.postMessage({ type: "openMcpSettings" })
224+
}}>
225+
<span className="codicon codicon-server" style={{ marginRight: "6px" }}></span>
226+
Configure MCP Servers
227+
</VSCodeButton>
228+
</div>
229+
)}
147230

148231
{/* Bottom padding */}
149232
<div style={{ height: "20px" }} />

0 commit comments

Comments
 (0)