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");