Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/features/settings/mcpServerList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
FernandoCelmer marked this conversation as resolved.
}
Comment thread
FernandoCelmer marked this conversation as resolved.
return [...servers, trimmed];
}

export function removeServer(servers: string[], server: string): string[] {
Expand Down
14 changes: 14 additions & 0 deletions test/mcpServerList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down