From 80c46fcde77b88c0e368eac79edab55e0f6a5ba7 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Wed, 4 Mar 2026 10:22:45 -0500 Subject: [PATCH] feat: add click-to-toggle functionality for MCP servers in dialog - Add onSelect handler to each MCP option in the /mcps dialog - Extract toggle logic into reusable toggle() function - Both mouse click and spacebar now use the same toggle logic - Dialog remains open after clicking (consistent with spacebar behavior) - Prevent concurrent toggles with loading state check --- .../src/cli/cmd/tui/component/dialog-mcp.tsx | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/component/dialog-mcp.tsx b/packages/opencode/src/cli/cmd/tui/component/dialog-mcp.tsx index 9cfa30d4df9..676ded464f1 100644 --- a/packages/opencode/src/cli/cmd/tui/component/dialog-mcp.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/dialog-mcp.tsx @@ -26,6 +26,20 @@ export function DialogMcp() { const [, setRef] = createSignal>() const [loading, setLoading] = createSignal(null) + async function toggle(name: string) { + if (loading() !== null) return + setLoading(name) + try { + await local.mcp.toggle(name) + const status = await sdk.client.mcp.status() + if (status.data) sync.set("mcp", status.data) + } catch (error) { + console.error("Failed to toggle MCP:", error) + } finally { + setLoading(null) + } + } + const options = createMemo(() => { // Track sync data and loading state to trigger re-render when they change const mcpData = sync.data.mcp @@ -41,6 +55,7 @@ export function DialogMcp() { description: status.status === "failed" ? "failed" : status.status, footer: , category: undefined, + onSelect: () => toggle(name), })), ) }) @@ -50,24 +65,7 @@ export function DialogMcp() { keybind: Keybind.parse("space")[0], title: "toggle", onTrigger: async (option: DialogSelectOption) => { - // Prevent toggling while an operation is already in progress - if (loading() !== null) return - - setLoading(option.value) - try { - await local.mcp.toggle(option.value) - // Refresh MCP status from server - const status = await sdk.client.mcp.status() - if (status.data) { - sync.set("mcp", status.data) - } else { - console.error("Failed to refresh MCP status: no data returned") - } - } catch (error) { - console.error("Failed to toggle MCP:", error) - } finally { - setLoading(null) - } + await toggle(option.value) }, }, ])