Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(mcp): preserve formatting when syncing launcher updates (#4674)
Dimitri POSTOLOVb23446b1c7f4
diff --git a/.changeset/preserve-synced-mcp-formatting.md b/.changeset/preserve-synced-mcp-formatting.mdnew file mode 100644index 000000000..fdf0c8fd2--- /dev/null+++ b/.changeset/preserve-synced-mcp-formatting.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Preserve JSON MCP configuration formatting when syncing launcher updates.diff --git a/packages/server/src/mcp-config-reconciler.test.ts b/packages/server/src/mcp-config-reconciler.test.tsindex 74c9d6f4d..79c908131 100644--- a/packages/server/src/mcp-config-reconciler.test.ts+++ b/packages/server/src/mcp-config-reconciler.test.ts@@ -21,6 +21,19 @@ function config(entry: unknown, theme = 'dark'): string {}describe('reconcileTrackedMcpConfig', () => {+ test('keeps incoming bytes when they already contain the selected launcher and unowned shell', () => {+ const base = `${JSON.stringify({ mcpServers: { other: { command: 'keep-me' }, 'open-knowledge': v1 } })}\n`;+ const incoming = `${JSON.stringify({ mcpServers: { other: { command: 'keep-me' }, 'open-knowledge': v2 } })}\n`;+ const plan = reconcileTrackedMcpConfig({+ target: '.mcp.json',+ layers: { base, head: base, index: base, worktree: base, incoming },+ });++ expect(plan.kind).toBe('resolved');+ if (plan.kind !== 'resolved') throw new Error('expected resolved configuration');+ expect(plan.raw).toBe(incoming);+ });+test('selects a recognized newer entry and preserves the local unowned shell', () => {const base = config(v1);const local = config(v1, 'light');diff --git a/packages/server/src/mcp-config-reconciler.ts b/packages/server/src/mcp-config-reconciler.tsindex 84b428266..b74e5aab1 100644--- a/packages/server/src/mcp-config-reconciler.ts+++ b/packages/server/src/mcp-config-reconciler.ts@@ -362,13 +362,19 @@ export function reconcileTrackedMcpConfig(input: {candidate.descriptor.revision > best.descriptor.revision ? candidate : best,);- const shellSource = [+ const shellSources = [managed.worktree,managed.index,managed.head,managed.incoming,managed.base,- ].find((state) => state.shell === shell);+ ].filter((state) => state.shell === shell);+ const shellSource =+ shellSources.find((state) =>+ shape.managedKeys.every(+ (key) => JSON.stringify(state.entry[key]) === JSON.stringify(winner.entry[key]),+ ),+ ) ?? shellSources[0];if (!shellSource) return { kind: 'declined', reason: 'unowned-shell-conflict' };const raw = upsertManagedFields(shellSource.raw, shape, winner.entry, input.tomlEditor);if (raw === null) {