diff --git a/ccw/frontend/src/pages/McpManagerPage.tsx b/ccw/frontend/src/pages/McpManagerPage.tsx index 09814283..0f02a5d1 100644 --- a/ccw/frontend/src/pages/McpManagerPage.tsx +++ b/ccw/frontend/src/pages/McpManagerPage.tsx @@ -413,9 +413,10 @@ export function McpManagerPage() { const handleToggleCcwToolCodex = async (tool: string, enabled: boolean) => { const currentConfig = queryClient.getQueryData(['ccwMcpConfigCodex']) ?? ccwCodexConfig; const currentTools = currentConfig.enabledTools; + const previousConfig = queryClient.getQueryData(['ccwMcpConfigCodex']); const updatedTools = enabled - ? [...currentTools, tool] + ? (currentTools.includes(tool) ? currentTools : [...currentTools, tool]) : currentTools.filter((t) => t !== tool); queryClient.setQueryData(['ccwMcpConfigCodex'], (old: CcwMcpConfig | undefined) => { @@ -424,34 +425,28 @@ export function McpManagerPage() { }); try { - await updateCcwConfigForCodex({ - enabledTools: updatedTools, - projectRoot: currentConfig.projectRoot, - allowedDirs: currentConfig.allowedDirs, - disableSandbox: currentConfig.disableSandbox, - }); + await updateCcwConfigForCodex({ ...currentConfig, enabledTools: updatedTools }); } catch (error) { console.error('Failed to toggle CCW tool (Codex):', error); + queryClient.setQueryData(['ccwMcpConfigCodex'], previousConfig); } ccwMcpCodexQuery.refetch(); }; const handleUpdateCcwConfigCodex = async (config: Partial) => { + const currentConfig = queryClient.getQueryData(['ccwMcpConfigCodex']) ?? ccwCodexConfig; + const previousConfig = queryClient.getQueryData(['ccwMcpConfigCodex']); + queryClient.setQueryData(['ccwMcpConfigCodex'], (old: CcwMcpConfig | undefined) => { if (!old) return old; return { ...old, ...config }; }); try { - const currentConfig = queryClient.getQueryData(['ccwMcpConfigCodex']) ?? ccwCodexConfig; - await updateCcwConfigForCodex({ - enabledTools: config.enabledTools ?? currentConfig.enabledTools, - projectRoot: config.projectRoot ?? currentConfig.projectRoot, - allowedDirs: config.allowedDirs ?? currentConfig.allowedDirs, - disableSandbox: config.disableSandbox ?? currentConfig.disableSandbox, - }); + await updateCcwConfigForCodex({ ...currentConfig, ...config }); } catch (error) { console.error('Failed to update CCW config (Codex):', error); + queryClient.setQueryData(['ccwMcpConfigCodex'], previousConfig); } ccwMcpCodexQuery.refetch(); };