Skip to content

Commit 0af4ca0

Browse files
author
catlog22
committed
fix(mcp): improve CCW config update logic and add debug logging
- Fix McpManagerPage to read config after optimistic update and pass only expected fields - Add debug logging for enabledTools config building and ccw-tools server saving
1 parent 7af258f commit 0af4ca0

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

ccw/frontend/src/lib/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,10 +4373,13 @@ function buildCcwMcpServerConfig(config: {
43734373

43744374
// Only use default when enabledTools is undefined (not provided)
43754375
// When enabledTools is an empty array, set to empty string to disable all tools
4376+
console.log('[buildCcwMcpServerConfig] config.enabledTools:', config.enabledTools);
43764377
if (config.enabledTools !== undefined) {
43774378
env.CCW_ENABLED_TOOLS = config.enabledTools.join(',');
4379+
console.log('[buildCcwMcpServerConfig] Set CCW_ENABLED_TOOLS to:', env.CCW_ENABLED_TOOLS);
43784380
} else {
43794381
env.CCW_ENABLED_TOOLS = 'write_file,edit_file,read_file,core_memory,ask_question,smart_search';
4382+
console.log('[buildCcwMcpServerConfig] Using default CCW_ENABLED_TOOLS');
43804383
}
43814384

43824385
if (config.projectRoot) {

ccw/frontend/src/pages/McpManagerPage.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ export function McpManagerPage() {
412412
};
413413

414414
const handleUpdateCcwConfig = async (config: Partial<CcwMcpConfig>) => {
415-
// Read BEFORE optimistic update to capture actual server state
416-
const currentConfig = queryClient.getQueryData<CcwMcpConfig>(ccwMcpQueryKey) ?? ccwConfig;
415+
// Read BEFORE optimistic update to capture previous state for rollback
417416
const previousConfig = queryClient.getQueryData<CcwMcpConfig>(ccwMcpQueryKey);
418417

419418
// Optimistic cache update for immediate UI response
@@ -422,8 +421,17 @@ export function McpManagerPage() {
422421
return { ...old, ...config };
423422
});
424423

424+
// Read AFTER optimistic update to get the latest merged state
425+
const currentConfig = queryClient.getQueryData<CcwMcpConfig>(ccwMcpQueryKey) ?? ccwConfig;
426+
425427
try {
426-
await updateCcwConfig({ ...currentConfig, ...config });
428+
// Only pass the fields that updateCcwConfig expects
429+
await updateCcwConfig({
430+
enabledTools: currentConfig.enabledTools,
431+
projectRoot: currentConfig.projectRoot,
432+
allowedDirs: currentConfig.allowedDirs,
433+
enableSandbox: currentConfig.enableSandbox,
434+
});
427435
} catch (error) {
428436
console.error('Failed to update CCW config:', error);
429437
queryClient.setQueryData(ccwMcpQueryKey, previousConfig);

ccw/src/core/routes/mcp-routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,11 @@ function addGlobalMcpServer(serverName: string, serverConfig: unknown) {
945945
config.mcpServers = {};
946946
}
947947

948+
// Debug logging for ccw-tools
949+
if (serverName === 'ccw-tools') {
950+
console.log('[addGlobalMcpServer] Saving ccw-tools config:', JSON.stringify(serverConfig, null, 2));
951+
}
952+
948953
// Add the server to top-level mcpServers
949954
config.mcpServers[serverName] = serverConfig;
950955

0 commit comments

Comments
 (0)