From 1d32b4e159b5c4255ef76e79911f445c26c61d62 Mon Sep 17 00:00:00 2001 From: Mohak Gupta Date: Sat, 15 Aug 2026 23:57:58 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B2=20BUG:=20reject=20duplicate=20and?= =?UTF-8?q?=20blank=20MCP=20server=20entries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addServer() appended unconditionally, so adding the same command twice spawned the server twice (pycodeloop serve received a duplicate --mcp flag) -- extra tool registrations, log noise, and resource usage. Also allowed blank/whitespace-only entries. Trims and checks against the existing list before appending; a duplicate or blank input is now a no-op. Fixes #10 --- src/features/settings/mcpServerList.ts | 6 +++++- test/mcpServerList.test.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/features/settings/mcpServerList.ts b/src/features/settings/mcpServerList.ts index 36c5934..80039d5 100644 --- a/src/features/settings/mcpServerList.ts +++ b/src/features/settings/mcpServerList.ts @@ -14,7 +14,11 @@ export function parseServerLabel(label: string): string | null { } export function addServer(servers: string[], server: string): string[] { - return [...servers, server]; + const trimmed = server.trim(); + if (!trimmed || servers.includes(trimmed)) { + return servers; + } + return [...servers, trimmed]; } export function removeServer(servers: string[], server: string): string[] { diff --git a/test/mcpServerList.test.ts b/test/mcpServerList.test.ts index 16b58f2..51eb150 100644 --- a/test/mcpServerList.test.ts +++ b/test/mcpServerList.test.ts @@ -28,6 +28,20 @@ test("addServer appends without mutating the input", () => { assert.deepEqual(original, ["a"]); }); +test("addServer is a no-op when the trimmed command already exists", () => { + assert.deepEqual(addServer(["npx -y foo"], "npx -y foo"), ["npx -y foo"]); + assert.deepEqual(addServer(["npx -y foo"], " npx -y foo "), ["npx -y foo"]); +}); + +test("addServer trims whitespace before appending a new command", () => { + assert.deepEqual(addServer(["a"], " b "), ["a", "b"]); +}); + +test("addServer rejects a blank or whitespace-only command", () => { + assert.deepEqual(addServer(["a"], ""), ["a"]); + assert.deepEqual(addServer(["a"], " "), ["a"]); +}); + test("removeServer drops a matching entry without mutating the input", () => { const original = ["a", "b", "c"]; const next = removeServer(original, "b");