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) }, }, ])