Skip to content

Commit 0d68f13

Browse files
authored
Merge pull request #202 from docker/fix-config-overwrite
Fix MCP server config overwriting
2 parents 4b4d417 + 9a8554b commit 0d68f13

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/extension/ui/src/queries/useConfig.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const getTemplateForItem = (
2121

2222
export function useConfig(client: v1.DockerDesktopClient) {
2323
const queryClient = useQueryClient();
24-
const configRef = useRef<any>(null);
2524

2625
const {
2726
data: config = undefined,
@@ -33,8 +32,6 @@ export function useConfig(client: v1.DockerDesktopClient) {
3332
try {
3433
const response = await getStoredConfig(client);
3534
const result = response || {};
36-
// Store a deep copy of the config in the ref
37-
configRef.current = JSON.parse(JSON.stringify(result));
3835
return result;
3936
} catch (error) {
4037
client.desktopUI.toast.error("Failed to get stored config: " + error);
@@ -55,14 +52,12 @@ export function useConfig(client: v1.DockerDesktopClient) {
5552
newConfig: { [key: string]: any };
5653
}) => {
5754
try {
58-
// Use the ref which contains the pre-optimistic update state
59-
const currentStoredConfig = { ...(configRef.current || {}) };
60-
const updatedConfig = { ...currentStoredConfig, [itemName]: newConfig };
55+
const updatedConfig = { ...((queryClient.getQueryData(["config"]) as Record<string, any>) ||
56+
{}), [itemName]: newConfig };
6157

6258
await writeToPromptsVolume(client, 'config.yaml', stringify(updatedConfig));
6359

6460
const updatedConfigRef = JSON.parse(JSON.stringify(updatedConfig));
65-
configRef.current = updatedConfigRef;
6661
return { itemName, updatedConfig: updatedConfigRef };
6762
} catch (error) {
6863
client.desktopUI.toast.error("Failed to update config: " + error);

0 commit comments

Comments
 (0)