Browse Source

Add back to the settings page as well

Matt Rubens 1 year ago
parent
commit
06733d949b

+ 29 - 0
webview-ui/src/components/mcp/McpEnabledToggle.tsx

@@ -0,0 +1,29 @@
+import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
+import { useExtensionState } from "../../context/ExtensionStateContext"
+import { vscode } from "../../utils/vscode"
+
+const McpEnabledToggle = () => {
+	const { mcpEnabled, setMcpEnabled } = useExtensionState()
+
+	return (
+		<div style={{ marginBottom: "20px" }}>
+			<VSCodeCheckbox
+				checked={mcpEnabled}
+				onChange={(e: any) => {
+					setMcpEnabled(e.target.checked)
+					vscode.postMessage({ type: "mcpEnabled", bool: e.target.checked })
+				}}>
+				<span style={{ fontWeight: "500" }}>Enable MCP Servers</span>
+			</VSCodeCheckbox>
+			<p style={{
+				fontSize: "12px",
+				marginTop: "5px",
+				color: "var(--vscode-descriptionForeground)",
+			}}>
+				When enabled, Cline will be able to interact with MCP servers for advanced functionality. If you're not using MCP, you can disable this to reduce Cline's token usage.
+			</p>
+		</div>
+	)
+}
+
+export default McpEnabledToggle

+ 3 - 19
webview-ui/src/components/mcp/McpView.tsx

@@ -1,6 +1,5 @@
 import {
 import {
 	VSCodeButton,
 	VSCodeButton,
-	VSCodeCheckbox,
 	VSCodeLink,
 	VSCodeLink,
 	VSCodePanels,
 	VSCodePanels,
 	VSCodePanelTab,
 	VSCodePanelTab,
@@ -12,13 +11,14 @@ import { useExtensionState } from "../../context/ExtensionStateContext"
 import { McpServer } from "../../../../src/shared/mcp"
 import { McpServer } from "../../../../src/shared/mcp"
 import McpToolRow from "./McpToolRow"
 import McpToolRow from "./McpToolRow"
 import McpResourceRow from "./McpResourceRow"
 import McpResourceRow from "./McpResourceRow"
+import McpEnabledToggle from "./McpEnabledToggle"
 
 
 type McpViewProps = {
 type McpViewProps = {
 	onDone: () => void
 	onDone: () => void
 }
 }
 
 
 const McpView = ({ onDone }: McpViewProps) => {
 const McpView = ({ onDone }: McpViewProps) => {
-	const { mcpServers: servers, alwaysAllowMcp, mcpEnabled, setMcpEnabled } = useExtensionState()
+	const { mcpServers: servers, alwaysAllowMcp, mcpEnabled } = useExtensionState()
 	// const [servers, setServers] = useState<McpServer[]>([
 	// const [servers, setServers] = useState<McpServer[]>([
 	// 	// Add some mock servers for testing
 	// 	// Add some mock servers for testing
 	// 	{
 	// 	{
@@ -123,23 +123,7 @@ const McpView = ({ onDone }: McpViewProps) => {
 					npm docs").
 					npm docs").
 				</div>
 				</div>
 
 
-				<div style={{ marginBottom: "20px" }}>
-					<VSCodeCheckbox
-						checked={mcpEnabled}
-						onChange={(e: any) => {
-							setMcpEnabled(e.target.checked)
-							vscode.postMessage({ type: "mcpEnabled", bool: e.target.checked })
-						}}>
-						<span style={{ fontWeight: "500" }}>Enable MCP Servers</span>
-					</VSCodeCheckbox>
-					<p style={{
-						fontSize: "12px",
-						marginTop: "5px",
-						color: "var(--vscode-descriptionForeground)",
-					}}>
-						When enabled, Cline will be able to interact with MCP servers for advanced functionality. If you're not using MCP, you can disable this to reduce Cline's token usage.
-					</p>
-				</div>
+				<McpEnabledToggle />
 
 
 				{mcpEnabled && (
 				{mcpEnabled && (
 					<>
 					<>

+ 5 - 0
webview-ui/src/components/settings/SettingsView.tsx

@@ -4,6 +4,7 @@ import { useExtensionState } from "../../context/ExtensionStateContext"
 import { validateApiConfiguration, validateModelId } from "../../utils/validate"
 import { validateApiConfiguration, validateModelId } from "../../utils/validate"
 import { vscode } from "../../utils/vscode"
 import { vscode } from "../../utils/vscode"
 import ApiOptions from "./ApiOptions"
 import ApiOptions from "./ApiOptions"
+import McpEnabledToggle from "../mcp/McpEnabledToggle"
 
 
 const IS_DEV = false // FIXME: use flags when packaging
 const IS_DEV = false // FIXME: use flags when packaging
 
 
@@ -48,6 +49,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
 		setScreenshotQuality,
 		setScreenshotQuality,
 		terminalOutputLineLimit,
 		terminalOutputLineLimit,
 		setTerminalOutputLineLimit,
 		setTerminalOutputLineLimit,
+		mcpEnabled,
 	} = useExtensionState()
 	} = useExtensionState()
 	const [apiErrorMessage, setApiErrorMessage] = useState<string | undefined>(undefined)
 	const [apiErrorMessage, setApiErrorMessage] = useState<string | undefined>(undefined)
 	const [modelIdErrorMessage, setModelIdErrorMessage] = useState<string | undefined>(undefined)
 	const [modelIdErrorMessage, setModelIdErrorMessage] = useState<string | undefined>(undefined)
@@ -79,6 +81,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
 			vscode.postMessage({ type: "writeDelayMs", value: writeDelayMs })
 			vscode.postMessage({ type: "writeDelayMs", value: writeDelayMs })
 			vscode.postMessage({ type: "screenshotQuality", value: screenshotQuality ?? 75 })
 			vscode.postMessage({ type: "screenshotQuality", value: screenshotQuality ?? 75 })
 			vscode.postMessage({ type: "terminalOutputLineLimit", value: terminalOutputLineLimit ?? 500 })
 			vscode.postMessage({ type: "terminalOutputLineLimit", value: terminalOutputLineLimit ?? 500 })
+			vscode.postMessage({ type: "mcpEnabled", bool: mcpEnabled })
 			onDone()
 			onDone()
 		}
 		}
 	}
 	}
@@ -211,6 +214,8 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
 						}}>
 						}}>
 						These instructions are added to the end of the system prompt sent with every request. Custom instructions set in .clinerules and .cursorrules in the working directory are also included.
 						These instructions are added to the end of the system prompt sent with every request. Custom instructions set in .clinerules and .cursorrules in the working directory are also included.
 					</p>
 					</p>
+
+					<McpEnabledToggle />
 				</div>
 				</div>
 
 
 				<div style={{ marginBottom: 5 }}>
 				<div style={{ marginBottom: 5 }}>